Skip to content

Commit 3dd2079

Browse files
committed
Added new tests for CBMC, and made the tests for goto-analyser more robust.
1 parent 9e89379 commit 3dd2079

File tree

22 files changed

+81
-46
lines changed

22 files changed

+81
-46
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
@@ -1,4 +1,4 @@
11
int main(int argc, char **argv)
22
{
33
return 0;
4-
}
4+
}

regression/goto-analyzer/wrap_entry_point_in_while_true/test.desc

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ main.c
44
^EXIT=6$
55
^SIGNAL=0$
66
^ 1: IF FALSE THEN GOTO 2$
7-
^ // 22 file main.c line 1$
87
^ main\(argc', argv'\);$
9-
^ // 23 file main.c line 1$
10-
^ return' = main#return_value;$
11-
^ // 24 file main.c line 1$
12-
^ dead main#return_value;$
13-
^ // 25 no location$
148
^ GOTO 1$
15-
--
9+
--
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
int skipWhitespace()
22
{
33
return 120;
4-
}
4+
}

regression/goto-analyzer/wrap_entry_point_in_while_true_custom_entry_point/test.desc

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ main.c
44
^EXIT=6$
55
^SIGNAL=0$
66
^ 1: IF FALSE THEN GOTO 2$
7-
^ // 18 file main.c line 1
87
^ skipWhitespace\(\);$
9-
^ // 19 file main.c line 1$
10-
^ return' = skipWhitespace#return_value;$
11-
^ // 20 file main.c line 1$
12-
^ dead skipWhitespace#return_value;$
13-
^ // 21 no location$
148
^ GOTO 1$
15-
--
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

+6-3
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,13 @@ bool ansi_c_entry_point(
447447
message_handler);
448448
}
449449

450-
if (wrap_entry_point) {
451-
auto wrapped_main = wrap_entry_point_in_while(call_main);
450+
if(wrap_entry_point)
451+
{
452+
code_whilet wrapped_main=wrap_entry_point_in_while(call_main);
452453
init_code.move_to_operands(wrapped_main);
453-
} else {
454+
}
455+
else
456+
{
454457
init_code.move_to_operands(call_main);
455458
}
456459

src/ansi-c/ansi_c_language.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ Author: Daniel Kroening, [email protected]
2929

3030
void ansi_c_languaget::get_language_options(const cmdlinet &cmd)
3131
{
32-
if (cmd.isset("wrap-entry-point-in-while"))
33-
{
34-
wrap_entry_point = true;
35-
}
32+
wrap_entry_point=cmd.isset("wrap-entry-point-in-while");
3633
}
3734

3835
std::set<std::string> ansi_c_languaget::extensions() const
@@ -136,8 +133,10 @@ bool ansi_c_languaget::typecheck(
136133
bool ansi_c_languaget::final(symbol_tablet &symbol_table)
137134
{
138135
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(),
139-
wrap_entry_point_in_while()))
136+
wrap_entry_point_in_while()))
137+
{
140138
return true;
139+
}
141140

142141
return false;
143142
}
@@ -221,6 +220,7 @@ bool ansi_c_languaget::to_expr(
221220
expr.type().id()==ID_empty &&
222221
expr.operands().size()==1)
223222
expr=expr.op0();
223+
224224
return result;
225225
}
226226

src/ansi-c/ansi_c_language.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ class ansi_c_languaget:public languaget
7070
languaget *new_language() override
7171
{ return new ansi_c_languaget; }
7272

73-
bool wrap_entry_point_in_while()
74-
{ return wrap_entry_point; }
75-
7673
std::string id() const override { return "C"; }
7774
std::string description() const override { return "ANSI-C 99"; }
7875
std::set<std::string> extensions() const override;
@@ -83,6 +80,9 @@ class ansi_c_languaget:public languaget
8380
ansi_c_parse_treet parse_tree;
8481
std::string parse_path;
8582

83+
bool wrap_entry_point_in_while() const
84+
{ return wrap_entry_point; }
85+
8686
private:
8787
bool wrap_entry_point;
8888
};

src/cbmc/cbmc_parse_options.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ Author: Daniel Kroening, [email protected]
6565
#include "version.h"
6666
#include "xml_interface.h"
6767

68-
69-
7068
cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv):
7169
parse_options_baset(CBMC_OPTIONS, argc, argv),
7270
xml_interfacet(cmdline),
@@ -185,9 +183,6 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
185183
cmdline.get_value("localize-faults-method"));
186184
}
187185

