Skip to content

Commit 7b42a2b

Browse files
author
Daniel Kroening
authored
Merge pull request #767 from owen-jones-diffblue/feature/pointer-function-parameters
Reorganise C parameter creation
2 parents 94e833d + db510c9 commit 7b42a2b

File tree

13 files changed

+543
-173
lines changed

13 files changed

+543
-173
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
int fun(int **a)
2+
{
3+
if(!a)
4+
{
5+
return 0;
6+
}
7+
if(!*a)
8+
{
9+
return 1;
10+
}
11+
if(**a==4)
12+
{
13+
return 2;
14+
}
15+
return 3;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--function fun --cover branch
4+
^\*\* 7 of 7 covered \(100.0%\)$
5+
^\*\* Used 4 iterations$
6+
^Test suite:$
7+
^a=\(\(signed int \*\*\)NULL\), tmp\$1=[^,]*, tmp\$2=[^,]*$
8+
^a=&tmp\$1!0, tmp\$1=\(\(signed int \*\)NULL\), tmp\$2=[^,]*$
9+
^a=&tmp\$1!0, tmp\$1=&tmp\$2!0, tmp\$2=([012356789][0-9]*|4[0-9]+)$
10+
^a=&tmp\$1!0, tmp\$1=&tmp\$2!0, tmp\$2=4$
11+
--
12+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
int fun(int *a)
2+
{
3+
if(!a)
4+
{
5+
return 0;
6+
}
7+
if(*a==4)
8+
{
9+
return 1;
10+
}
11+
return 2;
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
--function fun --cover branch
4+
^\*\* 5 of 5 covered \(100\.0%\)$
5+
^\*\* Used 3 iterations$
6+
^Test suite:$
7+
^a=\(\(signed int \*\)NULL\), tmp\$1=[^,]*$
8+
^a=&tmp\$1!0, tmp\$1=4$
9+
^a=&tmp\$1!0, tmp\$1=([012356789][0-9]*|4[0-9]+)$
10+
--
11+
^warning: ignoring

src/ansi-c/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SRC = anonymous_member.cpp \
1111
ansi_c_typecheck.cpp \
1212
ansi_c_y.tab.cpp \
1313
c_misc.cpp \
14+
c_nondet_symbol_factory.cpp \
1415
c_preprocess.cpp \
1516
c_qualifiers.cpp \
1617
c_sizeof.cpp \

src/ansi-c/ansi_c_entry_point.cpp

+26-56
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2424
#include <linking/static_lifetime_init.h>
2525

2626
#include "ansi_c_entry_point.h"
27+
#include "c_nondet_symbol_factory.h"
2728

2829
/*******************************************************************\
2930
@@ -40,66 +41,31 @@ Function: build_function_environment
4041
exprt::operandst build_function_environment(
4142
const code_typet::parameterst &parameters,
4243
code_blockt &init_code,
43-
symbol_tablet &symbol_table)
44+
symbol_tablet &symbol_table,
45+
message_handlert &message_handler)
4446
{
45-
exprt::operandst result;
46-
result.resize(parameters.size());
47+
exprt::operandst main_arguments;
48+
main_arguments.resize(parameters.size());
4749

48-
std::size_t i=0;
49-
50-
for(const auto &p : parameters)
50+
for(std::size_t param_number=0;
51+
param_number<parameters.size();
52+
param_number++)
5153
{
52-
irep_idt base_name=p.get_base_name().empty()?
53-
("argument#"+std::to_string(i)):p.get_base_name();
54-
irep_idt identifier=id2string(goto_functionst::entry_point())+
55-
"::"+id2string(base_name);
56-
57-
{
58-
auxiliary_symbolt new_symbol;
59-
new_symbol.mode=ID_C;
60-
new_symbol.is_static_lifetime=false;
61-
new_symbol.name=identifier;
62-
new_symbol.base_name=base_name;
63-
new_symbol.type=p.type();
64-
65-
symbol_table.move(new_symbol);
66-
}
67-
68-
symbol_exprt symbol_expr(identifier, p.type());
69-
70-
code_declt decl;
71-
decl.symbol()=symbol_expr;
72-
73-
init_code.add(decl);
74-
75-
// nondet init for _Bool
76-
if(decl.symbol().type().id()==ID_c_bool)
77-
{
78-
code_assignt assign(
79-
decl.symbol(),
80-
typecast_exprt(
81-
side_effect_expr_nondett(bool_typet()),
82-
decl.symbol().type()));
83-
84-
init_code.move_to_operands(assign);
85-
}
86-
87-
codet input(ID_input);
88-
input.operands().resize(2);
89-
90-
// record as an input
91-
input.op0()=address_of_exprt(
92-
index_exprt(string_constantt(base_name), from_integer(0, index_type())));
93-
input.op1()=symbol_expr;
94-
input.add_source_location()=p.source_location();
95-
96-
init_code.move_to_operands(input);
97-
98-
result[i]=symbol_expr;
99-
i++;
54+
const code_typet::parametert &p=parameters[param_number];
55+
const irep_idt base_name=p.get_base_name().empty()?
56+
("argument#"+std::to_string(param_number)):p.get_base_name();
57+
58+
main_arguments[param_number]=
59+
c_nondet_symbol_factory(
60+
init_code,
61+
symbol_table,
62+
base_name,
63+
p.type(),
64+
p.source_location(),
65+
true);
10066
}
10167

102-
return result;
68+
return main_arguments;
10369
}
10470

10571
/*******************************************************************\
@@ -506,7 +472,11 @@ bool ansi_c_entry_point(
506472
{
507473
// produce nondet arguments
508474
call_main.arguments()=
509-
build_function_environment(parameters, init_code, symbol_table);
475+
build_function_environment(
476+
parameters,
477+
init_code,
478+
symbol_table,
479+
message_handler);
510480
}
511481

512482
init_code.move_to_operands(call_main);

0 commit comments

Comments
 (0)