Skip to content

C front-end: cleanup label statement type checking #3277

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

Merged
merged 1 commit into from
Nov 6, 2018
Merged
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
13 changes: 13 additions & 0 deletions regression/cbmc/nested_label1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <assert.h>

int main()
{
goto label2;
goto out;
label1:
label2:
label3:
assert(0);
out:
return 0;
}
12 changes: 12 additions & 0 deletions regression/cbmc/nested_label1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c

^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
--
This test checks that the assertion is reachable despite being wrapped in a
nested list of labels, and that jumping to a label in the middle of that list is
handled correctly.
1 change: 1 addition & 0 deletions scripts/delete_failing_smt2_solver_tests
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ rm memory_allocation1/test.desc
rm memset1/test.desc
rm memset3/test.desc
rm mm_io1/test.desc
rm nested_label1/test.desc
rm no_nondet_static/test.desc
rm null1/test.desc
rm null2/test.desc
Expand Down
22 changes: 2 additions & 20 deletions src/ansi-c/c_typecheck_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,8 @@ void c_typecheck_baset::typecheck_block(code_blockt &code)

for(auto &code_op : code.statements())
{
if(code_op.is_nil())
continue;

if(code_op.get_statement()==ID_label)
{
// these may be nested
codet *code_ptr=&code_op;

while(code_ptr->get_statement()==ID_label)
{
assert(code_ptr->operands().size()==1);
code_ptr=&to_code(code_ptr->op0());
}

// codet &label_op=*code_ptr;

new_ops.move(code_op);
}
else
new_ops.move(code_op);
if(code_op.is_not_nil())
new_ops.add(std::move(code_op));
Copy link
Contributor

Choose a reason for hiding this comment

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

It is nice the code is a lot simpler - but we now don't check the operands size - is this a problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Type checking of labels is done elsewhere, I'd say this should be done over there.

}

code.statements().swap(new_ops.statements());
Expand Down