Skip to content

Commit 56c482c

Browse files
committed
Hide declarations steps from trace when an initialisation follows
If the front-end generated a declaration with an initialiser, then goto conversion can mark the declaration statement (but not the initialisation!) as hidden. This will avoid showing meaningless values in a goto trace.
1 parent de9fa65 commit 56c482c

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

regression/cbmc/trace-values/trace-values.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ struct S
1111
int main()
1212
{
1313
static int static_var;
14-
int local_var;
14+
int local_var = 3;
1515
int *p=&my_nested[0].array[1];
1616
int *q=&my_nested[1].f;
1717
int *null=0;
1818
int *junk;
1919

2020
global_var=1;
2121
static_var=2;
22-
local_var=3;
2322
*p=4;
2423
*q=5;
2524
*null=6;

regression/cbmc/trace-values/trace-values.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ trace-values.c
1616
^VERIFICATION FAILED$
1717
--
1818
^warning: ignoring
19+
^ local_var=[^3]+ .*$
1920
--
2021
Note the assignment to "null" is not included because an assignment direct to
2122
a certainly-null pointer goes to symex::invalid_object, not null$object, and is

src/goto-programs/goto_convert.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,12 @@ void goto_convertt::convert_frontend_decl(
627627
else
628628
{
629629
// this is expected to go away
630-
exprt initializer;
630+
exprt initializer = code.op1();
631631

632632
codet tmp=code;
633-
initializer=code.op1();
634633
tmp.operands().resize(1);
634+
// hide this declaration-without-initializer step in the goto trace
635+
tmp.add_source_location().set_hide();
635636

636637
// Break up into decl and assignment.
637638
// Decl must be visible before initializer.
@@ -642,7 +643,7 @@ void goto_convertt::convert_frontend_decl(
642643
if(initializer.is_not_nil())
643644
{
644645
code_assignt assign(code.op0(), initializer);
645-
assign.add_source_location() = tmp.source_location();
646+
assign.add_source_location() = initializer.source_location();
646647

647648
convert_assign(assign, dest, mode);
648649
}

0 commit comments

Comments
 (0)