Skip to content

Commit 1f4eb8c

Browse files
authored
Merge pull request #219 from diffblue/random-traces-fix
random traces should only consider top-level inputs
2 parents 3b36810 + e857c65 commit 1f4eb8c

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE broken-smt-backend
2+
with_submodule.v
3+
--random-traces --trace-steps 0 --number-of-traces 2
4+
^\*\*\* Trace 1$
5+
^ main\.some_wire = 0$
6+
^ main\.input1 = 0$
7+
^ main\.instance\.some_wire = 0$
8+
^ main\.instance\.sub_input = 0$
9+
^\*\*\* Trace 2$
10+
^ main\.some_wire = 1$
11+
^ main\.input1 = 1$
12+
^ main\.instance\.some_wire = 1$
13+
^ main\.instance\.sub_input = 1$
14+
^EXIT=0$
15+
^SIGNAL=0$
16+
--
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module submodule(input sub_input);
2+
3+
wire some_wire = sub_input;
4+
5+
endmodule
6+
7+
module main(input input1);
8+
9+
wire some_wire = input1;
10+
11+
submodule instance(some_wire);
12+
13+
endmodule

src/ebmc/random_traces.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -252,34 +252,27 @@ Function: random_tracest::inputs
252252
random_tracest::inputst random_tracest::inputs() const
253253
{
254254
inputst inputs;
255-
const symbol_tablet &symbol_table = ns.get_symbol_table();
256255

257-
auto module_identifier = transition_system.main_symbol->name;
258-
auto lower = symbol_table.symbol_module_map.lower_bound(module_identifier);
259-
auto upper = symbol_table.symbol_module_map.upper_bound(module_identifier);
256+
const auto &module_symbol = *transition_system.main_symbol;
260257

261-
// We need a deterministic ordering of the inputs that's
262-
// portable accross implementations. We use irep_idt::compare.
263-
std::vector<irep_idt> input_identifiers;
258+
if(module_symbol.type.id() != ID_module)
259+
throw ebmc_errort() << "expected a module but got "
260+
<< module_symbol.type.id();
264261

265-
for(auto it = lower; it != upper; it++)
266-
{
267-
const symbolt &symbol = ns.lookup(it->second);
262+
const auto &ports = module_symbol.type.find(ID_ports);
268263

269-
if(symbol.is_input)
270-
input_identifiers.push_back(symbol.name);
264+
// filter out the inputs
265+
for(auto &port : static_cast<const exprt &>(ports).operands())
266+
{
267+
DATA_INVARIANT(port.id() == ID_symbol, "port must be a symbol");
268+
if(port.get_bool(ID_input) && !port.get_bool(ID_output))
269+
{
270+
symbol_exprt input_symbol(port.get(ID_identifier), port.type());
271+
input_symbol.add_source_location() = port.source_location();
272+
inputs.push_back(std::move(input_symbol));
273+
}
271274
}
272275

273-
// sort by identifier
274-
std::sort(
275-
input_identifiers.begin(),
276-
input_identifiers.end(),
277-
[](const irep_idt &a, const irep_idt &b) { return a.compare(b) < 0; });
278-
279-
// turn into symbol_exprt
280-
for(auto identifier : input_identifiers)
281-
inputs.push_back(ns.lookup(identifier).symbol_expr());
282-
283276
return inputs;
284277
}
285278

@@ -336,7 +329,9 @@ std::vector<exprt> random_tracest::random_input_constraints(
336329
auto input_in_timeframe = instantiate(input, i, number_of_timeframes, ns);
337330
auto constraint =
338331
equal_exprt(input_in_timeframe, random_value(input.type()));
339-
result.push_back(solver.handle(constraint));
332+
auto handle = solver.handle(constraint);
333+
CHECK_RETURN(handle.id() == ID_literal);
334+
result.push_back(handle);
340335
}
341336
}
342337

@@ -382,6 +377,9 @@ void random_tracest::operator()(
382377

383378
auto inputs = this->inputs();
384379

380+
if(inputs.empty())
381+
throw ebmc_errort() << "module does not have inputs";
382+
385383
message.statistics() << "Found " << inputs.size() << " input(s)"
386384
<< messaget::eom;
387385

0 commit comments

Comments
 (0)