File tree 2 files changed +19
-4
lines changed
regression/cbmc/Overflow_Leftshift1 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1
1
int main ()
2
2
{
3
3
unsigned char x ;
4
+
5
+ // signed, owing to promotion, and may overflow
4
6
unsigned r = x << ((sizeof (unsigned )-1 )* 8 );
7
+
8
+ // signed, owing to promotion, and cannot overflow
5
9
r = x << ((sizeof (unsigned )-1 )* 8 - 1 );
10
+
11
+ // unsigned
6
12
r = (unsigned )x << ((sizeof (unsigned )-1 )* 8 );
7
13
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
+
10
20
return 0 ;
11
21
}
Original file line number Diff line number Diff line change 3
3
--signed-overflow-check
4
4
^EXIT=10$
5
5
^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
8
11
^VERIFICATION FAILED$
9
12
--
10
13
^warning: ignoring
14
+ ^\[.*\] line 12 arithmetic overflow on signed shl in .*: .*
15
+ ^\[.*\] line 21 arithmetic overflow on signed shl in .*: .*
You can’t perform that action at this time.
0 commit comments