Skip to content

Commit 6db85da

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Fix based on comments
1 parent 7318812 commit 6db85da

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

src/goto-programs/goto_program.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ void goto_programt::instructiont::validate(
749749
DATA_CHECK_WITH_DIAGNOSTICS(
750750
vm,
751751
!ns.lookup(to_code_decl(code).get_identifier(), table_symbol),
752-
"declaring unknown symbol: " +
753-
id2string(to_code_decl(code).get_identifier()),
752+
"declared symbols should be known",
753+
id2string(to_code_decl(code).get_identifier()),
754754
source_location);
755755
break;
756756
case DEAD:
@@ -762,8 +762,8 @@ void goto_programt::instructiont::validate(
762762
DATA_CHECK_WITH_DIAGNOSTICS(
763763
vm,
764764
!ns.lookup(to_code_dead(code).get_identifier(), table_symbol),
765-
"removing unknown symbol: " +
766-
id2string(to_code_dead(code).get_identifier()) + " from scope",
765+
"removed symbols should be known",
766+
id2string(to_code_dead(code).get_identifier()),
767767
source_location);
768768
break;
769769
case FUNCTION_CALL:

src/util/std_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ bool evaluates_to_boolean(const exprt &e)
215215
if(e.type().id() != ID_bool)
216216
return false;
217217
if(e.id() == ID_typecast)
218-
return e.type().id() == ID_bool;
218+
return true;
219219

220220
// Boolean constants
221221
if(e.id() == ID_true || e.id() == ID_false)

unit/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ SRC += analyses/ai/ai.cpp \
1717
compound_block_locations.cpp \
1818
goto-programs/goto_trace_output.cpp \
1919
goto-programs/goto_program_assume.cpp \
20+
goto-programs/goto_program_dead.cpp \
2021
goto-programs/goto_program_declaration.cpp \
2122
goto-programs/goto_program_function_call.cpp \
2223
goto-programs/goto_program_goto_target.cpp \
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for goto_program::validate
4+
5+
Author: Diffblue Ltd.
6+
7+
\*******************************************************************/
8+
9+
#include <goto-programs/goto_function.h>
10+
#include <testing-utils/catch.hpp>
11+
#include <util/arith_tools.h>
12+
13+
SCENARIO(
14+
"Validation of well-formed symbol removing codes",
15+
"[core][goto-programs][validate]")
16+
{
17+
GIVEN("A program with one symbol removal")
18+
{
19+
symbol_tablet symbol_table;
20+
const signedbv_typet type1(32);
21+
22+
symbolt var_symbol;
23+
irep_idt var_symbol_name = "a";
24+
var_symbol.type = type1;
25+
var_symbol.name = var_symbol_name;
26+
symbol_exprt var_a(var_symbol_name, type1);
27+
28+
goto_functiont goto_function;
29+
auto &instructions = goto_function.body.instructions;
30+
instructions.emplace_back(goto_program_instruction_typet::DEAD);
31+
code_deadt removal(var_a);
32+
instructions.back().make_dead();
33+
instructions.back().code = removal;
34+
35+
WHEN("Removing known symbol")
36+
{
37+
symbol_table.insert(var_symbol);
38+
const namespacet ns(symbol_table);
39+
40+
THEN("The consistency check succeeds")
41+
{
42+
goto_function.body.validate(ns, validation_modet::INVARIANT);
43+
REQUIRE(true);
44+
}
45+
}
46+
47+
WHEN("Removing unknown symbol")
48+
{
49+
const namespacet ns(symbol_table);
50+
51+
THEN("The consistency check fails")
52+
{
53+
bool caught = false;
54+
try
55+
{
56+
goto_function.body.validate(ns, validation_modet::EXCEPTION);
57+
}
58+
catch(incorrect_goto_program_exceptiont &e)
59+
{
60+
caught = true;
61+
}
62+
REQUIRE(caught);
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)