Skip to content

Commit 6e41e95

Browse files
WIP add tests for mul_overflow
1 parent 396dfe7 commit 6e41e95

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

regression/cbmc/gcc_builtin_mul_overflow/main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ void check_unsigned_long_long(void)
104104
assert(0 && "reachability");
105105
}
106106

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+
107123
int main(void)
108124
{
109125
check_int();
@@ -112,5 +128,6 @@ int main(void)
112128
check_unsigned();
113129
check_unsigned_long();
114130
check_unsigned_long_long();
131+
check_generic();
115132
return 0;
116133
}

regression/cbmc/gcc_builtin_mul_overflow/test.desc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,14 @@ main.c
3737
\[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
3838
\[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
3939
\[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
4049
^EXIT=10$
4150
^SIGNAL=0$

0 commit comments

Comments
 (0)