Skip to content

Commit 6ee96aa

Browse files
committed
Evaluate expressions that delimit GCC switch/case ranges
Type casts may reasonably occur in here (and maybe also other expressions that evaluate to constants). The regression test addionally covers the case of enum values being used, which works fine (even without this change).
1 parent bbf0d02 commit 6ee96aa

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
typedef enum
2+
{
3+
VALUE_1,
4+
VALUE_2,
5+
VALUE_3,
6+
VALUE_4
7+
} values;
8+
9+
int main()
10+
{
11+
unsigned x;
12+
switch(x)
13+
{
14+
case VALUE_1:
15+
__CPROVER_assert(0, "0 works");
16+
break;
17+
#ifdef __GNUC__
18+
case VALUE_2 ... 3:
19+
#else
20+
case VALUE_2:
21+
case VALUE_3:
22+
case VALUE_4:
23+
#endif
24+
__CPROVER_assert(0, "... works");
25+
break;
26+
default:
27+
__CPROVER_assert(0, "default works");
28+
break;
29+
}
30+
31+
return 0;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
^\*\* 3 of 3 failed
8+
--
9+
^warning: ignoring

src/goto-programs/goto_convert.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ void goto_convertt::convert_gcc_switch_case_range(
406406
throw 0;
407407
}
408408

409-
const auto lb = numeric_cast<mp_integer>(code.op0());
410-
const auto ub = numeric_cast<mp_integer>(code.op1());
409+
const auto lb = numeric_cast<mp_integer>(simplify_expr(code.op0(), ns));
410+
const auto ub = numeric_cast<mp_integer>(simplify_expr(code.op1(), ns));
411411

412412
if(!lb.has_value() || !ub.has_value())
413413
{

0 commit comments

Comments
 (0)