Skip to content

Commit 1e0fa76

Browse files
committed
Support enum-typed constants in format_expr
We should not have to fall back to irept pretty printing for these.
1 parent ed7a0d3 commit 1e0fa76

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
no_duplicate.c
3+
--show-goto-functions
4+
main::1::e = 0 ∨ main::1::e = 1 ∨ main::1::e = 2 ∨ main::1::e = 3
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
type: c_enum_tag
9+
--
10+
This test is to show that format(expr) also works for enum-typed constants.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
enum enm
2+
{
3+
first,
4+
second,
5+
third,
6+
fourth,
7+
};
8+
9+
static enum enm efunc(void)
10+
{
11+
return second;
12+
}
13+
14+
int main(void)
15+
{
16+
enum enm e = efunc();
17+
__CPROVER_assert(__CPROVER_enum_is_in_range(e), "enum failure");
18+
return (e);
19+
}

src/util/format_expr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ static std::ostream &format_rec(std::ostream &os, const constant_exprt &src)
204204
<< format(pointer_type.base_type()) << ')';
205205
}
206206
}
207+
else if(type == ID_c_enum_tag)
208+
{
209+
return os << string2integer(id2string(src.get_value()), 16);
210+
}
207211
else
208212
return os << src.pretty();
209213
}

0 commit comments

Comments
 (0)