Repository navigation
JBMC: test virtual dispatch of equals through Object - #8759
tautschnig wants to merge 1 commit into
Conversation
14e0873 to
4006e98
Compare
There was a problem hiding this comment.
Pull request overview
Fixes JBMC’s Java virtual-call callee discovery so classes previously visited with an unresolved/java.lang.Object target aren’t prematurely skipped, which could prevent resolving the correct override when dispatching through Object-typed receivers/parameters (issue #930).
Changes:
- Correct the “already visited” skip condition in
get_child_functions_recto only skip when a prior visit resolved to a non-java.lang.Objectimplementation. - Add a JBMC regression test for virtual dispatch through an
Object-typed parameter, including the corresponding.descand compiled.classartifacts.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/goto-programs/remove_virtual_functions.cpp |
Fixes inverted skip logic in virtual callee traversal to enable correct resolution beyond java.lang.Object. |
jbmc/regression/jbmc/virtual_equals_object_param/simple_test.desc |
Adds a new regression driver for the Java test. |
jbmc/regression/jbmc/virtual_equals_object_param/SimpleEquals.java |
Adds a Java regression program exercising virtual dispatch via an Object-typed parameter. |
jbmc/regression/jbmc/virtual_equals_object_param/SimpleEquals.class |
Compiled bytecode for the new regression. |
jbmc/regression/jbmc/virtual_equals_object_param/SimpleEquals$MyClass.class |
Compiled bytecode for the nested class in the new regression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Skip if we have already visited this and we found a function call that | ||
| // did not resolve to non java.lang.Object. | ||
| // resolved to a non-Object implementation (i.e., we don't need to revisit). | ||
| auto it = entry_map.find(child); | ||
| if( | ||
| it != entry_map.end() && | ||
| (!it->second.symbol_expr.has_value() || | ||
| !it->second.symbol_expr->get_identifier().starts_with( | ||
| "java::java.lang.Object"))) | ||
| it != entry_map.end() && it->second.symbol_expr.has_value() && | ||
| !it->second.symbol_expr->get_identifier().starts_with( | ||
| "java::java.lang.Object")) |
| public String toString() { | ||
| counter++; | ||
| return "MyClass"; | ||
| } | ||
| } | ||
|
|
||
| public static void testDirect() { | ||
| MyClass m = new MyClass(); | ||
| m.toString(); | ||
| assert(counter == 1); | ||
| } | ||
|
|
||
| public static void testThroughObject(Object o) { | ||
| // Virtual call through Object parameter should resolve to MyClass.toString | ||
| o.toString(); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8759 +/- ##
===========================================
+ Coverage 81.29% 81.34% +0.04%
===========================================
Files 1725 1727 +2
Lines 191680 191715 +35
Branches 73 73
===========================================
+ Hits 155835 155948 +113
+ Misses 35845 35767 -78 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Issue diffblue#930 reported that, in private static boolean myEquals(Object a, Object b) { return (a == b) || (a != null && a.equals(b)); } the call of equals did not resolve to String.equals, so that assert(myEquals(a, b)) failed for equal Strings a and b, while the same comparison written in main succeeded. Both assertions hold on develop when the Java models library is on the class path; without it, JBMC has no model of String and both assertions fail alike. Add the example from the issue as a regression test. Fixes: diffblue#930 Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
4006e98 to
93a847d
Compare
Issue #930 reported that calling
equalsthrough a parameter of typeObjectdid not resolve toString.equals. The example from the issue passes on develop when the Java models library is on the class path (without it, JBMC has no model ofString, and both assertions fail alike). This PR adds that example as a regression test.An earlier version of this PR changed the skip condition in
get_child_functions_rec(remove_virtual_functions.cpp). That change had no observable effect: the tests, the example from #930, and a differential fuzzing run over 286 generated Java dispatch programs gave the same results with and without it. The current condition keeps the behaviour that the code had before 6b2b950.Fixes: #930