Skip to content

Commit ccec4dd

Browse files
author
Enrico Steffinlongo
authored
Merge pull request #8091 from thomasspriggs/tas/fix_goto_decls
Add support for variables entering scope via a goto
2 parents 8fee19a + 49e8e53 commit ccec4dd

16 files changed

+428
-114
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <assert.h>
2+
3+
extern void __VERIFIER_assume(int cond);
4+
extern int __VERIFIER_nondet_int(void);
5+
6+
int main(void)
7+
{
8+
if(__VERIFIER_nondet_int())
9+
goto switch_2_1;
10+
int tmp_ndt_4 = __VERIFIER_nondet_int();
11+
__VERIFIER_assume(__VERIFIER_nondet_int());
12+
__VERIFIER_assume(tmp_ndt_4 == 1);
13+
switch_2_1:
14+
assert(tmp_ndt_4 > 0);
15+
return 0;
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
issue7997.c
3+
--trace
4+
\[main\.assertion\.1\] line \d+ assertion tmp_ndt_4 \> 0\: FAILURE
5+
return_value___VERIFIER_nondet_int=\-?[1-9]\d*
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
^VERIFICATION FAILED$
9+
--
10+
--
11+
The assertion should be falsifiable when `goto switch_2_1` introduces
12+
`tmp_ndt_4` to the scope without initialising it.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
3+
extern void __VERIFIER_assume(int cond);
4+
5+
int main(void)
6+
{
7+
int l = 2;
8+
int if_condition1;
9+
if(if_condition1)
10+
{
11+
unsigned int j = 42;
12+
l = 3;
13+
goto merge_point;
14+
}
15+
int if_condition2;
16+
if(if_condition2)
17+
{
18+
l = 4;
19+
unsigned int k = 24;
20+
goto merge_point;
21+
}
22+
int i = 3;
23+
int m = 9;
24+
25+
merge_point:
26+
assert(i == 3 || m == 9 || l == 3);
27+
assert(i == 3 || m == 9 || l == 4);
28+
return 0;
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
multiple_goto_single_label.c
3+
4+
\[main\.assertion\.1\] line \d+ assertion i \=\= 3 \|\| m \=\= 9 \|\| l \=\= 3\: FAILURE
5+
\[main\.assertion\.2\] line \d+ assertion i \=\= 3 \|\| m \=\= 9 \|\| l \=\= 4\: FAILURE
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
^VERIFICATION FAILED$
9+
--
10+
--
11+
Test for the case where there are multiple gotos which target the same label
12+
and both introduce variables into the scope.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <assert.h>
2+
3+
extern void __VERIFIER_assume(int cond);
4+
5+
int main(void)
6+
{
7+
int if_condition;
8+
if(if_condition)
9+
{
10+
unsigned int i = 42;
11+
goto j_scope;
12+
i_scope:
13+
assert(i == 42);
14+
return 0;
15+
}
16+
int j = 3;
17+
assert(j == 3);
18+
19+
j_scope:
20+
assert(j == 3);
21+
if(if_condition)
22+
goto i_scope;
23+
return 0;
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
re-enter_scope.c
3+
4+
\[main\.assertion\.1\] line 13 assertion i \=\= 42\: FAILURE
5+
\[main\.assertion\.2\] line 17 assertion j \=\= 3\: SUCCESS
6+
\[main\.assertion\.3\] line 20 assertion j \=\= 3\: FAILURE
7+
^EXIT=10$
8+
^SIGNAL=0$
9+
^VERIFICATION FAILED$
10+
--
11+
--
12+
Test that if execution re-enters a scope via a goto the pre-existing variable
13+
becomes non-det.

regression/cbmc/destructors/compound_literal.desc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ CORE
22
main.c
33
--unwind 10 --show-goto-functions --no-standard-checks
44
activate-multi-line-match
5-
(?P<comment_block>\/\/ [0-9]+ file main\.c line [0-9]+ function main)[\s]*DEAD .*newAlloc0[\s]*(?P>comment_block)[\s]*DEAD .*pc[\s]*(?P>comment_block)[\s]*DEAD .*literal[\s]*(?P>comment_block)[\s]*8: END_FUNCTION
5+
(?P<comment_block>\/\/ [0-9]+ file main\.c line [0-9]+ function main)[\s]*DEAD .*newAlloc0[\s]*(?P>comment_block)[\s]*DEAD .*pc[\s]*(?P>comment_block)[\s]*DEAD .*literal[\s]*(?P>comment_block)[\s]*9: END_FUNCTION
66
^EXIT=0$
77
^SIGNAL=0$
88
--
99
--
1010
Checks for:
1111

12-
// 49 file main.c line 44 function main
13-
DEAD main::1::newAlloc0
14-
// 50 file main.c line 44 function main
15-
DEAD main::1::pc
16-
// 51 file main.c line 44 function main
17-
DEAD main::$tmp::literal
18-
// 52 file main.c line 45 function main
19-
8: END_FUNCTION
12+
// 57 file main.c line 44 function main
13+
DEAD main::1::newAlloc0
14+
// 58 file main.c line 44 function main
15+
DEAD main::1::pc
16+
// 59 file main.c line 44 function main
17+
DEAD main::$tmp::literal
18+
// 60 file main.c line 45 function main
19+
9: END_FUNCTION
2020

2121
This asserts that when you've created a compound literal that both temp and real
2222
variable gets killed.

regression/cbmc/destructors/enter_lexical_block.desc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@ CORE
22
main.c
33
--unwind 10 --show-goto-functions
44
activate-multi-line-match
5-
(?P<comment_block>\/\/ [0-9]+ file main\.c line [0-9]+ function main)[\s]*5: .*newAlloc4 : struct tag-test[\s]*(?P>comment_block)[\s]*.*newAlloc4 := \{ 4 \}[\s]*(?P>comment_block)[\s]*.*newAlloc6 : struct tag-test[\s]*(?P>comment_block)[\s]*.*newAlloc6 := \{ 6 \}[\s]*(?P>comment_block)[\s]*.*newAlloc7 : struct tag-test[\s]*(?P>comment_block)[\s]*.*newAlloc7 := \{ 7 \}[\s]*(?P>comment_block)[\s]*.*DEAD main::1::2::2::newAlloc7[\s]*(?P>comment_block)[\s]*.*DEAD main::1::2::2::newAlloc6[\s]*(?P>comment_block)[\s]*.*DEAD main::1::2::2::newAlloc4[\s]*(?P>comment_block)[\s]*.*GOTO 3
5+
(?P<comment_block>\/\/ [0-9]+ file main\.c line [0-9]+ function main)[\s]*6: .*newAlloc4 : struct tag-test[\s]*(?P>comment_block)[\s]*.*newAlloc4 := \{ 4 \}[\s]*(?P>comment_block)[\s]*.*newAlloc6 : struct tag-test[\s]*(?P>comment_block)[\s]*.*newAlloc6 := \{ 6 \}[\s]*(?P>comment_block)[\s]*.*newAlloc7 : struct tag-test[\s]*(?P>comment_block)[\s]*.*newAlloc7 := \{ 7 \}[\s]*(?P>comment_block)[\s]*.*DEAD main::1::2::2::newAlloc7[\s]*(?P>comment_block)[\s]*.*DEAD main::1::2::2::newAlloc6[\s]*(?P>comment_block)[\s]*.*DEAD main::1::2::2::newAlloc4[\s]*(?P>comment_block)[\s]*.*ASSIGN going_to::nested_if := true[\s]*(?P>comment_block)[\s]*.*GOTO 3
66
^EXIT=0$
77
^SIGNAL=0$
88
--
99
--
1010
Checks for:
1111

12-
// 37 file main.c line 36 function main
13-
5: DECL main::1::2::2::newAlloc4 : struct tag-test
14-
// 38 file main.c line 36 function main
12+
// 41 file main.c line 36 function main
13+
6: DECL main::1::2::2::newAlloc4 : struct tag-test
14+
// 42 file main.c line 36 function main
1515
ASSIGN main::1::2::2::newAlloc4 := { 4 }
16-
// 39 file main.c line 37 function main
16+
// 43 file main.c line 37 function main
1717
DECL main::1::2::2::newAlloc6 : struct tag-test
18-
// 40 file main.c line 37 function main
18+
// 44 file main.c line 37 function main
1919
ASSIGN main::1::2::2::newAlloc6 := { 6 }
20-
// 41 file main.c line 38 function main
20+
// 45 file main.c line 38 function main
2121
DECL main::1::2::2::newAlloc7 : struct tag-test
22-
// 42 file main.c line 38 function main
22+
// 46 file main.c line 38 function main
2323
ASSIGN main::1::2::2::newAlloc7 := { 7 }
24-
// 43 file main.c line 39 function main
24+
// 47 file main.c line 39 function main
2525
DEAD main::1::2::2::newAlloc7
26-
// 44 file main.c line 39 function main
26+
// 48 file main.c line 39 function main
2727
DEAD main::1::2::2::newAlloc6
28-
// 45 file main.c line 39 function main
28+
// 49 file main.c line 39 function main
2929
DEAD main::1::2::2::newAlloc4
30-
// 46 file main.c line 39 function main
30+
// 50 file main.c line 39 function main
31+
ASSIGN going_to::nested_if := true
32+
// 51 file main.c line 39 function main
3133
GOTO 3
3234

3335
This asserts that when the GOTO is going into a lexical block that destructors

regression/cbmc/symex_should_filter_value_sets/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ main::1::c3!0@1#. = 1
99
main::1::c4!0@1#. = 1
1010
main::1::c5!0@1#. = 1
1111
main::1::c6!0@1#. = 1
12-
main::1::c7!0@1#. = 1
13-
main::1::c8!0@1#. = 1
12+
main::1::c7!0@2#. = 1
13+
main::1::c8!0@2#. = 1
1414
main::1::c9!0@1#. = 1
1515
main::1::c10!0@1#. = 1
1616
main::1::c11!0@1#. = 1

src/goto-programs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ SRC = allocate_objects.cpp \
55
class_identifier.cpp \
66
compute_called_functions.cpp \
77
destructor.cpp \
8-
destructor_tree.cpp \
98
elf_reader.cpp \
109
ensure_one_backedge_per_target.cpp \
1110
format_strings.cpp \
@@ -60,6 +59,7 @@ SRC = allocate_objects.cpp \
6059
rewrite_union.cpp \
6160
resolve_inherited_component.cpp \
6261
safety_checker.cpp \
62+
scope_tree.cpp \
6363
set_properties.cpp \
6464
show_goto_functions.cpp \
6565
show_goto_functions_json.cpp \

0 commit comments

Comments
 (0)