Skip to content

Commit 14e0873

Browse files
committed
Fix virtual method resolution for Java Object parameters
The skip condition for avoiding re-processing of already-visited classes had inverted logic. Fixes: #930
1 parent 4fe3ade commit 14e0873

File tree

7 files changed

+57
-5
lines changed

7 files changed

+57
-5
lines changed
890 Bytes
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Simpler test case demonstrating the virtual method resolution bug
2+
public class SimpleEquals {
3+
public static void testDirect() {
4+
// Direct call on String - this works
5+
String s1 = "hello";
6+
String s2 = "hello";
7+
assert(s1.equals(s2));
8+
}
9+
10+
public static void testThroughObject(Object o1, Object o2) {
11+
// Call through Object parameter - this was failing before the fix
12+
assert(o1.equals(o2));
13+
}
14+
15+
public static void main(String[] args) {
16+
testDirect();
17+
18+
String s1 = "world";
19+
String s2 = "world";
20+
testThroughObject(s1, s2);
21+
}
22+
}
867 Bytes
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class equals_Pass {
2+
private static boolean myEquals(Object a, Object b) {
3+
return (a == b) || (a != null && a.equals(b));
4+
}
5+
6+
public static void main(String[] args) {
7+
String a = new String("abc");
8+
String b = new String("abc");
9+
assert((a == b) || (a != null && a.equals(b))); // This passes
10+
boolean result = myEquals(a, b);
11+
assert(result); // This fails
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
SimpleEquals.class
3+
--function SimpleEquals.main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[SimpleEquals.testDirect.assertion.1\] line 6 .*: SUCCESS$
7+
^\[SimpleEquals.testThroughObject.assertion.1\] line 11 .*: SUCCESS$
8+
--
9+
^warning: ignoring
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
equals_Pass.class
3+
--function equals_Pass.main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\[equals_Pass.main.assertion.1\] line 9 .*: SUCCESS$
7+
^\[equals_Pass.main.assertion.2\] line 11 .*: SUCCESS$
8+
--
9+
^warning: ignoring

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,12 @@ void get_virtual_calleest::get_child_functions_rec(
518518
for(const auto &child : findit->second.children)
519519
{
520520
// Skip if we have already visited this and we found a function call that
521-
// did not resolve to non java.lang.Object.
521+
// resolved to a non-Object implementation (i.e., we don't need to revisit).
522522
auto it = entry_map.find(child);
523523
if(
524-
it != entry_map.end() &&
525-
(!it->second.symbol_expr.has_value() ||
526-
!it->second.symbol_expr->get_identifier().starts_with(
527-
"java::java.lang.Object")))
524+
it != entry_map.end() && it->second.symbol_expr.has_value() &&
525+
!it->second.symbol_expr->get_identifier().starts_with(
526+
"java::java.lang.Object"))
528527
{
529528
continue;
530529
}

0 commit comments

Comments
 (0)