Skip to content

Commit 06dd169

Browse files
committed
dump-c: fix output of _Bool-typed constants
Only __CPROVER_bool-typed constants can be used with exprt::is_true. exprt::is_one's documentation promised that ID_c_bool was supported, which wasn't actually the case. This commit fixes this and makes use of is_one to fix the bug in dump-c.
1 parent 99741b3 commit 06dd169

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <assert.h>
2+
3+
int main()
4+
{
5+
_Bool v;
6+
v = 1;
7+
assert(v == 1);
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--dump-c
4+
VERIFICATION SUCCESSFUL
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
irep
10+
--
11+
Dump-c previously always generated 0 for _Bool or __CPROVER_bool-typed
12+
constants. This test ensures that the value "1" is correctly generated.

src/goto-instrument/goto_program2code.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,14 +1893,20 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
18931893
}
18941894
else if(expr.type().id()==ID_pointer)
18951895
add_local_types(expr.type());
1896-
else if(expr.type().id()==ID_bool ||
1897-
expr.type().id()==ID_c_bool)
1896+
else if(expr.type().id() == ID_bool)
18981897
{
18991898
expr = typecast_exprt(
19001899
from_integer(
19011900
expr.is_true() ? 1 : 0, signedbv_typet(config.ansi_c.int_width)),
19021901
bool_typet());
19031902
}
1903+
else if(expr.type().id() == ID_c_bool)
1904+
{
1905+
expr = typecast_exprt(
1906+
from_integer(
1907+
expr.is_one() ? 1 : 0, signedbv_typet(config.ansi_c.int_width)),
1908+
c_bool_type());
1909+
}
19041910

19051911
const irept &c_sizeof_type=expr.find(ID_C_c_sizeof_type);
19061912

src/util/expr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ bool exprt::is_one() const
146146
CHECK_RETURN(false);
147147
return rat_value.is_one();
148148
}
149-
else if(type_id==ID_unsignedbv || type_id==ID_signedbv)
149+
else if(
150+
type_id == ID_unsignedbv || type_id == ID_signedbv ||
151+
type_id == ID_c_bool || type_id == ID_c_bit_field)
150152
{
151153
const auto width = to_bitvector_type(type()).get_width();
152154
mp_integer int_value =

0 commit comments

Comments
 (0)