Skip to content

[SV-COMP'18 7/19] Ensure that local declarations do not introduce spurious dead warnings #1996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions regression/cbmc/Local_out_of_scope4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
int main()
{
int *p = 0;

for(int i = 0; i < 3; ++i)
{
{
int x = 42;
p = &x;
*p = 1;
}
}

return 0;
}
8 changes: 8 additions & 0 deletions regression/cbmc/Local_out_of_scope4/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an extra no-match line for the particular warning you were seeing?

28 changes: 28 additions & 0 deletions src/analyses/goto_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,34 @@ void goto_checkt::goto_check(
}
}
}
else if(i.is_decl())
{
if(enable_pointer_check)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unfamiliar with this code so non-blocking (I don't understand why dead statements need this instrumentation), but some documentation of why a deceleration statement needs to be instrumented when enable_pointer_check is on would be appreciated

{
assert(i.code.operands().size()==1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INVARIANT here?

const symbol_exprt &variable=to_symbol_expr(i.code.op0());

// is it dirty?
if(local_bitvector_analysis->dirty(variable))
{
// reset the dead marker
goto_programt::targett t=new_code.add_instruction(ASSIGN);
exprt address_of_expr=address_of_exprt(variable);
exprt lhs=ns.lookup(CPROVER_PREFIX "dead_object").symbol_expr();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "dead_object" is a magic string, is it already defined somewhere else? (A quick search of the code says no - it'd be nice to pull it out rather than introduce another duplication of it)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignorant of this code, is this somehow the point where the variable that's declared goes out of scope? If you do pull out the "dead_object" string, it'd be great to document there what this variable is.

if(!base_type_eq(lhs.type(), address_of_expr.type(), ns))
address_of_expr.make_typecast(lhs.type());
exprt rhs=
if_exprt(
equal_exprt(lhs, address_of_expr),
null_pointer_exprt(to_pointer_type(address_of_expr.type())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be clearer to use lhs.type() (since either equal or typecast and therefore equal?)

lhs,
lhs.type());
t->source_location=i.source_location;
t->code=code_assignt(lhs, rhs);
t->code.add_source_location()=i.source_location;
}
}
}
else if(i.is_end_function())
{
if(i.function==goto_functionst::entry_point() &&
Expand Down
7 changes: 2 additions & 5 deletions src/goto-symex/symex_decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)
state.propagation.remove(l1_identifier);

// L2 renaming
// inlining may yield multiple declarations of the same identifier
// within the same L1 context
if(state.level2.current_names.find(l1_identifier)==
state.level2.current_names.end())
state.level2.current_names[l1_identifier]=std::make_pair(ssa, 0);
state.level2.current_names.insert(
std::make_pair(l1_identifier, std::make_pair(ssa, 0)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: might as well emplace, rather than make pair then insert

state.level2.increase_counter(l1_identifier);
const bool record_events=state.record_events;
state.record_events=false;
Expand Down