Skip to content

Commit 4ee2683

Browse files
authored
Merge pull request #5687 from tautschnig/graphml-enum
graphml-witnesses should not use enum values or typedef names
2 parents 1c0a36b + 33206c1 commit 4ee2683

File tree

6 files changed

+48
-20
lines changed

6 files changed

+48
-20
lines changed

regression/cbmc/graphml_witness1/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ main.c
4949
<edge source="[0-9\.]*" target="[0-9\.]*">
5050
<data key="originfile">main.c</data>
5151
<data key="startline">15</data>
52+
<data key="assumption">next_field = [01];</data>
5253
<data key="assumption.scope">remove_one</data>
5354
</edge>
5455
<node id="[0-9\.]*">

regression/cbmc/graphml_witness2/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
#include <stdlib.h>
2+
13
extern void __VERIFIER_error();
24

3-
static float one(float *foo)
5+
static size_t one(size_t *foo)
46
{
57
return *foo;
68
}
79

8-
static float two(float *foo)
10+
static size_t two(size_t *foo)
911
{
1012
return *foo;
1113
}
1214

13-
float x = 0;
15+
size_t x = 0;
1416

1517
void step()
1618
{
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
CORE
22
main.c
3-
--graphml-witness - --unwindset main.0:1 --unwinding-assertions
3+
--graphml-witness - --unwindset main.0:1 --unwinding-assertions --stack-trace
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
7-
<data key="assumption">foo = \(\(float \*\)0\);</data>
7+
<data key="assumption">foo = \(\(unsigned long( long)? int \*\)0\);</data>
88
<data key="assumption.scope">one</data>
99
--
1010
^warning: ignoring
11+
__CPROVER_size_t
12+
--
13+
In the GraphML witness, typedef names should be expanded.

regression/memory-analyzer/cycles/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
cycles.gb
33
--breakpoint process_buffer --symbols buffer
4-
cycle_buffer_entry_t tmp;
4+
struct cycle_buffer_entry tmp;
55
char tmp\$0\[\];
66
struct cycle_buffer_entry tmp\$1;
77
char tmp\$2\[\];

src/ansi-c/expr2c.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ expr2c_configurationt expr2c_configurationt::default_configuration
4343
true,
4444
"TRUE",
4545
"FALSE",
46-
true
46+
true,
47+
false,
48+
false
4749
};
4850

4951
expr2c_configurationt expr2c_configurationt::clean_configuration
@@ -53,7 +55,9 @@ expr2c_configurationt expr2c_configurationt::clean_configuration
5355
false,
5456
"1",
5557
"0",
56-
false
58+
false,
59+
true,
60+
true
5761
};
5862

5963
// clang-format on
@@ -196,7 +200,7 @@ std::string expr2ct::convert_rec(
196200

197201
std::string d = declarator.empty() ? declarator : " " + declarator;
198202

199-
if(src.find(ID_C_typedef).is_not_nil())
203+
if(!configuration.expand_typedef && src.find(ID_C_typedef).is_not_nil())
200204
{
201205
return q+id2string(src.get(ID_C_typedef))+d;
202206
}
@@ -1709,22 +1713,29 @@ std::string expr2ct::convert_constant(
17091713
if(c_enum_type.id()!=ID_c_enum)
17101714
return convert_norep(src, precedence);
17111715

1712-
const c_enum_typet::memberst &members=
1713-
to_c_enum_type(c_enum_type).members();
1714-
1715-
for(const auto &member : members)
1716+
if(!configuration.print_enum_int_value)
17161717
{
1717-
if(member.get_value() == value)
1718-
return "/*enum*/" + id2string(member.get_base_name());
1718+
const c_enum_typet::memberst &members =
1719+
to_c_enum_type(c_enum_type).members();
1720+
1721+
for(const auto &member : members)
1722+
{
1723+
if(member.get_value() == value)
1724+
return "/*enum*/" + id2string(member.get_base_name());
1725+
}
17191726
}
17201727

1721-
// failed...
1728+
// lookup failed or enum is to be output as integer
17221729
const bool is_signed = c_enum_type.subtype().id() == ID_signedbv;
17231730
const auto width = to_bitvector_type(c_enum_type.subtype()).get_width();
17241731

1725-
mp_integer int_value = bvrep2integer(value, width, is_signed);
1732+
std::string value_as_string =
1733+
integer2string(bvrep2integer(value, width, is_signed));
17261734

1727-
return "/*enum*/"+integer2string(int_value);
1735+
if(configuration.print_enum_int_value)
1736+
return value_as_string;
1737+
else
1738+
return "/*enum*/" + value_as_string;
17281739
}
17291740
else if(type.id()==ID_rational)
17301741
return convert_norep(src, precedence);

src/ansi-c/expr2c.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,30 @@ struct expr2c_configurationt final
3939
/// This is the string that will be printed for null pointers
4040
bool use_library_macros;
4141

42+
/// When printing an enum-typed constant, print the integer representation
43+
bool print_enum_int_value;
44+
45+
/// Print the expanded type instead of a typedef name, even when a typedef is
46+
/// present
47+
bool expand_typedef;
48+
4249
expr2c_configurationt(
4350
const bool include_struct_padding_components,
4451
const bool print_struct_body_in_type,
4552
const bool include_array_size,
4653
const std::string &true_string,
4754
const std::string &false_string,
48-
const bool use_library_macros)
55+
const bool use_library_macros,
56+
const bool print_enum_int_value,
57+
const bool expand_typedef)
4958
: include_struct_padding_components(include_struct_padding_components),
5059
print_struct_body_in_type(print_struct_body_in_type),
5160
include_array_size(include_array_size),
5261
true_string(true_string),
5362
false_string(false_string),
54-
use_library_macros(use_library_macros)
63+
use_library_macros(use_library_macros),
64+
print_enum_int_value(print_enum_int_value),
65+
expand_typedef(expand_typedef)
5566
{
5667
}
5768

0 commit comments

Comments
 (0)