Skip to content

Commit 15d4307

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 b4f5800 commit 15d4307

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
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/ansi-c/c_typecheck_code.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ void c_typecheck_baset::typecheck_switch_case(code_switch_caset &code)
535535
exprt &case_expr=code.case_op();
536536
typecheck_expr(case_expr);
537537
implicit_typecast(case_expr, switch_op_type);
538+
make_constant(case_expr);
538539
}
539540
}
540541

@@ -561,6 +562,8 @@ void c_typecheck_baset::typecheck_gcc_switch_case_range(codet &code)
561562
typecheck_expr(code.op1());
562563
implicit_typecast(code.op0(), switch_op_type);
563564
implicit_typecast(code.op1(), switch_op_type);
565+
make_constant(code.op0());
566+
make_constant(code.op1());
564567
}
565568

566569
void c_typecheck_baset::typecheck_gcc_local_label(codet &code)

0 commit comments

Comments
 (0)