188-
if (cmdline.isset("wrap-entry-point-in-while"))
189-
options.set_option("wrap-entry-point-in-while", true);
190-
191186
if(cmdline.isset("unwind"))
192187
options.set_option("unwind", cmdline.get_value("unwind"));
193188

@@ -604,6 +599,7 @@ int cbmc_parse_optionst::get_goto_program(
604599
}
605600

606601
language->set_message_handler(get_message_handler());
602+
607603
status() << "Parsing " << filename << eom;
608604

609605
if(language->parse(infile, filename))

src/cpp/cpp_language.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ Author: Daniel Kroening, [email protected]
3131

3232
void cpp_languaget::get_language_options(const cmdlinet &cmd)
3333
{
34-
if (cmd.isset("wrap-entry-point-in-while"))
35-
{
36-
wrap_entry_point = true;
37-
}
34+
wrap_entry_point=cmd.isset("wrap-entry-point-in-while");
3835
}
3936

4037
std::set<std::string> cpp_languaget::extensions() const
@@ -144,8 +141,10 @@ bool cpp_languaget::typecheck(
144141
bool cpp_languaget::final(symbol_tablet &symbol_table)
145142
{
146143
if(ansi_c_entry_point(symbol_table, "main", get_message_handler(),
147-
wrap_entry_point_in_while()))
144+
wrap_entry_point_in_while()))
145+
{
148146
return true;
147+
}
149148

150149
return false;
151150
}

src/cpp/cpp_language.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class cpp_languaget:public languaget
8888

8989
void modules_provided(std::set<std::string> &modules) override;
9090

91-
bool wrap_entry_point_in_while()
91+
bool wrap_entry_point_in_while() const
9292
{ return wrap_entry_point; }
9393

9494
protected:

src/goto-instrument/goto_instrument_parse_options.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,6 @@ void goto_instrument_parse_optionst::help()
15541554
" --log <file> log in json format which code segments were inlined, use with --function-inline\n" // NOLINT(*)
15551555
" --remove-function-pointers replace function pointers by case statement over function calls\n" // NOLINT(*)
15561556
HELP_REMOVE_CONST_FUNCTION_POINTERS
1557-
HELP_WRAP_ENTRY_POINT_IN_WHILE_TRUE
15581557
" --add-library add models of C library functions\n"
15591558
" --model-argc-argv <n> model up to <n> command line arguments\n"
15601559
// NOLINTNEXTLINE(whitespace/line_length)

src/goto-instrument/goto_instrument_parse_options.h

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ 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>
2019
#include <goto-programs/goto_functions.h>
2120
#include <goto-programs/show_goto_functions.h>
2221
#include <goto-programs/remove_const_function_pointers.h>
@@ -79,7 +78,6 @@ Author: Daniel Kroening, [email protected]
7978
"(show-threaded)(list-calls-args)(print-path-lengths)" \
8079
"(undefined-function-is-assume-false)" \
8180
"(remove-function-body):" \
82-
WRAP_ENTRY_POINT_IN_WHILE_TRUE \
8381
"(remove-calls-nobody)"
8482

8583
class goto_instrument_parse_optionst:

src/langapi/wrap_entry_point.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ code_whilet wrap_entry_point_in_while(code_function_callt &call_main)
2020
exprt true_expr;
2121
code_whilet while_expr;
2222
true_expr.make_true();
23-
while_expr.cond() = true_expr;
24-
while_expr.body() = call_main;
23+
while_expr.cond()=true_expr;
24+
while_expr.body()=call_main;
2525

2626
return while_expr;
2727
}

src/langapi/wrap_entry_point.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Date: August 2017
88
99
\*******************************************************************/
1010

11-
#ifndef WRAP_ENTRY_POINT_H
12-
#define WRAP_ENTRY_POINT_H
11+
#ifndef CPROVER_LANGAPI_WRAP_ENTRY_POINT_H
12+
#define CPROVER_LANGAPI_WRAP_ENTRY_POINT_H
1313

1414
#include <util/std_code.h>
1515

@@ -23,4 +23,4 @@ Date: August 2017
2323
code_whilet wrap_entry_point_in_while(
2424
code_function_callt &call_main);
2525

26-
#endif // WRAP_ENTRY_POINT_H
26+
#endif // CPROVER_LANGAPI_WRAP_ENTRY_POINT_H

0 commit comments

Comments
 (0)