Skip to content

Commit efbbfc8

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Use type equality, not base_type_eq in local safe pointers
We no longer need to resort to tag/symbol type resolution.
1 parent 5377c2c commit efbbfc8

File tree

6 files changed

+29
-49
lines changed

6 files changed

+29
-49
lines changed

jbmc/unit/java_bytecode/java_bytecode_instrument/virtual_call_null_checks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ SCENARIO(
7474
// This analysis checks that any usage of a pointer is preceded by an
7575
// assumption that it is non-null
7676
// (e.g. assume(x != nullptr); y = x->...)
77-
local_safe_pointerst safe_pointers(ns);
77+
local_safe_pointerst safe_pointers;
7878
safe_pointers(main_function.body);
7979

8080
for(auto instrit = main_function.body.instructions.begin(),

src/analyses/local_safe_pointers.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Author: Diffblue Ltd
1111

1212
#include "local_safe_pointers.h"
1313

14-
#include <util/base_type.h>
1514
#include <util/expr_iterator.h>
1615
#include <util/expr_util.h>
1716
#include <util/format_expr.h>
@@ -82,8 +81,7 @@ static optionalt<goto_null_checkt> get_null_checked_expr(const exprt &expr)
8281
/// \param goto_program: program to analyse
8382
void local_safe_pointerst::operator()(const goto_programt &goto_program)
8483
{
85-
std::set<exprt, base_type_comparet> checked_expressions(
86-
base_type_comparet{ns});
84+
std::set<exprt, type_comparet> checked_expressions(type_comparet{});
8785

8886
for(const auto &instruction : goto_program.instructions)
8987
{
@@ -98,8 +96,7 @@ void local_safe_pointerst::operator()(const goto_programt &goto_program)
9896
checked_expressions = findit->second;
9997
else
10098
{
101-
checked_expressions =
102-
std::set<exprt, base_type_comparet>(base_type_comparet{ns});
99+
checked_expressions = std::set<exprt, type_comparet>(type_comparet{});
103100
}
104101
}
105102

@@ -179,8 +176,11 @@ void local_safe_pointerst::operator()(const goto_programt &goto_program)
179176
/// \param out: stream to write output to
180177
/// \param goto_program: GOTO program analysed (the same one passed to
181178
/// operator())
179+
/// \param ns: namespace
182180
void local_safe_pointerst::output(
183-
std::ostream &out, const goto_programt &goto_program)
181+
std::ostream &out,
182+
const goto_programt &goto_program,
183+
const namespacet &ns)
184184
{
185185
forall_goto_program_instructions(i_it, goto_program)
186186
{
@@ -220,8 +220,11 @@ void local_safe_pointerst::output(
220220
/// \param out: stream to write output to
221221
/// \param goto_program: GOTO program analysed (the same one passed to
222222
/// operator())
223+
/// \param ns: namespace
223224
void local_safe_pointerst::output_safe_dereferences(
224-
std::ostream &out, const goto_programt &goto_program)
225+
std::ostream &out,
226+
const goto_programt &goto_program,
227+
const namespacet &ns)
225228
{
226229
forall_goto_program_instructions(i_it, goto_program)
227230
{
@@ -274,10 +277,10 @@ bool local_safe_pointerst::is_non_null_at_program_point(
274277
return findit->second.count(*tocheck) != 0;
275278
}
276279

277-
bool local_safe_pointerst::base_type_comparet::operator()(
278-
const exprt &e1, const exprt &e2) const
280+
bool local_safe_pointerst::type_comparet::
281+
operator()(const exprt &e1, const exprt &e2) const
279282
{
280-
if(base_type_eq(e1, e2, ns))
283+
if(e1.type() == e2.type())
281284
return false;
282285
else
283286
return e1 < e2;

src/analyses/local_safe_pointers.h

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,17 @@ Author: Diffblue Ltd
2323
/// possibly-aliasing operations are handled pessimistically.
2424
class local_safe_pointerst
2525
{
26-
/// Comparator that regards base_type_eq expressions as equal, and otherwise
26+
/// Comparator that regards type-equal expressions as equal, and otherwise
2727
/// uses the natural (operator<) ordering on irept.
28-
/// An expression is base_type_eq another one if their types, and types of
29-
/// their subexpressions, are identical except that one may use a symbol_typet
30-
/// while the other uses that type's expanded (namespacet::follow'd) form.
31-
class base_type_comparet
28+
class type_comparet
3229
{
33-
const namespacet &ns;
34-
3530
public:
36-
explicit base_type_comparet(const namespacet &ns)
37-
: ns(ns)
38-
{
39-
}
40-
41-
base_type_comparet(const base_type_comparet &other)
42-
: ns(other.ns)
43-
{
44-
}
45-
46-
base_type_comparet &operator=(const base_type_comparet &other)
47-
{
48-
INVARIANT(&ns == &other.ns, "base_type_comparet: clashing namespaces");
49-
return *this;
50-
}
51-
5231
bool operator()(const exprt &e1, const exprt &e2) const;
5332
};
5433

55-
std::map<unsigned, std::set<exprt, base_type_comparet>> non_null_expressions;
56-
57-
const namespacet &ns;
34+
std::map<unsigned, std::set<exprt, type_comparet>> non_null_expressions;
5835

5936
public:
60-
local_safe_pointerst(const namespacet &ns)
61-
: ns(ns)
62-
{
63-
}
64-
6537
void operator()(const goto_programt &goto_program);
6638

6739
bool is_non_null_at_program_point(
@@ -74,10 +46,15 @@ class local_safe_pointerst
7446
return is_non_null_at_program_point(deref.op(), program_point);
7547
}
7648

77-
void output(std::ostream &stream, const goto_programt &program);
49+
void output(
50+
std::ostream &stream,
51+
const goto_programt &program,
52+
const namespacet &ns);
7853

7954
void output_safe_dereferences(
80-
std::ostream &stream, const goto_programt &program);
55+
std::ostream &stream,
56+
const goto_programt &program,
57+
const namespacet &ns);
8158
};
8259

8360
#endif // CPROVER_ANALYSES_LOCAL_SAFE_POINTERS_H

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,17 @@ int goto_instrument_parse_optionst::doit()
320320

321321
forall_goto_functions(it, goto_model.goto_functions)
322322
{
323-
local_safe_pointerst local_safe_pointers(ns);
323+
local_safe_pointerst local_safe_pointers;
324324
local_safe_pointers(it->second.body);
325325
std::cout << ">>>>\n";
326326
std::cout << ">>>> " << it->first << '\n';
327327
std::cout << ">>>>\n";
328328
if(cmdline.isset("show-local-safe-pointers"))
329-
local_safe_pointers.output(std::cout, it->second.body);
329+
local_safe_pointers.output(std::cout, it->second.body, ns);
330330
else
331331
{
332332
local_safe_pointers.output_safe_dereferences(
333-
std::cout, it->second.body);
333+
std::cout, it->second.body, ns);
334334
}
335335
std::cout << '\n';
336336
}

src/goto-symex/symex_function_call.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void goto_symext::symex_function_call_code(
229229
state.dirty.populate_dirty_for_function(identifier, goto_function);
230230

231231
auto emplace_safe_pointers_result =
232-
state.safe_pointers.emplace(identifier, local_safe_pointerst{ns});
232+
state.safe_pointers.emplace(identifier, local_safe_pointerst{});
233233
if(emplace_safe_pointers_result.second)
234234
emplace_safe_pointers_result.first->second(goto_function.body);
235235

src/goto-symex/symex_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ std::unique_ptr<goto_symext::statet> goto_symext::initialize_entry_point_state(
310310

311311
// initialize support analyses
312312
auto emplace_safe_pointers_result =
313-
state->safe_pointers.emplace(entry_point_id, local_safe_pointerst{ns});
313+
state->safe_pointers.emplace(entry_point_id, local_safe_pointerst{});
314314
if(emplace_safe_pointers_result.second)
315315
emplace_safe_pointers_result.first->second(start_function->body);
316316

0 commit comments

Comments
 (0)