Skip to content

Commit b8ce0a7

Browse files
author
Daniel Kroening
committed
Merge pull request #54 from tautschnig/missing-arguments
Handle missing arguments more gracefully
2 parents 759f172 + 8acbb9e commit b8ce0a7

File tree

2 files changed

+40
-28
lines changed

2 files changed

+40
-28
lines changed

src/goto-programs/goto_inline.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ void goto_inlinet::parameter_assignments(
5050
it2!=parameter_types.end();
5151
it2++)
5252
{
53-
// if you run out of actual arguments there was a mismatch
54-
if(it1==arguments.end())
55-
{
56-
err_location(source_location);
57-
str << "call to `" << function_name << "': not enough arguments";
58-
throw 0;
59-
}
60-
6153
const code_typet::parametert &parameter=*it2;
6254

6355
// this is the type the n-th argument should be
@@ -82,15 +74,28 @@ void goto_inlinet::parameter_assignments(
8274
decl->function=function_name;
8375
}
8476

77+
// this is the actual parameter
78+
exprt actual;
79+
80+
// if you run out of actual arguments there was a mismatch
81+
if(it1==arguments.end())
82+
{
83+
err_location(source_location);
84+
str << "call to `" << function_name << "': "
85+
"not enough arguments, inserting non-deterministic value";
86+
warning_msg();
87+
88+
actual=side_effect_expr_nondett(par_type);
89+
}
90+
else
91+
actual=*it1;
92+
8593
// nil means "don't assign"
86-
if(it1->is_nil())
94+
if(actual.is_nil())
8795
{
8896
}
8997
else
9098
{
91-
// this is the actual parameter
92-
exprt actual=*it1;
93-
9499
// it should be the same exact type as the parameter,
95100
// subject to some exceptions
96101
if(!base_type_eq(par_type, actual.type(), ns))
@@ -118,7 +123,7 @@ void goto_inlinet::parameter_assignments(
118123
}
119124
else
120125
{
121-
err_location(*it1);
126+
err_location(actual);
122127

123128
str << "function call: argument `" << identifier
124129
<< "' type mismatch: argument is `"
@@ -141,7 +146,8 @@ void goto_inlinet::parameter_assignments(
141146
dest.instructions.back().function=function_name;
142147
}
143148

144-
it1++;
149+
if(it1!=arguments.end())
150+
++it1;
145151
}
146152

147153
if(it1!=arguments.end())

src/goto-symex/symex_function_call.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9+
#include <iostream>
910
#include <cassert>
1011

1112
#include <util/expr_util.h>
@@ -74,15 +75,6 @@ void goto_symext::parameter_assignments(
7475
it2!=parameter_types.end();
7576
it2++)
7677
{
77-
// if you run out of actual arguments there was a mismatch
78-
if(it1==arguments.end())
79-
{
80-
std::string error=
81-
"call to `"+id2string(function_identifier)+"': "
82-
"not enough arguments";
83-
throw state.source.pc->source_location.as_string()+": "+error;
84-
}
85-
8678
const code_typet::parametert &parameter=*it2;
8779

8880
// this is the type that the n-th argument should have
@@ -96,14 +88,27 @@ void goto_symext::parameter_assignments(
9688
const symbolt &symbol=ns.lookup(identifier);
9789
symbol_exprt lhs=symbol.symbol_expr();
9890

99-
if(it1->is_nil())
91+
exprt rhs;
92+
93+
// if you run out of actual arguments there was a mismatch
94+
if(it1==arguments.end())
95+
{
96+
std::string warn=
97+
"call to `"+id2string(function_identifier)+"': "
98+
"not enough arguments, inserting non-deterministic value\n";
99+
std::cerr << state.source.pc->source_location.as_string()+": "+warn;
100+
101+
rhs=side_effect_expr_nondett(parameter_type);
102+
}
103+
else
104+
rhs=*it1;
105+
106+
if(rhs.is_nil())
100107
{
101108
// 'nil' argument doesn't get assigned
102109
}
103110
else
104111
{
105-
exprt rhs=*it1;
106-
107112
// It should be the same exact type.
108113
if(!base_type_eq(parameter_type, rhs.type(), ns))
109114
{
@@ -130,7 +135,7 @@ void goto_symext::parameter_assignments(
130135
{
131136
std::string error="function call: parameter \""+
132137
id2string(identifier)+"\" type mismatch: got "+
133-
it1->type().to_string()+", expected "+
138+
rhs.type().to_string()+", expected "+
134139
parameter_type.to_string();
135140
throw error;
136141
}
@@ -139,7 +144,8 @@ void goto_symext::parameter_assignments(
139144
symex_assign_rec(state, code_assignt(lhs, rhs));
140145
}
141146

142-
it1++;
147+
if(it1!=arguments.end())
148+
it1++;
143149
}
144150

145151
if(function_type.has_ellipsis())

0 commit comments

Comments
 (0)