Skip to content

Commit dbad224

Browse files
Petr BauchPetr Bauch
authored andcommitted
Fix based on reviews
1 parent 0ce472c commit dbad224

11 files changed

+76
-15
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Author: Daniel Kroening, [email protected]
4646
#include <langapi/mode.h>
4747

4848
#include <util/config.h>
49+
#include <util/exception_utils.h>
4950
#include <util/exit_codes.h>
5051
#include <util/options.h>
5152
#include <util/unicode.h>
@@ -637,6 +638,12 @@ bool janalyzer_parse_optionst::set_properties()
637638
::set_properties(goto_model, cmdline.get_values("property"));
638639
}
639640

641+
catch(const incorrect_goto_program_exceptiont &e)
642+
{
643+
std::cerr << e.what() << "\n";
644+
return true;
645+
}
646+
640647
catch(const char *e)
641648
{
642649
error() << e << eom;

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <memory>
1818

1919
#include <util/config.h>
20+
#include <util/exception_utils.h>
2021
#include <util/exit_codes.h>
2122
#include <util/invariant.h>
2223
#include <util/unicode.h>
@@ -574,6 +575,12 @@ bool jbmc_parse_optionst::set_properties(goto_modelt &goto_model)
574575
::set_properties(goto_model, cmdline.get_values("property"));
575576
}
576577

578+
catch(const incorrect_goto_program_exceptiont &e)
579+
{
580+
std::cerr << e.what() << "\n";
581+
return true;
582+
}
583+
577584
catch(const char *e)
578585
{
579586
error() << e << eom;

src/cbmc/cbmc_parse_options.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <memory>
1818

1919
#include <util/config.h>
20+
#include <util/exception_utils.h>
2021
#include <util/exit_codes.h>
2122
#include <util/invariant.h>
2223
#include <util/unicode.h>
@@ -541,6 +542,12 @@ bool cbmc_parse_optionst::set_properties()
541542
::set_properties(goto_model, cmdline.get_values("property"));
542543
}
543544

545+
catch(const incorrect_goto_program_exceptiont &e)
546+
{
547+
std::cerr << e.what() << "\n";
548+
return true;
549+
}
550+
544551
catch(const char *e)
545552
{
546553
error() << e << eom;

src/goto-analyzer/goto_analyzer_parse_options.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Author: Daniel Kroening, [email protected]
5151
#include <langapi/language.h>
5252

5353
#include <util/config.h>
54+
#include <util/exception_utils.h>
5455
#include <util/exit_codes.h>
5556
#include <util/options.h>
5657
#include <util/unicode.h>
@@ -691,6 +692,12 @@ bool goto_analyzer_parse_optionst::set_properties()
691692
::set_properties(goto_model, cmdline.get_values("property"));
692693
}
693694

