Skip to content

Commit 41f65a0

Browse files
authored
Merge pull request #6520 from tautschnig/unwindset-warnings
unwindset: Warn about non-existent loops
2 parents e3719e3 + f14cd09 commit 41f65a0

File tree

5 files changed

+46
-19
lines changed

5 files changed

+46
-19
lines changed

regression/cbmc/unwindset1/test.desc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
CORE
22
main.c
33
--unwindset main.0:2,main.2:2
4-
^Invalid User Input$
5-
^Option: unwindset$
6-
^Reason: invalid loop identifier main\.2$
7-
^EXIT=1$
4+
^loop identifier main.2 provided with unwindset does not match any loop$
5+
^VERIFICATION FAILED$
6+
^EXIT=10$
87
^SIGNAL=0$
98
--
109
^warning: ignoring

src/goto-checker/bmc_util.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ void setup_symex(
192192
symex.last_source_location.make_nil();
193193

194194
symex.unwindset.parse_unwind(options.get_option("unwind"));
195-
symex.unwindset.parse_unwindset(options.get_list_option("unwindset"));
195+
symex.unwindset.parse_unwindset(
196+
options.get_list_option("unwindset"), ui_message_handler);
196197
}
197198

198199
void slice(

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,16 @@ int goto_instrument_parse_optionst::doit()
171171
unwindset.parse_unwind(cmdline.get_value("unwind"));
172172

173173
if(unwindset_file_given)
174-
unwindset.parse_unwindset_file(cmdline.get_value("unwindset-file"));
174+
{
175+
unwindset.parse_unwindset_file(
176+
cmdline.get_value("unwindset-file"), ui_message_handler);
177+
}
175178

176179
if(unwindset_given)
177-
unwindset.parse_unwindset(cmdline.get_values("unwindset"));
180+
{
181+
unwindset.parse_unwindset(
182+
cmdline.get_values("unwindset"), ui_message_handler);
183+
}
178184

179185
bool unwinding_assertions=cmdline.isset("unwinding-assertions");
180186
bool partial_loops=cmdline.isset("partial-loops");

src/goto-instrument/unwindset.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#include "unwindset.h"
1010

1111
#include <util/exception_utils.h>
12+
#include <util/message.h>
1213
#include <util/string2int.h>
1314
#include <util/string_utils.h>
1415

@@ -24,7 +25,9 @@ void unwindsett::parse_unwind(const std::string &unwind)
2425
global_limit = unsafe_string2unsigned(unwind);
2526
}
2627

27-
void unwindsett::parse_unwindset_one_loop(std::string val)
28+
void unwindsett::parse_unwindset_one_loop(
29+
std::string val,
30+
message_handlert &message_handler)
2831
{
2932
if(val.empty())
3033
return;
@@ -94,8 +97,11 @@ void unwindsett::parse_unwindset_one_loop(std::string val)
9497
});
9598
if(!found)
9699
{
97-
throw invalid_command_line_argument_exceptiont{
98-
"invalid loop identifier " + id, "unwindset"};
100+
messaget log{message_handler};
101+
log.warning() << "loop identifier " << id
102+
<< " provided with unwindset does not match any loop"
103+
<< messaget::eom;
104+
return;
99105
}
100106
}
101107
else
@@ -122,8 +128,11 @@ void unwindsett::parse_unwindset_one_loop(std::string val)
122128
}
123129
if(!nr.has_value())
124130
{
125-
throw invalid_command_line_argument_exceptiont{
126-
"loop identifier " + id + " does not match any loop", "unwindset"};
131+
messaget log{message_handler};
132+
log.warning() << "loop identifier " << id
133+
<< " provided with unwindset does not match any loop"
134+
<< messaget::eom;
135+
return;
127136
}
128137
else
129138
id = function_id + "." + std::to_string(*nr);
@@ -147,15 +156,17 @@ void unwindsett::parse_unwindset_one_loop(std::string val)
147156
}
148157
}
149158

150-
void unwindsett::parse_unwindset(const std::list<std::string> &unwindset)
159+
void unwindsett::parse_unwindset(
160+
const std::list<std::string> &unwindset,
161+
message_handlert &message_handler)
151162
{
152163
for(auto &element : unwindset)
153164
{
154165
std::vector<std::string> unwindset_elements =
155166
split_string(element, ',', true, true);
156167

157168
for(auto &element : unwindset_elements)
158-
parse_unwindset_one_loop(element);
169+
parse_unwindset_one_loop(element, message_handler);
159170
}
160171
}
161172

@@ -181,7 +192,9 @@ unwindsett::get_limit(const irep_idt &loop_id, unsigned thread_nr) const
181192
return global_limit;
182193
}
183194

184-
void unwindsett::parse_unwindset_file(const std::string &file_name)
195+
void unwindsett::parse_unwindset_file(
196+
const std::string &file_name,
197+
message_handlert &message_handler)
185198
{
186199
#ifdef _MSC_VER
187200
std::ifstream file(widen(file_name));
@@ -199,5 +212,5 @@ void unwindsett::parse_unwindset_file(const std::string &file_name)
199212
split_string(buffer.str(), ',', true, true);
200213

201214
for(auto &element : unwindset_elements)
202-
parse_unwindset_one_loop(element);
215+
parse_unwindset_one_loop(element, message_handler);
203216
}

src/goto-instrument/unwindset.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected]
1818
#include <map>
1919
#include <string>
2020

21+
class message_handlert;
22+
2123
class unwindsett
2224
{
2325
public:
@@ -34,13 +36,17 @@ class unwindsett
3436
void parse_unwind(const std::string &unwind);
3537

3638
// limit for instances of a loop
37-
void parse_unwindset(const std::list<std::string> &unwindset);
39+
void parse_unwindset(
40+
const std::list<std::string> &unwindset,
41+
message_handlert &message_handler);
3842

3943
// queries
4044
optionalt<unsigned> get_limit(const irep_idt &loop, unsigned thread_id) const;
4145

4246
// read unwindset directives from a file
43-
void parse_unwindset_file(const std::string &file_name);
47+
void parse_unwindset_file(
48+
const std::string &file_name,
49+
message_handlert &message_handler);
4450

4551
protected:
4652
abstract_goto_modelt &goto_model;
@@ -57,7 +63,9 @@ class unwindsett
5763
std::map<std::pair<irep_idt, unsigned>, optionalt<unsigned>>;
5864
thread_loop_mapt thread_loop_map;
5965

60-
void parse_unwindset_one_loop(std::string loop_limit);
66+
void parse_unwindset_one_loop(
67+
std::string loop_limit,
68+
message_handlert &message_handler);
6169
};
6270

6371
#define OPT_UNWINDSET \

0 commit comments

Comments
 (0)