Skip to content

Commit 07dec16

Browse files
Do not use side_effect_expr_nondett in recursive_initialization
If we use side_effect_expr_nondett then dump_c will generation function calls to functions with names like `nondet_int` without declaration. This is a problem because it’ll lead the C frontend to complain about undeclared identifiers and such. To fix this, we changed goto-harness to just not use side_effect_expr_nondett at all (better long term fix would be to make sure `dump_c` outputs declarations too).
1 parent 823782c commit 07dec16

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <assert.h>
2+
3+
void test_function(int test)
4+
{
5+
assert(test != 42);
6+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CORE
2+
test.c
3+
--function test_function --harness-type call-function
4+
\[test_function\.assertion\.1\] line \d+ assertion test != 42
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
nondet_signed_int
9+
--
10+
If we use side_effect_expr_nondett then dump_c will generation function calls
11+
to functions with names like nondet_signed_int without declaration.
12+
This can cause problems around usability.
13+
14+
To fix this, we changed goto-harness to just not use side_effect_expr_nondett
15+
at all.
16+
17+
This test tests for the absence the use for these things.

src/goto-harness/recursive_initialization.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ void recursive_initializationt::initialize(
169169
goto_model.symbol_table.lookup_ref(fun_name);
170170
const auto proper_init_case = code_function_callt{
171171
fun_symbol.symbol_expr(), {depth, address_of_exprt{lhs}}};
172-
172+
const auto should_make_equal =
173+
get_fresh_local_typed_symexpr("should_make_equal", bool_typet{});
174+
body.add(code_declt{should_make_equal});
173175
body.add(code_ifthenelset{
174-
side_effect_expr_nondett{bool_typet{}, source_locationt{}},
175-
set_equal_case,
176-
proper_init_case});
176+
should_make_equal, set_equal_case, proper_init_case});
177177
}
178178
else
179179
{
@@ -693,9 +693,12 @@ code_blockt recursive_initializationt::build_pointer_constructor(
693693
code_blockt null_and_return{{assign_null, code_returnt{}}};
694694
body.add(code_ifthenelset{conjunction(should_not_recurse), null_and_return});
695695

696+
const auto should_recurse_nondet =
697+
get_fresh_local_typed_symexpr("should_recurse_nondet", bool_typet{});
698+
body.add(code_declt{should_recurse_nondet});
696699
exprt::operandst should_recurse_ops{
697700
binary_predicate_exprt{depth, ID_lt, get_symbol_expr(min_depth_var_name)},
698-
side_effect_expr_nondett{bool_typet{}, source_locationt{}}};
701+
should_recurse_nondet};
699702
code_blockt then_case{};
700703

701704
code_assignt seen_assign_prev{};
@@ -753,8 +756,10 @@ code_blockt recursive_initializationt::build_array_string_constructor(
753756
{
754757
index_exprt index_expr{dereference_exprt{result},
755758
from_integer(index, size_type())};
756-
body.add(code_assignt{
757-
index_expr, side_effect_expr_nondett{char_type(), source_locationt{}}});
759+
auto const nondet_char =
760+
get_fresh_local_typed_symexpr("nondet_char", char_type());
761+
body.add(code_declt{nondet_char});
762+
body.add(code_assignt{index_expr, nondet_char});
758763
body.add(code_assumet{
759764
notequal_exprt{index_expr, from_integer(0, array_type.subtype())}});
760765
}
@@ -830,9 +835,10 @@ code_blockt recursive_initializationt::build_nondet_constructor(
830835
{
831836
PRECONDITION(result.type().id() == ID_pointer);
832837
code_blockt body{};
833-
body.add(code_assignt{
834-
dereference_exprt{result},
835-
side_effect_expr_nondett{result.type().subtype(), source_locationt{}}});
838+
auto const nondet_symbol =
839+
get_fresh_local_typed_symexpr("nondet", result.type().subtype());
840+
body.add(code_declt{nondet_symbol});
841+
body.add(code_assignt{dereference_exprt{result}, nondet_symbol});
836842
return body;
837843
}
838844

@@ -1029,10 +1035,6 @@ code_blockt recursive_initializationt::build_function_pointer_constructor(
10291035
const auto function_pointer_selector =
10301036
get_fresh_local_symexpr("function_pointer_selector");
10311037
body.add(code_declt{function_pointer_selector});
1032-
body.add(
1033-
code_assignt{function_pointer_selector,
1034-
side_effect_expr_nondett{function_pointer_selector.type(),
1035-
source_locationt{}}});
10361038
auto function_pointer_index = std::size_t{0};
10371039

10381040
for(const auto &target : targets)

0 commit comments

Comments
 (0)