Skip to content

Commit 05cc814

Browse files
author
Thomas Kiley
authored
Merge pull request #166 from diffblue/feature/wrap_entry_point_martin_changes
[TYT-5] Address Martin's comments of the Cyclic Dependency Analysis
2 parents 55ce40e + b48b405 commit 05cc814

File tree

21 files changed

+72
-114
lines changed

21 files changed

+72
-114
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
int main(int argc, char **argv)
1+
int g = 0;
2+
3+
int main(void)
24
{
3-
return 0;
5+
assert(g == 0);
6+
g = (g == 0) ? 1 : 0;
47
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
CORE
22
main.c
3-
--show-goto-functions --wrap-entry-point-in-while
4-
^EXIT=0$
3+
--wrap-entry-point-in-while --unwind 100
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^ 1: main\(argc', argv'\);$
7-
^ GOTO 1$
6+
^\[main.assertion.1\] assertion g == 0: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^VERIFICATION SUCCESSFUL$
810
--
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
int skipWhitespace()
1+
int g = 0;
2+
3+
int skipWhitespace(void)
24
{
3-
return 120;
5+
assert(g == 0);
6+
g = (g == 0) ? 1 : 0;
47
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
CORE
22
main.c
3-
--show-goto-functions --wrap-entry-point-in-while --function skipWhitespace
4-
^EXIT=0$
3+
--wrap-entry-point-in-while --unwind 100 --function skipWhitespace
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^ 1: skipWhitespace\(\);$
7-
^ GOTO 1$
6+
^\[skipWhitespace.assertion.1\] assertion g == 0: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^VERIFICATION SUCCESSFUL$
810
--
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
int main(int argc, char **argv)
1+
int g = 0;
2+
3+
int main(void)
24
{
3-
return 0;
5+
assert(g == 0);
6+
g = (g == 0) ? 1 : 0;
47
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
CORE
22
main.c
3-
--show-goto-functions --wrap-entry-point-in-while
3+
--wrap-entry-point-in-while --show-goto-functions
44
^EXIT=6$
55
^SIGNAL=0$
66
^ 1: IF FALSE THEN GOTO 2$
7-
^ main\(argc', argv'\);$
7+
^ main\(\);$
88
^ GOTO 1$
99
--
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
int skipWhitespace()
1+
int g = 0;
2+
3+
int skipWhitespace(void)
24
{
3-
return 120;
5+
assert(g == 0);
6+
g = (g == 0) ? 1 : 0;
47
}

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,25 @@ Author: Daniel Kroening, [email protected]
2222
#include <ansi-c/string_constant.h>
2323

2424
#include <goto-programs/goto_functions.h>
25-
#include <langapi/wrap_entry_point.h>
2625
#include <linking/static_lifetime_init.h>
2726

2827
#include "ansi_c_entry_point.h"
2928
#include "ansi_c_language.h"
3029
#include "c_nondet_symbol_factory.h"
3130

31+
// Build and return a while(true) statement nesting the function call
32+
// passed as a parameter.
33+
code_whilet wrap_entry_point_in_while(code_function_callt &call_main)
34+
{
35+
exprt true_expr;
36+
code_whilet while_expr;
37+
true_expr.make_true();
38+
while_expr.cond()=true_expr;
39+
while_expr.body()=call_main;
40+
41+
return while_expr;
42+
}
43+
3244
exprt::operandst build_function_environment(
3345
const code_typet::parameterst &parameters,
3446
code_blockt &init_code,
@@ -123,8 +135,7 @@ void record_function_outputs(
123135
bool ansi_c_entry_point(
124136
symbol_tablet &symbol_table,
125137
const std::string &standard_main,
126-
message_handlert &message_handler,
127-
bool wrap_entry_point)
138+
message_handlert &message_handler)
128139
{
129140
// check if entry point is already there
130141
if(symbol_table.symbols.find(goto_functionst::entry_point())!=
@@ -447,7 +458,7 @@ bool ansi_c_entry_point(
447458
message_handler);
448459
}
449460

450-
if(wrap_entry_point)
461+
if(config.ansi_c.wrap_entry_point_in_while)
451462
{
452463
code_whilet wrapped_main=wrap_entry_point_in_while(call_main);
453464
init_code.move_to_operands(wrapped_main);

src/ansi-c/ansi_c_entry_point.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Author: Daniel Kroening, [email protected]
1616
bool ansi_c_entry_point(
1717
symbol_tablet &symbol_table,
1818
const std::string &standard_main,
19-
message_handlert &message_handler,
20-
bool wrap_entry_point);
19+
message_handlert &message_handler);
2120

2221
#endif // CPROVER_ANSI_C_ANSI_C_ENTRY_POINT_H

src/ansi-c/ansi_c_language.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ Author: Daniel Kroening, [email protected]
2727
#include "ansi_c_internal_additions.h"
2828
#include "type2name.h"
2929

30-
void ansi_c_languaget::get_language_options(const cmdlinet &cmd)
31-
{
32-
wrap_entry_point=cmd.isset("wrap-entry-point-in-while");
33-
}
34-
3530
std::set<std::string> ansi_c_languaget::extensions() const
3631
{
3732
return { "c", "i" };
@@ -132,8 +127,7 @@ bool ansi_c_languaget::typecheck(
132127

133128
bool ansi_c_languaget::final(symbol_tablet &symbol_table)
134129
{
135-
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(),
136-
wrap_entry_point_in_while()))
130+
if(ansi_c_entry_point(symbol_table, "main", get_message_handler()))
137131
{
138132
return true;
139133
}

src/ansi-c/ansi_c_language.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ Author: Daniel Kroening, [email protected]
2222
class ansi_c_languaget:public languaget
2323
{
2424
public:
25-
virtual void get_language_options(
26-
const cmdlinet &) override;
27-
2825
bool preprocess(
2926
std::istream &instream,
3027
const std::string &path,
@@ -79,12 +76,6 @@ class ansi_c_languaget:public languaget
7976
protected:
8077
ansi_c_parse_treet parse_tree;
8178
std::string parse_path;
82-
83-
bool wrap_entry_point_in_while() const
84-
{ return wrap_entry_point; }
85-
86-
private:
87-
bool wrap_entry_point;
8879
};
8980

9081
languaget *new_ansi_c_language();

src/cbmc/cbmc_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include <util/ui_message.h>
1616
#include <util/parse_options.h>
17+
#include <util/config.h>
1718

1819
#include <langapi/language_ui.h>
19-
#include <langapi/wrap_entry_point.h>
2020

2121
#include <analyses/goto_check.h>
2222

src/cpp/cpp_language.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ Author: Daniel Kroening, [email protected]
2929
#include "cpp_typecheck.h"
3030
#include "cpp_type2name.h"
3131

32-
void cpp_languaget::get_language_options(const cmdlinet &cmd)
33-
{
34-
wrap_entry_point=cmd.isset("wrap-entry-point-in-while");
35-
}
36-
3732
std::set<std::string> cpp_languaget::extensions() const
3833
{
3934
std::set<std::string> s;
@@ -140,8 +135,7 @@ bool cpp_languaget::typecheck(
140135

141136
bool cpp_languaget::final(symbol_tablet &symbol_table)
142137
{
143-
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(),
144-
wrap_entry_point_in_while()))
138+
if(ansi_c_entry_point(symbol_table, "main", get_message_handler()))
145139
{
146140
return true;
147141
}

src/cpp/cpp_language.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ Author: Daniel Kroening, [email protected]
2424
class cpp_languaget:public languaget
2525
{
2626
public:
27-
virtual void get_language_options(
28-
const cmdlinet &cmd) override;
29-
3027
bool preprocess(
3128
std::istream &instream,
3229
const std::string &path,
@@ -88,9 +85,6 @@ class cpp_languaget:public languaget
8885

8986
void modules_provided(std::set<std::string> &modules) override;
9087

91-
bool wrap_entry_point_in_while() const
92-
{ return wrap_entry_point; }
93-
9488
protected:
9589
cpp_parse_treet cpp_parse_tree;
9690
std::string parse_path;
@@ -101,9 +95,6 @@ class cpp_languaget:public languaget
10195
{
10296
return "main";
10397
}
104-
105-
private:
106-
bool wrap_entry_point;
10798
};
10899

109100
languaget *new_cpp_language();

src/goto-analyzer/goto_analyzer_parse_options.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ graphs in DOT format.
106106

107107
#include <util/ui_message.h>
108108
#include <util/parse_options.h>
109+
#include <util/config.h>
109110

110111
#include <langapi/language_ui.h>
111-
#include <langapi/wrap_entry_point.h>
112-
113112
#include <goto-programs/goto_model.h>
114113
#include <goto-programs/show_goto_functions.h>
115114

src/goto-cc/compile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ bool compilet::link()
368368
symbol_table.remove(goto_functionst::entry_point());
369369
compiled_functions.function_map.erase(goto_functionst::entry_point());
370370

371-
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(), false))
371+
if(ansi_c_entry_point(symbol_table, "main", get_message_handler()))
372372
return true;
373373

374374
// entry_point may (should) add some more functions.

src/langapi/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ SRC = language_ui.cpp \
22
language_util.cpp \
33
languages.cpp \
44
mode.cpp \
5-
wrap_entry_point.cpp \
65
# Empty last line
76
INCLUDES= -I ..
87

src/langapi/wrap_entry_point.cpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/langapi/wrap_entry_point.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/util/config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,9 @@ bool configt::set(const cmdlinet &cmdline)
757757
if(cmdline.isset('I'))
758758
ansi_c.include_paths=cmdline.get_values('I');
759759

760+
ansi_c.wrap_entry_point_in_while=
761+
cmdline.isset(WRAP_ENTRY_POINT_IN_WHILE_TRUE_STRING);
762+
760763
if(cmdline.isset("classpath"))
761764
{
762765
// Specifying -classpath or -cp overrides any setting of the

src/util/config.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include <list>
1414

15+
#include <util/std_code.h>
16+
1517
#include "ieee_float.h"
1618
#include "irep.h"
1719

@@ -44,6 +46,7 @@ class configt
4446
bool use_fixed_for_float;
4547
bool for_has_scope;
4648
bool single_precision_constant;
49+
bool wrap_entry_point_in_while;
4750
enum class c_standardt { C89, C99, C11 } c_standard;
4851
static c_standardt default_c_standard();
4952

@@ -160,4 +163,15 @@ class configt
160163

161164
extern configt config;
162165

166+
/// Command line option (to be shared by the different tools)
167+
/// (This contains the actual string, needed in config.cpp)
168+
#define WRAP_ENTRY_POINT_IN_WHILE_TRUE_STRING "wrap-entry-point-in-while"
169+
170+
/// Command line option (to be shared by the different tools)
171+
#define WRAP_ENTRY_POINT_IN_WHILE_TRUE "(" WRAP_ENTRY_POINT_IN_WHILE_TRUE_STRING ")"
172+
173+
/// Command line help text
174+
#define HELP_WRAP_ENTRY_POINT_IN_WHILE_TRUE \
175+
" --wrap-entry-point-in-while wrap the designated entry point function in a while(true) statement\n" // NOLINT(*)
176+
163177
#endif // CPROVER_UTIL_CONFIG_H

0 commit comments

Comments
 (0)