Skip to content

Commit 71366aa

Browse files
authored
Merge pull request #165 from diffblue/feature/wrap_entry_point
[TYT-2] Support for wrapping the entry point in an infinite loop in the different tools
2 parents 57af54c + 3dd2079 commit 71366aa

File tree

26 files changed

+194
-7
lines changed

26 files changed

+194
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main(int argc, char **argv)
2+
{
3+
return 0;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --wrap-entry-point-in-while
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ 1: main\(argc', argv'\);$
7+
^ GOTO 1$
8+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int skipWhitespace()
2+
{
3+
return 120;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --wrap-entry-point-in-while --function skipWhitespace
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ 1: skipWhitespace\(\);$
7+
^ GOTO 1$
8+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main(int argc, char **argv)
2+
{
3+
return 0;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --wrap-entry-point-in-while
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^ 1: IF FALSE THEN GOTO 2$
7+
^ main\(argc', argv'\);$
8+
^ GOTO 1$
9+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int skipWhitespace()
2+
{
3+
return 120;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --wrap-entry-point-in-while --function skipWhitespace
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^ 1: IF FALSE THEN GOTO 2$
7+
^ skipWhitespace\(\);$
8+
^ GOTO 1$
9+
--
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main(int argc, char **argv)
2+
{
3+
return 0;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
main.c
3+
--show-goto-functions --wrap-entry-point-in-while
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ 1: main\(argc', argv'\);$
7+
^ GOTO 1$
8+
--
9+
--
10+
This is tracked by the JIRA issue TYT-4: https://diffblue.atlassian.net/projects/TYT/issues/TYT-4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int skipWhitespace()
2+
{
3+
return 120;
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
main.c
3+
--show-goto-functions --wrap-entry-point-in-while --function skipWhitespace
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^ 1: skipWhitespace\(\);$
7+
^ GOTO 1$
8+
--
9+
--
10+
This is tracked by the JIRA issue TYT-4: https://diffblue.atlassian.net/projects/TYT/issues/TYT-4

src/ansi-c/ansi_c_entry_point.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ 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>
2526
#include <linking/static_lifetime_init.h>
2627

2728
#include "ansi_c_entry_point.h"
29+
#include "ansi_c_language.h"
2830
#include "c_nondet_symbol_factory.h"
2931

3032
exprt::operandst build_function_environment(
@@ -121,7 +123,8 @@ void record_function_outputs(
121123
bool ansi_c_entry_point(
122124
symbol_tablet &symbol_table,
123125
const std::string &standard_main,
124-
message_handlert &message_handler)
126+
message_handlert &message_handler,
127+
bool wrap_entry_point)
125128
{
126129
// check if entry point is already there
127130
if(symbol_table.symbols.find(goto_functionst::entry_point())!=
@@ -444,7 +447,15 @@ bool ansi_c_entry_point(
444447
message_handler);
445448
}
446449

447-
init_code.move_to_operands(call_main);
450+
if(wrap_entry_point)
451+
{
452+
code_whilet wrapped_main=wrap_entry_point_in_while(call_main);
453+
init_code.move_to_operands(wrapped_main);
454+
}
455+
else
456+
{
457+
init_code.move_to_operands(call_main);
458+
}
448459

449460
// TODO: add read/modified (recursively in call graph) globals as INPUT/OUTPUT
450461

src/ansi-c/ansi_c_entry_point.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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);
19+
message_handlert &message_handler,
20+
bool wrap_entry_point);
2021

2122
#endif // CPROVER_ANSI_C_ANSI_C_ENTRY_POINT_H

src/ansi-c/ansi_c_language.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <util/config.h>
1515
#include <util/get_base_name.h>
16+
#include <util/cmdline.h>
1617

1718
#include <linking/linking.h>
1819
#include <linking/remove_internal_symbols.h>
@@ -26,6 +27,11 @@ Author: Daniel Kroening, [email protected]
2627
#include "ansi_c_internal_additions.h"
2728
#include "type2name.h"
2829

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+
2935
std::set<std::string> ansi_c_languaget::extensions() const
3036
{
3137
return { "c", "i" };
@@ -126,8 +132,11 @@ bool ansi_c_languaget::typecheck(
126132

127133
bool ansi_c_languaget::final(symbol_tablet &symbol_table)
128134
{
129-
if(ansi_c_entry_point(symbol_table, "main", get_message_handler()))
135+
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(),
136+
wrap_entry_point_in_while()))
137+
{
130138
return true;
139+
}
131140

132141
return false;
133142
}

src/ansi-c/ansi_c_language.h

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ 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+
2528
bool preprocess(
2629
std::istream &instream,
2730
const std::string &path,
@@ -76,6 +79,12 @@ class ansi_c_languaget:public languaget
7679
protected:
7780
ansi_c_parse_treet parse_tree;
7881
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;
7988
};
8089

8190
languaget *new_ansi_c_language();

src/cbmc/cbmc_parse_options.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Author: Daniel Kroening, [email protected]
5757

5858
#include <langapi/mode.h>
5959

60+
#include <ansi-c/ansi_c_language.h>
61+
6062
#include "cbmc_solvers.h"
6163
#include "cbmc_parse_options.h"
6264
#include "bmc.h"
@@ -1017,6 +1019,7 @@ void cbmc_parse_optionst::help()
10171019
" --round-to-minus-inf rounding towards minus infinity\n"
10181020
" --round-to-zero rounding towards zero\n"
10191021
" --function name set main function name\n"
1022+
HELP_WRAP_ENTRY_POINT_IN_WHILE_TRUE
10201023
"\n"
10211024
"Program representations:\n"
10221025
" --show-parse-tree show parse tree\n"

src/cbmc/cbmc_parse_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/parse_options.h>
1717

1818
#include <langapi/language_ui.h>
19+
#include <langapi/wrap_entry_point.h>
1920

2021
#include <analyses/goto_check.h>
2122

@@ -63,6 +64,7 @@ class optionst;
6364
"(java-cp-include-files):" \
6465
"(localize-faults)(localize-faults-method):" \
6566
"(lazy-methods)" \
67+
WRAP_ENTRY_POINT_IN_WHILE_TRUE \
6668
"(test-invariant-failure)" \
6769
"(fixedbv)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length)
6870

src/cpp/cpp_language.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/config.h>
1717
#include <util/replace_symbol.h>
1818
#include <util/get_base_name.h>
19-
19+
#include <util/cmdline.h>
2020
#include <linking/linking.h>
2121

2222
#include <ansi-c/ansi_c_entry_point.h>
@@ -29,6 +29,11 @@ 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+
3237
std::set<std::string> cpp_languaget::extensions() const
3338
{
3439
std::set<std::string> s;
@@ -135,8 +140,11 @@ bool cpp_languaget::typecheck(
135140

136141
bool cpp_languaget::final(symbol_tablet &symbol_table)
137142
{
138-
if(ansi_c_entry_point(symbol_table, "main", get_message_handler()))
143+
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(),
144+
wrap_entry_point_in_while()))
145+
{
139146
return true;
147+
}
140148

141149
return false;
142150
}

src/cpp/cpp_language.h

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ 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+
2730
bool preprocess(
2831
std::istream &instream,
2932
const std::string &path,
@@ -85,6 +88,9 @@ class cpp_languaget:public languaget
8588

8689
void modules_provided(std::set<std::string> &modules) override;
8790

91+
bool wrap_entry_point_in_while() const
92+
{ return wrap_entry_point; }
93+
8894
protected:
8995
cpp_parse_treet cpp_parse_tree;
9096
std::string parse_path;
@@ -95,6 +101,9 @@ class cpp_languaget:public languaget
95101
{
96102
return "main";
97103
}
104+
105+
private:
106+
bool wrap_entry_point;
98107
};
99108

100109
languaget *new_cpp_language();

src/goto-analyzer/goto_analyzer_parse_options.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ void goto_analyzer_parse_optionst::help()
757757
" --gcc use GCC as preprocessor\n"
758758
#endif
759759
" --no-library disable built-in abstract C library\n"
760+
HELP_WRAP_ENTRY_POINT_IN_WHILE_TRUE
760761
"\n"
761762
"Java Bytecode frontend options:\n"
762763
" --classpath dir/jar set the classpath\n"

src/goto-analyzer/goto_analyzer_parse_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ graphs in DOT format.
108108
#include <util/parse_options.h>
109109

110110
#include <langapi/language_ui.h>
111+
#include <langapi/wrap_entry_point.h>
111112

112113
#include <goto-programs/goto_model.h>
113114
#include <goto-programs/show_goto_functions.h>
@@ -149,6 +150,7 @@ class optionst;
149150
"(unwind-bounds)" \
150151
"(unwind-bounds-threshold):" \
151152
"(unwindset)" \
153+
WRAP_ENTRY_POINT_IN_WHILE_TRUE \
152154
"(functions-ignore)" \
153155
"(functions-full)"
154156

src/goto-cc/compile.cpp

+1-1
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()))
371+
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(), false))
372372
return true;
373373

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

src/langapi/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ SRC = language_ui.cpp \
22
language_util.cpp \
33
languages.cpp \
44
mode.cpp \
5+
wrap_entry_point.cpp \
56
# Empty last line
67
INCLUDES= -I ..
78

src/langapi/wrap_entry_point.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************\
2+
3+
Module: Wrap the designated entry point into a while(true) loop.
4+
5+
Author: Diffblue Limited (c) 2017
6+
7+
Date: August 2017
8+
9+
\*******************************************************************/
10+
11+
/// \file
12+
/// Wrap the designated entry point into a while(true) loop.
13+
14+
#include "wrap_entry_point.h"
15+
16+
// Build and return a while(true) statement nesting the function call
17+
// passed as a parameter.
18+
code_whilet wrap_entry_point_in_while(code_function_callt &call_main)
19+
{
20+
exprt true_expr;
21+
code_whilet while_expr;
22+
true_expr.make_true();
23+
while_expr.cond()=true_expr;
24+
while_expr.body()=call_main;
25+
26+
return while_expr;
27+
}

src/langapi/wrap_entry_point.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*******************************************************************\
2+
3+
Module: Wrap the designated entry point into a while(true) loop.
4+
5+
Author: Diffblue Limited (c) 2017
6+
7+
Date: August 2017
8+
9+
\*******************************************************************/
10+
11+
#ifndef CPROVER_LANGAPI_WRAP_ENTRY_POINT_H
12+
#define CPROVER_LANGAPI_WRAP_ENTRY_POINT_H
13+
14+
#include <util/std_code.h>
15+
16+
/// Command line option (to be shared by the different tools)
17+
#define WRAP_ENTRY_POINT_IN_WHILE_TRUE "(wrap-entry-point-in-while)"
18+
19+
/// Command line help text
20+
#define HELP_WRAP_ENTRY_POINT_IN_WHILE_TRUE \
21+
" --wrap-entry-point-in-while wrap the designated entry point function in a while(true) statement\n" // NOLINT(*)
22+
23+
code_whilet wrap_entry_point_in_while(
24+
code_function_callt &call_main);
25+
26+
#endif // CPROVER_LANGAPI_WRAP_ENTRY_POINT_H

0 commit comments

Comments
 (0)