Skip to content

Commit 01eb3a8

Browse files
committed
Remove {r,w,rw}_ok and pointer_in_range expansion from C front-end
These expressions are now handled by the back-ends. Unconditional rewrites by goto_check_ct (even when no checks are enabled) are no longer necessary. Fixes: diffblue#7377
1 parent 20b7cef commit 01eb3a8

File tree

3 files changed

+2
-61
lines changed

3 files changed

+2
-61
lines changed

regression/cbmc/realloc-should-not-free-on-failure-to-allocate/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE new-smt-backend
22
test.c
33
--malloc-may-fail --malloc-fail-null
4-
^\[main.precondition_instance.\d+] line \d+ double free: SUCCESS$
4+
^\[free.precondition.\d+] line \d+ double free: SUCCESS$
55
^VERIFICATION SUCCESSFUL$
66
^EXIT=0$
77
^SIGNAL=0$

regression/goto-cc-goto-analyzer/instrument_preconditions_locations/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test.c
44
^EXIT=0$
55
^SIGNAL=0$
66
Checking assertions
7-
^\[EVP_MD_CTX_free.precondition_instance.1\] line \d+ free argument must be NULL or valid pointer: SUCCESS
7+
^\[free.precondition.1\] line \d+ free argument must be NULL or valid pointer: SUCCESS
88
--
99
Invariant check failed
1010
--

src/ansi-c/goto_check_c.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ class goto_check_ct
228228
void conversion_check(const exprt &, const guardt &);
229229
void float_overflow_check(const exprt &, const guardt &);
230230
void nan_check(const exprt &, const guardt &);
231-
optionalt<exprt> expand_pointer_checks(exprt);
232231

233232
std::string array_name(const exprt &);
234233

@@ -1992,62 +1991,6 @@ void goto_check_ct::check(const exprt &expr)
19921991
check_rec(expr, identity);
19931992
}
19941993

1995-
/// expand the r_ok, w_ok, rw_ok, pointer_in_range predicates
1996-
optionalt<exprt> goto_check_ct::expand_pointer_checks(exprt expr)
1997-
{
1998-
bool modified = false;
1999-
2000-
for(auto &op : expr.operands())
2001-
{
2002-
auto op_result = expand_pointer_checks(op);
2003-
if(op_result.has_value())
2004-
{
2005-
op = *op_result;
2006-
modified = true;
2007-
}
2008-
}
2009-
2010-
if(expr.id() == ID_r_ok || expr.id() == ID_w_ok || expr.id() == ID_rw_ok)
2011-
{
2012-
// these get an address as first argument and a size as second
2013-
DATA_INVARIANT(
2014-
expr.operands().size() == 4, "r/w_ok must have four operands");
2015-
2016-
const auto conditions = get_pointer_dereferenceable_conditions(
2017-
to_r_or_w_ok_expr(expr).pointer(), to_r_or_w_ok_expr(expr).size());
2018-
2019-
exprt::operandst conjuncts;
2020-
2021-
for(const auto &c : conditions)
2022-
conjuncts.push_back(c.assertion);
2023-
2024-
exprt c = conjunction(conjuncts);
2025-
if(enable_simplify)
2026-
simplify(c, ns);
2027-
return c;
2028-
}
2029-
else if(expr.id() == ID_pointer_in_range)
2030-
{
2031-
const auto &pointer_in_range_expr = to_pointer_in_range_expr(expr);
2032-
2033-
auto expanded = pointer_in_range_expr.lower(ns);
2034-
2035-
// rec. call
2036-
auto expanded_rec_opt = expand_pointer_checks(expanded);
2037-
if(expanded_rec_opt.has_value())
2038-
expanded = *expanded_rec_opt;
2039-
2040-
if(enable_simplify)
2041-
simplify(expanded, ns);
2042-
2043-
return expanded;
2044-
}
2045-
else if(modified)
2046-
return std::move(expr);
2047-
else
2048-
return {};
2049-
}
2050-
20511994
void goto_check_ct::memory_leak_check(const irep_idt &function_id)
20521995
{
20531996
const symbolt &leak = ns.lookup(CPROVER_PREFIX "memory_leak");
@@ -2267,8 +2210,6 @@ void goto_check_ct::goto_check(
22672210
}
22682211
}
22692212

2270-
i.transform([this](exprt expr) { return expand_pointer_checks(expr); });
2271-
22722213
for(auto &instruction : new_code.instructions)
22732214
{
22742215
if(instruction.source_location().is_nil())

0 commit comments

Comments
 (0)