Skip to content

Commit 3feb57d

Browse files
committed
Unwindset parsing: support labels as loop identifiers
Labels can enable a more stable loop identification when code bases are subject to change.
1 parent f170ba1 commit 3feb57d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

regression/cbmc/unwindset1/label.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--unwindset main.for_loop:2,main.1:6
4+
^VERIFICATION FAILED$
5+
^EXIT=10$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/goto-instrument/unwindset.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void unwindsett::parse_unwindset_one_loop(std::string val)
4949
// The loop id can take three forms:
5050
// 1) Just a function name to limit recursion.
5151
// 2) F.N where F is a function name and N is a loop number.
52+
// 3) F.L where F is a function name and L is a label.
5253
const symbol_tablet &symbol_table = goto_model.get_symbol_table();
5354
const symbolt *maybe_fn = symbol_table.lookup(id);
5455
if(maybe_fn && maybe_fn->type.id() == ID_code)
@@ -99,8 +100,33 @@ void unwindsett::parse_unwindset_one_loop(std::string val)
99100
}
100101
else
101102
{
102-
throw invalid_command_line_argument_exceptiont{
103-
"invalid loop identifier " + id, "unwindset"};
103+
optionalt<unsigned> nr;
104+
optionalt<source_locationt> location;
105+
for(const auto &instruction : goto_function.body.instructions)
106+
{
107+
if(
108+
std::find(
109+
instruction.labels.begin(),
110+
instruction.labels.end(),
111+
loop_nr_label) != instruction.labels.end())
112+
{
113+
location = instruction.source_location();
114+
}
115+
if(
116+
location.has_value() && instruction.is_backwards_goto() &&
117+
instruction.source_location() == *location)
118+
{
119+
nr = instruction.loop_number;
120+
break;
121+
}
122+
}
123+
if(!nr.has_value())
124+
{
125+
throw invalid_command_line_argument_exceptiont{
126+
"loop identifier " + id + " does not match any loop", "unwindset"};
127+
}
128+
else
129+
id = function_id + "." + std::to_string(*nr);
104130
}
105131
}
106132

0 commit comments

Comments
 (0)