Skip to content

Commit 052a8d3

Browse files
author
Daniel Kroening
committed
improve test for signed left-shift overflows
1 parent a55065a commit 052a8d3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
int main()
22
{
33
unsigned char x;
4+
5+
// signed, owing to promotion, and may overflow
46
unsigned r=x << ((sizeof(unsigned)-1)*8);
7+
8+
// signed, owing to promotion, and cannot overflow
59
r=x << ((sizeof(unsigned)-1)*8-1);
10+
11+
// unsigned
612
r=(unsigned)x << ((sizeof(unsigned)-1)*8);
713

8-
int s=-1 << ((sizeof(int)-1)*8);
9-
s=-256 << ((sizeof(int)-1)*8);
14+
// negative value or zero, not an overflow
15+
int s = -x << ((sizeof(int) - 1) * 8);
16+
17+
// overflow
18+
s = 1 << x;
19+
1020
return 0;
1121
}

regression/cbmc/Overflow_Leftshift1/test.desc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ main.c
33
--signed-overflow-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[.*\] .* arithmetic overflow on signed shl in .*: FAILURE$
7-
^\*\* 2 of 4 failed
6+
^\[.*\] line 6 arithmetic overflow on signed shl in .*: FAILURE$
7+
^\[.*\] line 9 arithmetic overflow on signed shl in .*: SUCCESS$
8+
^\[.*\] line 15 arithmetic overflow on signed shl in .*: SUCCESS$
9+
^\[.*\] line 18 arithmetic overflow on signed shl in .*: FAILURE$
10+
^\*\* 2 of 5 failed
811
^VERIFICATION FAILED$
912
--
1013
^warning: ignoring
14+
^\[.*\] line 12 arithmetic overflow on signed shl in .*: .*
15+
^\[.*\] line 21 arithmetic overflow on signed shl in .*: .*

0 commit comments

Comments
 (0)