Skip to content

Commit 726bf13

Browse files
authored
Merge pull request #5845 from tautschnig/keep-redundant-checks
goto_checkt: keep same-assertion for different expressions
2 parents 4bbd1c9 + 93bd022 commit 726bf13

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

regression/cbmc/Pointer_byte_extract5/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ main.i
44
^EXIT=10$
55
^SIGNAL=0$
66
array\.List dynamic object upper bound in p->List\[2\]: FAILURE
7-
\*\* 1 of 14 failed
7+
\*\* 1 of \d+ failed
88
--
99
^warning: ignoring
1010
--

regression/cbmc/Undefined_Shift1/test.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ main.c
44
^EXIT=10$
55
^SIGNAL=0$
66
^\[.*\] line 4 shift operand is negative in .*: SUCCESS$
7+
^\[.*\] line 5 shift operand is negative in .*: SUCCESS$
78
^\[.*\] line 7 shift distance too large in .*: FAILURE$
89
^\[.*\] line 15 shift distance is negative in .*: FAILURE$
910
^\[.*\] line 15 shift distance too large in .*: SUCCESS$
1011
^\[.*\] line 20 shift operand is negative in .*: FAILURE$
11-
^\*\* 3 of 5 failed
12+
^\*\* 3 of 6 failed
1213
^VERIFICATION FAILED$
1314
--
1415
^warning: ignoring

regression/cbmc/bounds_check2/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int main()
2+
{
3+
int A[2];
4+
int x = A[1];
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--bounds-check --retain-trivial-checks
4+
^Generated \d+ VCC\(s\), 0 remaining after simplification$
5+
^\[main.array_bounds.1\] line 4 array 'A' lower bound in A\[\(signed (long (long )?)?int\)1\]: SUCCESS$
6+
^VERIFICATION SUCCESSFUL$
7+
^EXIT=0$
8+
^SIGNAL=0$
9+
--
10+
^warning: ignoring
11+
^Generated 0 VCC\(s\), 0 remaining after simplification$
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE broken-smt-backend
2+
main.c
3+
--pointer-overflow-check --no-simplify
4+
^\[main.pointer_arithmetic.\d+\] line 6 pointer arithmetic: pointer outside dynamic object bounds in p \+ \(signed (long (long )?)?int\)10: FAILURE
5+
^\[main.pointer_arithmetic.\d+\] line 7 pointer arithmetic: pointer outside dynamic object bounds in p - \(signed (long (long )?)?int\)10: FAILURE
6+
^\[main.pointer_arithmetic.\d+\] line 10 pointer arithmetic: pointer outside object bounds in arr \+ \(signed (long (long )?)?int\)10: FAILURE
7+
^\[main.pointer_arithmetic.\d+\] line 11 pointer arithmetic: pointer outside object bounds in arr - \(signed (long (long )?)?int\)10: FAILURE
8+
^\*\* 4 of \d+ failed
9+
^VERIFICATION FAILED$
10+
^EXIT=10$
11+
^SIGNAL=0$
12+
--
13+
^warning: ignoring
14+
Invariant check failed
15+
--
16+
Uses --no-simplify to avoid removing repeated ASSERT FALSE statements.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
CORE broken-smt-backend
1+
CORE
22
main.c
3-
--pointer-overflow-check --no-simplify
3+
--pointer-overflow-check
44
^\[main.pointer_arithmetic.\d+\] line 6 pointer arithmetic: pointer outside dynamic object bounds in p \+ \(signed (long (long )?)?int\)10: FAILURE
55
^\[main.pointer_arithmetic.\d+\] line 7 pointer arithmetic: pointer outside dynamic object bounds in p - \(signed (long (long )?)?int\)10: FAILURE
66
^\[main.pointer_arithmetic.\d+\] line 10 pointer arithmetic: pointer outside object bounds in arr \+ \(signed (long (long )?)?int\)10: FAILURE
@@ -12,5 +12,3 @@ main.c
1212
--
1313
^warning: ignoring
1414
Invariant check failed
15-
--
16-
Uses --no-simplify to avoid removing repeated ASSERT FALSE statements.

src/analyses/goto_check.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class goto_checkt
7070
_options.get_bool_option("float-overflow-check");
7171
enable_simplify=_options.get_bool_option("simplify");
7272
enable_nan_check=_options.get_bool_option("nan-check");
73-
retain_trivial=_options.get_bool_option("retain-trivial");
73+
retain_trivial = _options.get_bool_option("retain-trivial-checks");
7474
enable_assert_to_assume=_options.get_bool_option("assert-to-assume");
7575
enable_assertions=_options.get_bool_option("assertions");
7676
enable_built_in_assertions=_options.get_bool_option("built-in-assertions");
@@ -242,7 +242,7 @@ class goto_checkt
242242
const guardt &guard);
243243

