Skip to content

Commit 7ab722c

Browse files
Assert type bounds after assign & Fix tests
1 parent 1b63914 commit 7ab722c

34 files changed

+116
-82
lines changed

src/analyses/apron/relationAnalysis.apron.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ struct
256256
if M.tracing then M.traceli "relation" "assign inner %a = %a (%a)" CilType.Varinfo.pretty v d_exp e' d_plainexp e';
257257
if M.tracing then M.trace "relation" "st: %a" RD.pretty apr';
258258
let r = RD.assign_exp ask apr' (RV.local v) e' (no_overflow ask simplified_e) in
259-
if M.tracing then M.traceu "relation" "-> %a" RD.pretty r;
260-
r
259+
let r' = assert_type_bounds ask r v in
260+
if M.tracing then M.traceu "relation" "-> %a" RD.pretty r';
261+
r'
261262
)
262263
)
263264
in
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//SKIP PARAM: --enable ana.int.interval --set ana.activated[+] apron
2+
// NOCRASH (was arithmetic on bottom)
3+
int main(void)
4+
{
5+
int a;
6+
unsigned short b;
7+
int tmp;
8+
9+
b = (unsigned short )a;
10+
11+
if ((int )b + (int )b < (int )b) {
12+
13+
tmp = (int )b;
14+
b += 1;
15+
16+
if (! tmp) {
17+
tmp = 1;
18+
}
19+
20+
}
21+
22+
return 0;
23+
}

tests/regression/78-termination/01-simple-loop-terminating.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int main()
55
{
6-
int i = 1;
6+
unsigned int i = 1;
77

88
while (i <= 10)
99
{

tests/regression/78-termination/03-nested-loop-terminating.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
int main()
55
{
6-
int rows = 3;
7-
int columns = 4;
8-
int i = 1;
6+
unsigned int rows = 3;
7+
unsigned int columns = 4;
8+
unsigned int i = 1;
99

1010
// Outer while loop for rows
1111
while (i <= rows)

tests/regression/78-termination/04-nested-loop-nonterminating.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ int main()
77

88
while (outerCount <= 3)
99
{
10-
int innerCount = 1;
10+
unsigned int innerCount = 1;
1111

1212
while (1) // NONTERMLOOP termination analysis shall mark beginning of while as non-terminating loop
1313
{

tests/regression/78-termination/05-for-loop-terminating.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int main()
55
{
6-
int i;
6+
unsigned int i;
77

88
for (i = 1; i <= 10; i++)
99
{

tests/regression/78-termination/07-nested-for-loop-terminating.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
int main()
55
{
6-
int rows = 3;
7-
int columns = 4;
6+
unsigned int rows = 3;
7+
unsigned int columns = 4;
88

99
// Nested loop to iterate over rows and columns
1010
for (int i = 1; i <= rows; i++)

tests/regression/78-termination/08-nested-for-loop-nonterminating.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int main()
55
{
6-
int outerCount, innerCount;
6+
unsigned int outerCount, innerCount;
77

88
for (outerCount = 1; outerCount <= 3; outerCount++)
99
{

tests/regression/78-termination/09-complex-for-loop-terminating.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <stdio.h>
44

55
int loops0(){
6-
int i, j, k;
6+
unsigned int i, j, k;
77

88
// Outer loop
99
for (i = 1; i <= 5; i++)
@@ -36,7 +36,7 @@ int loops0(){
3636
}
3737

3838
int loops1(){
39-
int i, j, k;
39+
unsigned int i, j, k;
4040

4141
// Loop with conditions
4242
for (i = 1; i <= 10; i++)
@@ -81,7 +81,7 @@ int loops1(){
8181
printf("\n");
8282

8383
// Loop with multiple variables
84-
int a, b, c;
84+
unsigned int a, b, c;
8585
for (a = 1, b = 2, c = 3; a <= 10; a++, b += 2, c += 3)
8686
{
8787
printf("%d %d %d\n", a, b, c);

tests/regression/78-termination/10-complex-loop-terminating.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include <stdio.h>
44

55
int loops0(){
6-
int i = 1;
7-
int j = 1;
8-
int k = 5;
6+
unsigned int i = 1;
7+
unsigned int j = 1;
8+
unsigned int k = 5;
99

1010
// Outer while loop
1111
while (i <= 5)
@@ -84,9 +84,9 @@ int loops0(){
8484

8585
int loops1()
8686
{
87-
int i = 1;
88-
int j = 1;
89-
int k = 5;
87+
unsigned int i = 1;
88+
unsigned int j = 1;
89+
unsigned int k = 5;
9090

9191
// Outer while loop
9292
while (i <= 5)
@@ -145,9 +145,9 @@ int loops1()
145145
}
146146

147147
int loops2(){
148-
int i = 1;
149-
int j = 1;
150-
int k = 5;
148+
unsigned int i = 1;
149+
unsigned int j = 1;
150+
unsigned int k = 5;
151151

152152
// Loop with nested conditions
153153
i = 1;
@@ -197,9 +197,9 @@ int loops2(){
197197
printf("\n");
198198

199199
// Loop with multiple variables
200-
int a = 1;
201-
int b = 2;
202-
int c = 3;
200+
unsigned int a = 1;
201+
unsigned int b = 2;
202+
unsigned int c = 3;
203203
while (a <= 10)
204204
{
205205
printf("%d %d %d\n", a, b, c);
@@ -215,4 +215,4 @@ int main(){
215215
loops1();
216216
loops2();
217217
return 0;
218-
}
218+
}

0 commit comments

Comments
 (0)