695+
catch(const incorrect_goto_program_exceptiont &e)
696+
{
697+
std::cerr << e.what() << "\n";
698+
return true;
699+
}
700+
694701
catch(const char *e)
695702
{
696703
error() << e << eom;

src/goto-programs/slice_global_inits.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Date: December 2016
2121
#include <util/cprover_prefix.h>
2222
#include <util/prefix.h>
2323

24+
#include <util/exception_utils.h>
2425
#include <util/invariant.h>
2526

2627
#include <goto-programs/goto_functions.h>
@@ -34,8 +35,8 @@ void slice_global_inits(goto_modelt &goto_model)
3435
const irep_idt entry_point=goto_functionst::entry_point();
3536
goto_functionst &goto_functions=goto_model.goto_functions;
3637

37-
INVARIANT(
38-
goto_functions.function_map.count(entry_point), "entry point not found");
38+
if(goto_functions.function_map.count(entry_point) == 0)
39+
throw incorrect_goto_program_exceptiont("entry point not found");
3940

4041
// Get the call graph restricted to functions reachable from
4142
// the entry point:
@@ -75,8 +76,8 @@ void slice_global_inits(goto_modelt &goto_model)
7576

7677
goto_functionst::function_mapt::iterator f_it;
7778
f_it=goto_functions.function_map.find(INITIALIZE_FUNCTION);
78-
INVARIANT(
79-
f_it != goto_functions.function_map.end(), "initialize function not found");
79+
if(f_it == goto_functions.function_map.end())
80+
throw incorrect_goto_program_exceptiont("initialize function not found");
8081

8182
goto_programt &goto_program=f_it->second.body;
8283

src/goto-programs/string_instrumentation.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/arith_tools.h>
1717
#include <util/c_types.h>
1818
#include <util/config.h>
19-
#include <util/exception_utils.h>
2019
#include <util/invariant.h>
2120
#include <util/message.h>
2221
#include <util/std_code.h>
@@ -281,7 +280,7 @@ void string_instrumentationt::do_sprintf(
281280

282281
if(arguments.size()<2)
283282
{
284-
throw incorrect_goto_program_exceptiont(
283+
throw incorrect_source_program_exceptiont(
285284
"sprintf expected to have two or more arguments",
286285
target->source_location);
287286
}
@@ -323,7 +322,7 @@ void string_instrumentationt::do_snprintf(
323322

324323
if(arguments.size()<3)
325324
{
326-
throw incorrect_goto_program_exceptiont(
325+
throw incorrect_source_program_exceptiont(
327326
"snprintf expected to have three or more arguments",
328327
target->source_location);
329328
}
@@ -365,7 +364,7 @@ void string_instrumentationt::do_fscanf(
365364

366365
if(arguments.size()<2)
367366
{
368-
throw incorrect_goto_program_exceptiont(
367+
throw incorrect_source_program_exceptiont(
369368
"fscanf expected to have two or more arguments", target->source_location);
370369
}
371370

@@ -650,7 +649,7 @@ void string_instrumentationt::do_strchr(
650649

651650
if(arguments.size()!=2)
652651
{
653-
throw incorrect_goto_program_exceptiont(
652+
throw incorrect_source_program_exceptiont(
654653
"strchr expected to have two arguments", target->source_location);
655654
}
656655

@@ -676,7 +675,7 @@ void string_instrumentationt::do_strrchr(
676675

677676
if(arguments.size()!=2)
678677
{
679-
throw incorrect_goto_program_exceptiont(
678+
throw incorrect_source_program_exceptiont(
680679
"strrchr expected to have two arguments", target->source_location);
681680
}
682681

@@ -702,7 +701,7 @@ void string_instrumentationt::do_strstr(
702701

703702
if(arguments.size()!=2)
704703
{
705-
throw incorrect_goto_program_exceptiont(
704+
throw incorrect_source_program_exceptiont(
706705
"strstr expected to have two arguments", target->source_location);
707706
}
708707

@@ -735,7 +734,7 @@ void string_instrumentationt::do_strtok(
735734

736735
if(arguments.size()!=2)
737736
{
738-
throw incorrect_goto_program_exceptiont(
737+
throw incorrect_source_program_exceptiont(
739738
"strtok expected to have two arguments", target->source_location);
740739
}
741740

src/goto-programs/string_instrumentation.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,30 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include "goto_functions.h"
1616

17+
#include <util/exception_utils.h>
18+
1719
class message_handlert;
1820
class goto_modelt;
1921

22+
class incorrect_source_program_exceptiont : public cprover_exception_baset
23+
{
24+
public:
25+
incorrect_source_program_exceptiont(
26+
std::string message,
27+
source_locationt source_location)
28+
: message(std::move(message)), source_location(std::move(source_location))
29+
{
30+
}
31+
std::string what() const
32+
{
33+
return message + " (at: " + source_location.as_string() + ")";
34+
}
35+
36+
private:
37+
std::string message;
38+
source_locationt source_location;
39+
};
40+
2041
void string_instrumentation(
2142
symbol_tablet &,
2243
message_handlert &,

src/goto-programs/vcd_goto_trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::string as_vcd_binary(
5454
}
5555
else if(expr.id()==ID_union)
5656
{
57-
return as_vcd_binary(to_union_expr(expr).op0(), ns);
57+
return as_vcd_binary(to_union_expr(expr).op(), ns);
5858
}
5959

6060
// build "xxx"

src/goto-programs/write_goto_binary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ bool write_goto_binary(
153153
const int current_goto_version = 4;
154154
if(version < current_goto_version)
155155
throw invalid_user_input_exceptiont(
156-
"version no longer supported",
156+
"version " + std::to_string(version) + " no longer supported",
157157
"supported version = " + std::to_string(current_goto_version));
158158
else if(version > current_goto_version)
159159
throw invalid_user_input_exceptiont(
160-
"unknown goto binary version",
160+
"unknown goto binary version " + std::to_string(version),
161161
"supported version = " + std::to_string(current_goto_version));
162162
else
163163
return write_goto_binary_v4(

src/util/exception_utils.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ incorrect_goto_program_exceptiont::incorrect_goto_program_exceptiont(
6363
std::string incorrect_goto_program_exceptiont::what() const
6464
{
6565
return message + " (at: " + source_location.as_string() + ")";
66+
if(source_location.is_nil())
67+
return message;
68+
else
69+
return message + " (at: " + source_location.as_string() + ")";
70+
}
71+
72+
incorrect_goto_program_exceptiont::incorrect_goto_program_exceptiont(
73+
std::string message)
74+
: message(std::move(message))
75+
{
76+
source_location.make_nil();
6677
}
6778

6879
unsupported_operation_exceptiont::unsupported_operation_exceptiont(

src/util/exception_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class incorrect_goto_program_exceptiont : public cprover_exception_baset
8686
incorrect_goto_program_exceptiont(
8787
std::string message,
8888
source_locationt source_location);
89+
incorrect_goto_program_exceptiont(std::string message);
8990
std::string what() const override;
9091

9192
private:

0 commit comments

Comments
 (0)