Skip to content

Commit 35c0970

Browse files
authored
Merge pull request #141 from diffblue/bugfix/simplify-lhs
Bugfix for LHS simplification
2 parents c763a2a + 9c5e009 commit 35c0970

File tree

14 files changed

+182
-82
lines changed

14 files changed

+182
-82
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void main()
2+
{
3+
int arr[4] = {1, 2, 3, 4};
4+
5+
// No simplification
6+
arr[0] = 1;
7+
8+
// Can simplify
9+
int constant = 1;
10+
arr[constant] = 2;
11+
12+
// No simplification
13+
int nondet;
14+
arr[nondet] = 3;
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
"--variable --arrays"
4+
5+
arr\[0l\] =
6+
arr\[1l\] =
7+
arr\[\(signed long int\)nondet\] =
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
void main()
2+
{
3+
int symbol_a;
4+
int symbol_b;
5+
6+
int nondet;
7+
int * nondet_pointer;
8+
if(nondet > 0)
9+
{
10+
nondet_pointer = &symbol_a;
11+
}
12+
else
13+
{
14+
nondet_pointer = &symbol_b;
15+
}
16+
17+
int *arr[] = { &symbol_a, &symbol_b, nondet_pointer };
18+
19+
// Simplify the pointer
20+
*arr[0] = 1;
21+
22+
// Simplify index and the pointer
23+
int constant1 = 1;
24+
*arr[constant1] = 2;
25+
26+
// Simplify the index but not the pointer
27+
int constant2 = 2;
28+
*arr[constant2] = 3;
29+
30+
// No simplification
31+
int nondet_index;
32+
*arr[nondet_index] = 4;
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
"--variable --arrays --pointers"
4+
5+
symbol_a = 1
6+
symbol_b = 2
7+
\*arr\[2l\] = 3;
8+
\*arr\[\(signed long int\)nondet_index\] = 4;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
void main()
2+
{
3+
int symbol;
4+
5+
int *pointer=&symbol;
6+
7+
// Simplify
8+
*pointer=5;
9+
10+
int nondet;
11+
if(nondet>0)
12+
{
13+
pointer=&nondet;
14+
}
15+
else
16+
{
17+
pointer=&symbol;
18+
}
19+
20+
// No simplification
21+
*pointer=6;
22+
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
main.c
3+
"--variable --pointers"
4+
5+
symbol = 5
6+
\*pointer = 6
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
struct test_struct
2+
{
3+
int * pointer_component;
4+
int array[5];
5+
};
6+
7+
void main()
8+
{
9+
int symbol;
10+
11+
struct test_struct value;
12+
13+
// Simplify a pointer inside a struct
14+
int symbol;
15+
value.pointer_component=&symbol;
16+
17+
// Simplify
18+
*value.pointer_component=5;
19+
20+
int nondet;
21+
if(nondet>0)
22+
{
23+
value.pointer_component=&nondet;
24+
}
25+
else
26+
{
27+
value.pointer_component=&symbol;
28+
}
29+
30+
// No simplification
31+
*value.pointer_component=6;
32+
33+
// Simplify an array
34+
35+
// Can simplify
36+
int constant = 1;
37+
value.array[constant] = 2;
38+
39+
// No simplification
40+
int nondet;
41+
value.array[nondet] = 3;
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
"--variable --arrays --pointers --structs"
4+
5+
symbol = 5
6+
\*value\.pointer_component = 6
7+
value\.array\[1l\] = 2
8+
value\.array\[\(signed long int\)nondet\] = 3
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
void main()
2+
{
3+
int array[] = {1, 2, 3, 4, 5};
4+
5+
int *pointer=array;
6+
7+
// Simplify -> array[0] = 5
8+
*pointer=5;
9+
10+
int nondet;
11+
pointer[nondet]=6;
12+
13+
// TODO: Currently writing to an offset pointer sets the domain to top
14+
// so recreate the variables to reign the domain back in
15+
// This will be addressed by diffblue/cbmc-toyota#118
16+
int new_array[] = {1, 2, 3, 4, 5};
17+
int * new_pointer=new_array;
18+
19+
int constant=1;
20+
new_pointer[constant]=7;
21+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
main.c
3+
"--variable --arrays --pointers"
4+
array\[0l\] = 5
5+
array\[\(signed long int\)nondet\] = 6
6+
new_array\[1l\] = 7

0 commit comments

Comments
 (0)