Skip to content

Commit 9c188f4

Browse files
Don't use find_or_create_symbol_expr for symbols that must already exist
Remove find_or_create_symbol_expr - it had an assertion that the symbol existed in it because it should never be called for a symbol that doesn't exist Instead make sure that the symbol exists by using the single-argument version of lookup
1 parent f2417d6 commit 9c188f4

File tree

2 files changed

+7
-38
lines changed

2 files changed

+7
-38
lines changed

src/taint-analysis/taint_program.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016-2017 Diffblue Limited. All Rights Reserved.
1+
// Copyright 2016-2018 Diffblue Limited. All Rights Reserved.
22

33
/// \file
44
/// taint_programt
@@ -12,11 +12,6 @@
1212
#include <analyses/call_graph_helpers.h>
1313
#include <unordered_set>
1414

15-
extern symbol_exprt find_or_create_symbol_expr(
16-
const namespacet &ns,
17-
const irep_idt &symbol_name,
18-
const typet &symbol_type);
19-
2015
static void build_NONDET_retvals_replacements(
2116
const goto_modelt &model,
2217
const namespacet &ns,
@@ -98,9 +93,6 @@ static void build_NONDET_retvals_replacements(
9893
const irep_idt &callee_ident=
9994
to_symbol_expr(fn_call.function()).get_identifier();
10095

101-
const code_typet &fn_type=
102-
model.goto_functions.function_map.at(callee_ident).type;
103-
10496
const code_assignt &asgn=to_code_assign(next_instr_it->code);
10597
if(asgn.rhs().id()!=ID_side_effect)
10698
continue;
@@ -110,10 +102,7 @@ static void build_NONDET_retvals_replacements(
110102
replacements.insert(
111103
{
112104
next_instr_it,
113-
find_or_create_symbol_expr(
114-
ns,
115-
as_string(callee_ident)+RETURN_VALUE_SUFFIX,
116-
fn_type.return_type())
105+
ns.lookup(id2string(callee_ident) + RETURN_VALUE_SUFFIX).symbol_expr()
117106
});
118107
}
119108
}

src/taint-analysis/taint_summary.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -342,22 +342,6 @@ std::string taint_summaryt::description() const noexcept
342342
///
343343
////////////////////////////////////////////////////////////////////////////////
344344

345-
346-
symbol_exprt find_or_create_symbol_expr(
347-
const namespacet &ns,
348-
const irep_idt &symbol_name,
349-
const typet &symbol_type)
350-
{
351-
const symbolt *symbol_ptr;
352-
if(ns.lookup(symbol_name, symbol_ptr))
353-
{
354-
assert(false);
355-
return symbol_exprt(symbol_name, symbol_type);
356-
}
357-
assert(symbol_ptr!=nullptr);
358-
return symbol_ptr->symbol_expr();
359-
}
360-
361345
/// \brief If the passed expression in a non-null pointer expression, then
362346
/// the dereference expression is returned. Otherwise the original expression
363347
/// is returned.
@@ -1143,7 +1127,7 @@ numbered_lvalue_to_taint_mapt taint_algorithm_computing_summary_of_functiont::
11431127
if(callee_expr.id()==ID_symbol)
11441128
{
11451129
irep_idt callee_id = to_symbol_expr(callee_expr).get_identifier();
1146-
const std::string callee_ident = as_string(callee_id);
1130+
const std::string &callee_ident = as_string(callee_id);
11471131
const code_typet &fn_type =
11481132
program->get_functions().function_map.at(callee_id).type;
11491133
if(database.contains(callee_id))
@@ -1234,10 +1218,8 @@ numbered_lvalue_to_taint_mapt taint_algorithm_computing_summary_of_functiont::
12341218
&result_location))
12351219
{
12361220
// Update of return_value of the callee.
1237-
result_lvalue = find_or_create_symbol_expr(
1238-
program->get_namespace(),
1239-
callee_ident + RETURN_VALUE_SUFFIX,
1240-
fn_type.return_type());
1221+
result_lvalue = program->get_namespace()
1222+
.lookup(callee_ident + RETURN_VALUE_SUFFIX).symbol_expr();
12411223
}
12421224
else if(
12431225
const taintable_location_argumentt *result_argument =
@@ -1300,10 +1282,8 @@ numbered_lvalue_to_taint_mapt taint_algorithm_computing_summary_of_functiont::
13001282
&sanitized_location))
13011283
{
13021284
// Update of return_value of the callee.
1303-
result_lvalue = find_or_create_symbol_expr(
1304-
program->get_namespace(),
1305-
callee_ident + RETURN_VALUE_SUFFIX,
1306-
fn_type.return_type());
1285+
result_lvalue = program->get_namespace()
1286+
.lookup(callee_ident + RETURN_VALUE_SUFFIX).symbol_expr();
13071287
}
13081288
else if(
13091289
const taintable_location_argumentt *sanitized_argument =

0 commit comments

Comments
 (0)