Skip to content

Commit fd9f697

Browse files
Add generic sub tests
1 parent 6e41e95 commit fd9f697

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

regression/cbmc/gcc_builtin_sub_overflow/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,23 @@ void check_unsigned_long_long(void)
7171
assert(0 && "reachability");
7272
}
7373

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+
7491
int main(void)
7592
{
7693
check_int();
@@ -79,4 +96,5 @@ int main(void)
7996
check_unsigned();
8097
check_unsigned_long();
8198
check_unsigned_long_long();
99+
check_generic();
82100
}

regression/cbmc/gcc_builtin_sub_overflow/test.desc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,15 @@ main.c
4040
\[check_unsigned_long_long.assertion.5\] line \d+ assertion result == 0ull: SUCCESS
4141
\[check_unsigned_long_long.assertion.6\] line \d+ assertion __builtin_usubll_overflow\(.* / 2ull, .*, &result\): SUCCESS
4242
\[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
4353
^EXIT=10$
4454
^SIGNAL=0$

0 commit comments

Comments
 (0)