244244
goto_programt new_code;
245-
typedef std::set<exprt> assertionst;
245+
typedef std::set<std::pair<exprt, exprt>> assertionst;
246246
assertionst assertions;
247247

248248
/// Remove all assertions containing the symbol in \p lhs as well as all
@@ -333,8 +333,12 @@ void goto_checkt::invalidate(const exprt &lhs)
333333

334334
for(auto it = assertions.begin(); it != assertions.end();)
335335
{
336-
if(has_symbol(*it, find_symbols_set) || has_subexpr(*it, ID_dereference))
336+
if(
337+
has_symbol(it->second, find_symbols_set) ||
338+
has_subexpr(it->second, ID_dereference))
339+
{
337340
it = assertions.erase(it);
341+
}
338342
else
339343
++it;
340344
}
@@ -1545,7 +1549,7 @@ void goto_checkt::add_guarded_property(
15451549
? std::move(simplified_expr)
15461550
: implies_exprt{guard.as_expr(), std::move(simplified_expr)};
15471551

1548-
if(assertions.insert(guarded_expr).second)
1552+
if(assertions.insert(std::make_pair(src_expr, guarded_expr)).second)
15491553
{
15501554
auto t = new_code.add(
15511555
enable_assert_to_assume ? goto_programt::make_assumption(

src/analyses/goto_check.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void goto_check(
3939
"overflow-check)" \
4040
"(pointer-overflow-check)(conversion-check)(undefined-shift-check)" \
4141
"(float-overflow-check)(nan-check)(no-built-in-assertions)" \
42-
"(pointer-primitive-check)"
42+
"(pointer-primitive-check)" \
43+
"(retain-trivial-checks)"
4344

4445
// clang-format off
4546
#define HELP_GOTO_CHECK \
@@ -54,9 +55,10 @@ void goto_check(
5455
" --undefined-shift-check check shift greater than bit-width\n" \
5556
" --float-overflow-check check floating-point for +/-Inf\n" \
5657
" --nan-check check floating-point for NaN\n" \
57-
" --no-built-in-assertions ignore assertions in built-in library\n" \
5858
" --enum-range-check checks that all enum type expressions have values in the enum range\n" /* NOLINT(whitespace/line_length) */ \
59-
" --pointer-primitive-check checks that all pointers in pointer primitives are valid or null\n" /* NOLINT(whitespace/line_length) */
59+
" --pointer-primitive-check checks that all pointers in pointer primitives are valid or null\n" /* NOLINT(whitespace/line_length) */ \
60+
" --no-built-in-assertions ignore assertions in built-in library\n" \
61+
" --retain-trivial-checks include checks that are trivially true\n" \
6062

6163
#define PARSE_OPTIONS_GOTO_CHECK(cmdline, options) \
6264
options.set_option("bounds-check", cmdline.isset("bounds-check")); \
@@ -72,7 +74,10 @@ void goto_check(
7274
options.set_option("float-overflow-check", cmdline.isset("float-overflow-check")); /* NOLINT(whitespace/line_length) */ \
7375
options.set_option("nan-check", cmdline.isset("nan-check")); \
7476
options.set_option("built-in-assertions", !cmdline.isset("no-built-in-assertions")); /* NOLINT(whitespace/line_length) */ \
75-
options.set_option("pointer-primitive-check", cmdline.isset("pointer-primitive-check")) /* NOLINT(whitespace/line_length) */
77+
options.set_option("pointer-primitive-check", cmdline.isset("pointer-primitive-check")); /* NOLINT(whitespace/line_length) */ \
78+
options.set_option("retain-trivial-checks", \
79+
cmdline.isset("retain-trivial-checks")); \
80+
(void)0
7681
// clang-format on
7782

7883
#endif // CPROVER_ANALYSES_GOTO_CHECK_H

0 commit comments

Comments
 (0)