Skip to content

Commit e8d26ae

Browse files
Merge pull request #2267 from LAJW/lajw/always-load-cprover-nondet-initialize
[TG-3657] Always load CProver.nondetInitialize
2 parents 3082d9d + a673e5d commit e8d26ae

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import org.cprover.CProver;
2+
3+
class ObjectWithNondetInitialize {
4+
private int value_;
5+
public void cproverNondetInitialize() {
6+
CProver.assume(value_ == 13);
7+
}
8+
public int value() {
9+
return value_;
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import org.cprover.CProver;
2+
3+
public class Opaque {
4+
public ObjectWithNondetInitialize get() {
5+
return new ObjectWithNondetInitialize();
6+
}
7+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class Test {
2+
public int test() {
3+
return (new Opaque()).get().value();
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
KNOWNBUG
2+
Test.class
3+
--function Test.test --show-goto-functions --lazy-methods
4+
EXIT=0
5+
SIGNAL=0
6+
ObjectWithNondetInitialize\.cproverNondetInitialize\(\)
7+
--
8+
--
9+
Check if cproverNondetInitialize method is loaded in an object
10+
returned from an opaque method
11+
https://github.com/diffblue/cbmc/issues/2273

jbmc/src/java_bytecode/ci_lazy_methods.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@ bool ci_lazy_methodst::operator()(
248248
}
249249
}
250250

251+
// cproverNondetInitialize has to be force-loaded for mocks to return valid
252+
// objects (objects which satisfy invariants specified in the
253+
// cproverNondetInitialize method)
254+
for(const auto &class_name : instantiated_classes)
255+
{
256+
const irep_idt cprover_validate =
257+
id2string(class_name) + ".cproverNondetInitialize:()V";
258+
if(symbol_table.symbols.count(cprover_validate))
259+
methods_already_populated.insert(cprover_validate);
260+
}
261+
251262
// Remove symbols for methods that were declared but never used:
252263
symbol_tablet keep_symbols;
253264
// Manually keep @inflight_exception, as it is unused at this stage

0 commit comments

Comments
 (0)