Skip to content

Commit d3cb2d3

Browse files
Fix C enum JSON output
The subtype must be used.
1 parent 79ea945 commit d3cb2d3

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

regression/cbmc/enum-trace1/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <assert.h>
2+
3+
enum ENUM
4+
{
5+
E1,
6+
E2,
7+
E3
8+
};
9+
10+
typedef enum ENUMT { T1, T2, T3 } enum_t;
11+
12+
void test(enum ENUM e, enum_t t)
13+
{
14+
enum ENUM ee = e;
15+
enum_t tt = t;
16+
17+
assert(ee != tt);
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--json-ui --function test --trace
4+
activate-multi-line-match
5+
EXIT=10
6+
SIGNAL=0
7+
VERIFICATION FAILED
8+
\{\n\s*"hidden": false,\n\s*"inputID": "e",\n\s*"internal": true,\n\s*"mode": "C",\n\s*"sourceLocation": \{(\n.*)*\},\n\s*"stepType": "input",\n\s*"thread": 0,\n\s*"values": \[\n\s*\{\n\s*"binary": "000000000000000000000000000000(0|1){2}",\n\s*"data": ".*E(1|2|3)",\n\s*"name": "integer",\n\s*"type": "enum",\n\s*"width": 32\n\s*\}\n\s*\]\n\s*\},
9+
\{\n\s*"hidden": false,\n\s*"inputID": "t",\n\s*"internal": true,\n\s*"mode": "C",\n\s*"sourceLocation": \{(\n.*)*\},\n\s*"stepType": "input",\n\s*"thread": 0,\n\s*"values": \[\n\s*\{\n\s*"binary": "000000000000000000000000000000(0|1){2}",\n\s*"data": ".*T(1|2|3)",\n\s*"name": "integer",\n\s*"type": "enum",\n\s*"width": 32\n\s*\}\n\s*\]\n\s*\},
10+
--
11+
^warning: ignoring

src/goto-programs/json_expr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ json_objectt json(const typet &type, const namespacet &ns, const irep_idt &mode)
206206

207207
static std::string binary(const constant_exprt &src)
208208
{
209-
const auto width = to_bitvector_type(src.type()).get_width();
209+
std::size_t width;
210+
if(src.type().id() == ID_c_enum)
211+
width = to_bitvector_type(to_c_enum_type(src.type()).subtype()).get_width();
212+
else
213+
width = to_bitvector_type(src.type()).get_width();
210214
const auto int_val = bvrep2integer(src.get_value(), width, false);
211215
return integer2binary(int_val, width);
212216
}

0 commit comments

Comments
 (0)