Skip to content

Commit ce9aa98

Browse files
author
Daniel Kroening
authored
Merge pull request #357 from peterschrammel/fix-c-bool-xml-output
Fix _Bool XML output
2 parents a0cd5ec + aaa5348 commit ce9aa98

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

regression/cbmc/c99_Bool/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
3+
void foo(_Bool y)
4+
{
5+
int x;
6+
if(y)
7+
{
8+
x=(int)y;
9+
assert(x==1);
10+
}
11+
}

regression/cbmc/c99_Bool/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function foo
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ exprt::operandst build_function_environment(
7373

7474
init_code.add(decl);
7575

76+
// nondet init for _Bool
77+
if(decl.symbol().type().id()==ID_c_bool)
78+
{
79+
code_assignt assign(
80+
decl.symbol(),
81+
typecast_exprt(
82+
side_effect_expr_nondett(bool_typet()),
83+
decl.symbol().type()));
84+
85+
init_code.move_to_operands(assign);
86+
}
87+
7688
codet input(ID_input);
7789
input.operands().resize(2);
7890

src/util/json_expr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ json_objectt json(
265265
result["binary"]=json_stringt(expr.is_true()?"1":"0");
266266
result["data"]=jsont::json_boolean(expr.is_true());
267267
}
268+
else if(type.id()==ID_c_bool)
269+
{
270+
result["name"]=json_stringt("integer");
271+
result["c_type"]=json_stringt("_Bool");
272+
result["binary"]=json_stringt(expr.get_string(ID_value));
273+
mp_integer b;
274+
to_integer(to_constant_expr(expr), b);
275+
result["data"]=json_stringt(integer2string(b));
276+
}
268277
else
269278
{
270279
result["name"]=json_stringt("unknown");

src/util/xml_expr.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ xmlt xml(
126126
{
127127
result.name="vector";
128128
result.new_element("subtype").new_element()=xml(type.subtype(), ns);
129-
result.new_element("size").new_element()=xml(to_vector_type(type).size(), ns);
129+
result.new_element("size").new_element()=
130+
xml(to_vector_type(type).size(), ns);
130131
}
131132
else if(type.id()==ID_struct)
132133
{
@@ -263,6 +264,15 @@ xmlt xml(
263264
result.set_attribute("binary", expr.is_true()?"1":"0");
264265
result.data=expr.is_true()?"TRUE":"FALSE";
265266
}
267+
else if(type.id()==ID_c_bool)
268+
{
269+
result.name="integer";
270+
result.set_attribute("c_type", "_Bool");
271+
result.set_attribute("binary", expr.get_string(ID_value));
272+
mp_integer b;
273+
to_integer(to_constant_expr(expr), b);
274+
result.data=integer2string(b);
275+
}
266276
else
267277
{
268278
result.name="unknown";
@@ -309,7 +319,8 @@ xmlt xml(
309319

310320
xmlt &e=result.new_element("member");
311321
e.new_element(xml(expr.op0(), ns));
312-
e.set_attribute("member_name",
322+
e.set_attribute(
323+
"member_name",
313324
id2string(to_union_expr(expr).get_component_name()));
314325
}
315326
else

0 commit comments

Comments
 (0)