Skip to content

Commit ecd6887

Browse files
committed
Hash-based loop identifiers
compute_loop_hashes() uses AST fingerprinting based on loop structure. This yields loop identifiers that are stable across unrelated code changes.
1 parent 7a68f46 commit ecd6887

File tree

31 files changed

+954
-7
lines changed

31 files changed

+954
-7
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Test program with nested loops
2+
// Each loop should have a unique hash identifier
3+
4+
int main()
5+
{
6+
int sum = 0;
7+
8+
// Outer loop
9+
for(int i = 0; i < 3; i++)
10+
{
11+
// Inner loop
12+
for(int j = 0; j < 3; j++)
13+
{
14+
sum += i * j;
15+
}
16+
}
17+
18+
return sum;
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-loops --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^main\.hash_[0-9]+$
7+
--
8+
^warning: ignoring
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Test program to demonstrate hash-based loop identification
2+
// The loop identifiers should remain stable even when we add
3+
// unrelated code before or after the loops.
4+
5+
int main()
6+
{
7+
int sum = 0;
8+
9+
// Loop 1: Simple for loop
10+
for(int i = 0; i < 10; i++)
11+
{
12+
sum += i;
13+
}
14+
15+
// Loop 2: While loop
16+
int j = 0;
17+
while(j < 5)
18+
{
19+
sum += j * 2;
20+
j++;
21+
}
22+
23+
return sum;
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-loops --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^main\.hash_[0-9]+$
7+
--
8+
^warning: ignoring
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Modified test program with pseudo-loops added before the real loops
2+
// The real loops should maintain their hash identifiers
3+
4+
int main()
5+
{
6+
int sum = 0;
7+
8+
// Add some pseudo-loops (do-while-0 pattern) that should not affect
9+
// the hash values of the real loops below
10+
do
11+
{
12+
sum += 1;
13+
} while(0);
14+
do
15+
{
16+
sum += 2;
17+
} while(0);
18+
do
19+
{
20+
sum += 3;
21+
} while(0);
22+
23+
// Loop 1: Simple for loop (same as before)
24+
for(int i = 0; i < 10; i++)
25+
{
26+
sum += i;
27+
}
28+
29+
// Loop 2: While loop (same as before)
30+
int j = 0;
31+
while(j < 5)
32+
{
33+
sum += j * 2;
34+
j++;
35+
}
36+
37+
return sum;
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test_modified.c
3+
--show-loops --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^main\.hash_[0-9]+$
7+
--
8+
^warning: ignoring
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Test program with different loop types
2+
// Each loop should have a unique hash identifier
3+
4+
int main()
5+
{
6+
int sum = 0;
7+
8+
// For loop
9+
for(int i = 0; i < 5; i++)
10+
{
11+
sum += i;
12+
}
13+
14+
// While loop
15+
int j = 0;
16+
while(j < 5)
17+
{
18+
sum += j;
19+
j++;
20+
}
21+
22+
// Do-while loop
23+
int k = 0;
24+
do
25+
{
26+
sum += k;
27+
k++;
28+
} while(k < 5);
29+
30+
return sum;
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test.c
3+
--show-loops --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^main\.hash_[0-9]+$
7+
--
8+
^warning: ignoring
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# CMake configuration for goto-programs regression tests
2+
3+
add_subdirectory(loop-hash-regression)

regression/goto-programs/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# For goto-programs regression tests, see ../Makefile
2+
3+
default: test
4+
5+
include ../../src/config.inc
6+
include ../../src/common
7+
8+
ifeq ($(BUILD_ENV_),MSVC)
9+
exe=../../../src/goto-cc/goto-cl
10+
else
11+
exe=../../../src/goto-cc/goto-cc
12+
endif
13+
14+
test:
15+
@../test.pl -p -c "../chain.sh $(exe) ../../../src/cbmc/cbmc"
16+
17+
clean:
18+
find -name '*.out' -execdir $(RM) '{}' \;
19+
find -name '*.gb' -execdir $(RM) '{}' \;

0 commit comments

Comments
 (0)