File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
regression/cbmc/gcc_builtin_sub_overflow Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,23 @@ void check_unsigned_long_long(void)
71
71
assert (0 && "reachability" );
72
72
}
73
73
74
+ void check_generic (void )
75
+ {
76
+ unsigned char small_result ;
77
+ long long big_result ;
78
+
79
+ assert (__builtin_sub_overflow (5 , 10 , & small_result ));
80
+ assert (!__builtin_sub_overflow (5 , 10 , & big_result ));
81
+ assert (big_result == -5ll );
82
+ assert (!__builtin_sub_overflow (10 , 5 , & small_result ));
83
+ assert (small_result == 5 );
84
+ assert (!__builtin_sub_overflow (10 , 5 , & big_result ));
85
+ assert (big_result == 5ll );
86
+ assert (!__builtin_sub_overflow (INT_MIN , INT_MAX , & big_result ));
87
+ assert (big_result == 2ll * INT_MIN + 1 );
88
+ assert (0 && "reachability" );
89
+ }
90
+
74
91
int main (void )
75
92
{
76
93
check_int ();
@@ -79,4 +96,5 @@ int main(void)
79
96
check_unsigned ();
80
97
check_unsigned_long ();
81
98
check_unsigned_long_long ();
99
+ check_generic ();
82
100
}
Original file line number Diff line number Diff line change @@ -40,5 +40,15 @@ main.c
40
40
\[check_unsigned_long_long.assertion.5\] line \d+ assertion result == 0ull: SUCCESS
41
41
\[check_unsigned_long_long.assertion.6\] line \d+ assertion __builtin_usubll_overflow\(.* / 2ull, .*, &result\): SUCCESS
42
42
\[check_unsigned_long_long.assertion.7\] line \d+ assertion 0 && "reachability": FAILURE
43
+ \[check_generic.assertion.1\] line 79 assertion __builtin_sub_overflow\(5, 10, &small_result\): SUCCESS
44
+ \[check_generic.assertion.2\] line 80 assertion !__builtin_sub_overflow\(5, 10, &big_result\): SUCCESS
45
+ \[check_generic.assertion.3\] line 81 assertion big_result == -5ll: SUCCESS
46
+ \[check_generic.assertion.4\] line 82 assertion !__builtin_sub_overflow\(10, 5, &small_result\): SUCCESS
47
+ \[check_generic.assertion.5\] line 83 assertion small_result == 5: SUCCESS
48
+ \[check_generic.assertion.6\] line 84 assertion !__builtin_sub_overflow\(10, 5, &big_result\): SUCCESS
49
+ \[check_generic.assertion.7\] line 85 assertion big_result == 5ll: SUCCESS
50
+ \[check_generic.assertion.8\] line 86 assertion !__builtin_sub_overflow\(.*, .*, &big_result\): SUCCESS
51
+ \[check_generic.assertion.9\] line 87 assertion big_result == 2ll \* .* \+ 1: SUCCESS
52
+ \[check_generic.assertion.10\] line 88 assertion 0 && "reachability": FAILURE
43
53
^EXIT=10$
44
54
^SIGNAL=0$
You can’t perform that action at this time.
0 commit comments