Skip to content

Commit e9755ae

Browse files
committed
Use type equality, not base_type_eq in local safe pointers
We no longer need to resort to tag/symbol type resolution. This enables partial revert of 959c7a5 (Bugfix: Maintain safe_pointers per-path) as we no longer need to maintain a namespacet in local_safe_pointerst. On SV-COMP's ReachSafety-ECA, copying safe_pointers accounted for 14% of the time spent in goto_symext::symex_goto (715 of 5119 seconds).
1 parent ed6796d commit e9755ae

File tree

10 files changed

+40
-62
lines changed

10 files changed

+40
-62
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
@@ -319,17 +319,17 @@ int goto_instrument_parse_optionst::doit()
319319

320320
forall_goto_functions(it, goto_model.goto_functions)
321321
{
322-
local_safe_pointerst local_safe_pointers(ns);
322+
local_safe_pointerst local_safe_pointers;
323323
local_safe_pointers(it->second.body);
324324
std::cout << ">>>>\n";
325325
std::cout << ">>>> " << it->first << '\n';
326326
std::cout << ">>>>\n";
327327
if(cmdline.isset("show-local-safe-pointers"))
328-
local_safe_pointers.output(std::cout, it->second.body);
328+
local_safe_pointers.output(std::cout, it->second.body, ns);
329329
else
330330
{
331331
local_safe_pointers.output_safe_dereferences(
332-
std::cout, it->second.body);
332+
std::cout, it->second.body, ns);
333333
}
334334
std::cout << '\n';
335335
}

src/goto-symex/goto_symex.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ Author: Daniel Kroening, [email protected]
1717

1818
#include <goto-programs/abstract_goto_model.h>
1919

20-
#include "goto_symex_state.h"
2120
#include "path_storage.h"
22-
#include "symex_target_equation.h"
2321

2422
class byte_extract_exprt;
2523
class typet;

src/goto-symex/goto_symex_state.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Author: Daniel Kroening, [email protected]
1616
#include <unordered_set>
1717

1818
#include <analyses/dirty.h>
19-
#include <analyses/local_safe_pointers.h>
2019

2120
#include <util/invariant.h>
2221
#include <util/guard.h>
@@ -68,7 +67,6 @@ class goto_statet
6867
/// Threads
6968
unsigned atomic_section_id = 0;
7069

71-
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
7270
unsigned total_vccs = 0;
7371
unsigned remaining_vccs = 0;
7472

@@ -317,7 +315,6 @@ inline goto_statet::goto_statet(const class goto_symex_statet &s)
317315
source(s.source),
318316
propagation(s.propagation),
319317
atomic_section_id(s.atomic_section_id),
320-
safe_pointers(s.safe_pointers),
321318
total_vccs(s.total_vccs),
322319
remaining_vccs(s.remaining_vccs)
323320
{

src/goto-symex/path_storage.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
#ifndef CPROVER_GOTO_SYMEX_PATH_STORAGE_H
66
#define CPROVER_GOTO_SYMEX_PATH_STORAGE_H
77

8-
#include "goto_symex_state.h"
9-
#include "symex_target_equation.h"
10-
11-
#include <util/options.h>
128
#include <util/cmdline.h>
13-
#include <util/ui_message.h>
149
#include <util/invariant.h>
10+
#include <util/message.h>
11+
#include <util/options.h>
12+
13+
#include <analyses/local_safe_pointers.h>
1514

1615
#include <memory>
1716

17+
#include "goto_symex_state.h"
18+
#include "symex_target_equation.h"
19+
1820
/// Functor generating fresh nondet symbols
1921
class symex_nondet_generatort
2022
{
@@ -90,6 +92,8 @@ class path_storaget
9092
/// Counter for nondet objects, which require unique names
9193
symex_nondet_generatort build_symex_nondet;
9294

95+
std::unordered_map<irep_idt, local_safe_pointerst> safe_pointers;
96+
9397
private:
9498
// Derived classes should override these methods, allowing the base class to
9599
// enforce preconditions.

src/goto-symex/symex_dereference.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,8 @@ void goto_symext::dereference_rec(
262262
{
263263
get_original_name(to_check);
264264

265-
expr_is_not_null =
266-
state.safe_pointers.at(expr_function).is_safe_dereference(
267-
to_check, state.source.pc);
265+
expr_is_not_null = path_storage.safe_pointers.at(expr_function)
266+
.is_safe_dereference(to_check, state.source.pc);
268267
}
269268
}
270269

src/goto-symex/symex_function_call.cpp

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

242242
auto emplace_safe_pointers_result =
243-
state.safe_pointers.emplace(identifier, local_safe_pointerst{ns});
243+
path_storage.safe_pointers.emplace(identifier, local_safe_pointerst{});
244244
if(emplace_safe_pointers_result.second)
245245
emplace_safe_pointers_result.first->second(goto_function.body);
246246

src/goto-symex/symex_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void goto_symext::initialize_entry_point(
178178
state.top().hidden_function = entry_point_function.is_hidden();
179179

180180
auto emplace_safe_pointers_result =
181-
state.safe_pointers.emplace(function_id, local_safe_pointerst{ns});
181+
path_storage.safe_pointers.emplace(function_id, local_safe_pointerst{});
182182
if(emplace_safe_pointers_result.second)
183183
emplace_safe_pointers_result.first->second(entry_point_function.body);
184184

0 commit comments

Comments
 (0)