Skip to content

Commit c7b70da

Browse files
author
Daniel Kroening
committed
fix half-constructed GOTO instruction
1 parent 63acc5b commit c7b70da

File tree

6 files changed

+31
-37
lines changed

6 files changed

+31
-37
lines changed

regression/cbmc/goto5/main.c

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <assert.h>
2+
3+
void main(void)
4+
{
5+
int r = 0;
6+
if ( r == 0 )
7+
{
8+
goto l1;
9+
r = 1;
10+
}
11+
l1:
12+
assert(r != 0); // should fail
13+
}

regression/cbmc/goto5/test.desc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--

src/goto-instrument/accelerate/accelerate.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,12 @@ void acceleratet::insert_looping_path(
212212
++loop_body;
213213

214214
goto_programt::targett jump=program.insert_before(loop_body);
215-
jump->make_goto();
216-
jump->guard=side_effect_expr_nondett(bool_typet());
217-
jump->targets.push_back(loop_body);
215+
jump->make_goto(loop_body, side_effect_expr_nondett(bool_typet()));
218216

219217
program.destructive_insert(loop_body, looping_path);
220218

221219
jump=program.insert_before(loop_body);
222-
jump->make_goto();
223-
jump->guard=true_exprt();
224-
jump->targets.push_back(back_jump);
220+
jump->make_goto(back_jump, true_exprt());
225221

226222
for(goto_programt::targett t=loop_header;
227223
t!=loop_body;

src/goto-instrument/branch.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void branch(
5656
t1->function=f_it->first;
5757

5858
goto_programt::targett t2=body.insert_after(t1);
59-
t2->make_goto();
60-
t2->targets=i_it->targets;
59+
t2->make_goto(i_it->get_target());
6160

6261
goto_programt::targett t3=body.insert_after(t2);
6362
t3->make_function_call(

src/goto-programs/goto_convert.cpp

+7-27
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,7 @@ void goto_convertt::finish_gotos(goto_programt &dest, const irep_idt &mode)
109109
{
110110
goto_programt::instructiont &i=*(g_it.first);
111111

112-
if(i.code.get_statement()=="non-deterministic-goto")
113-
{
114-
const irept &destinations=i.code.find("destinations");
115-
116-
i.make_goto();
117-
118-
forall_irep(it, destinations.get_sub())
119-
{
120-
labelst::const_iterator l_it=
121-
targets.labels.find(it->id_string());
122-
123-
if(l_it==targets.labels.end())
124-
{
125-
error().source_location=i.code.find_source_location();
126-
error() << "goto label `" << it->id() << "' not found" << eom;
127-
throw 0;
128-
}
129-
130-
i.targets.push_back(l_it->second.first);
131-
}
132-
}
133-
else if(i.is_start_thread())
112+
if(i.is_start_thread())
134113
{
135114
const irep_idt &goto_label=i.code.get(ID_destination);
136115

@@ -159,6 +138,7 @@ void goto_convertt::finish_gotos(goto_programt &dest, const irep_idt &mode)
159138
throw 0;
160139
}
161140

141+
i.type=GOTO;
162142
i.targets.clear();
163143
i.targets.push_back(l_it->second.first);
164144

@@ -1480,21 +1460,21 @@ void goto_convertt::convert_goto(
14801460
const codet &code,
14811461
goto_programt &dest)
14821462
{
1483-
goto_programt::targett t=dest.add_instruction();
1484-
t->make_goto();
1463+
// this instruction will turn into a goto during post-processing
1464+
goto_programt::targett t=dest.add_instruction(NO_INSTRUCTION_TYPE);
14851465
t->source_location=code.source_location();
14861466
t->code=code;
14871467

1488-
// remember it to do target later
1468+
// remember it to do the target later
14891469
targets.gotos.push_back(std::make_pair(t, targets.destructor_stack));
14901470
}
14911471

14921472
void goto_convertt::convert_gcc_computed_goto(
14931473
const codet &code,
14941474
goto_programt &dest)
14951475
{
1496-
goto_programt::targett t=dest.add_instruction();
1497-
t->make_skip();
1476+
// this instruction will turn into OTHER during post-processing
1477+
goto_programt::targett t=dest.add_instruction(NO_INSTRUCTION_TYPE);
14981478
t->source_location=code.source_location();
14991479
t->code=code;
15001480

src/goto-programs/goto_program.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ class goto_programt
237237
code.make_nil();
238238
}
239239

240-
void make_goto() { clear(GOTO); }
241240
void make_return() { clear(RETURN); }
242241
void make_skip() { clear(SKIP); }
243242
void make_location(const source_locationt &l)
@@ -256,7 +255,7 @@ class goto_programt
256255

257256
void make_goto(targett _target)
258257
{
259-
make_goto();
258+
clear(GOTO);
260259
targets.push_back(_target);
261260
}
262261

0 commit comments

Comments
 (0)