File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
regression/cbmc/gcc_builtin_mul_overflow Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,22 @@ void check_unsigned_long_long(void)
104
104
assert (0 && "reachability" );
105
105
}
106
106
107
+ void check_generic (void )
108
+ {
109
+ unsigned char small_result ;
110
+ long long big_result ;
111
+
112
+ assert (__builtin_mul_overflow (100 , 100 , & small_result ));
113
+ assert (!__builtin_mul_overflow (100 , 100 , & big_result ));
114
+ assert (big_result == 10000 );
115
+ assert (!__builtin_mul_overflow (10 , 10 , & small_result ));
116
+ assert (small_result == 100 );
117
+ assert (!__builtin_mul_overflow (INT_MAX , INT_MAX , & big_result ));
118
+ assert (big_result == 4611686014132420609ll );
119
+ assert (__builtin_mul_overflow (INT_MAX * 2ll , INT_MAX * 2ll , & big_result ));
120
+ assert (0 && "reachability" );
121
+ }
122
+
107
123
int main (void )
108
124
{
109
125
check_int ();
@@ -112,5 +128,6 @@ int main(void)
112
128
check_unsigned ();
113
129
check_unsigned_long ();
114
130
check_unsigned_long_long ();
131
+ check_generic ();
115
132
return 0 ;
116
133
}
Original file line number Diff line number Diff line change @@ -37,5 +37,14 @@ main.c
37
37
\[check_unsigned_long_long.assertion.4\] line \d+ assertion result == lt_isqrt_of_unsigned_long_long_max \* lt_isqrt_of_unsigned_long_long_max: SUCCESS
38
38
\[check_unsigned_long_long.assertion.5\] line \d+ assertion __builtin_umulll_overflow\( lt_isqrt_of_unsigned_long_long_max << 1, lt_isqrt_of_unsigned_long_long_max << 1, &result\): SUCCESS
39
39
\[check_unsigned_long_long.assertion.6\] line \d+ assertion 0 && "reachability": FAILURE
40
+ \[check_generic.assertion.1\] line \d+ assertion __builtin_mul_overflow\(100, 100, &small_result\): SUCCESS
41
+ \[check_generic.assertion.2\] line \d+ assertion !__builtin_mul_overflow\(100, 100, &big_result\): SUCCESS
42
+ \[check_generic.assertion.3\] line \d+ assertion big_result == 10000: SUCCESS
43
+ \[check_generic.assertion.4\] line \d+ assertion !__builtin_mul_overflow\(10, 10, &small_result\): SUCCESS
44
+ \[check_generic.assertion.5\] line \d+ assertion small_result == 100: SUCCESS
45
+ \[check_generic.assertion.6\] line \d+ assertion !__builtin_mul_overflow\(.*, .*, &big_result\): SUCCESS
46
+ \[check_generic.assertion.7\] line \d+ assertion big_result == 4611686014132420609ll: SUCCESS
47
+ \[check_generic.assertion.8\] line \d+ assertion __builtin_mul_overflow\(.* \* 2ll, .* \* 2ll, &big_result\): SUCCESS
48
+ \[check_generic.assertion.9\] line \d+ assertion 0 && "reachability": FAILURE
40
49
^EXIT=10$
41
50
^SIGNAL=0$
You can’t perform that action at this time.
0 commit comments