Skip to content

Commit e1f4120

Browse files
committed
Make virtual function resolution independent of string table entry ordering
The program generated by virtual-function removal depended on where 'B', 'C', 'D', 'E' appear in the string table as there are multiple semantically equivalent resolutions of virtual functions.
1 parent 714ccff commit e1f4120

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

regression/cbmc-java/virtual7/test.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ test.class
33
--show-goto-functions --function test.main
44
^EXIT=0$
55
^SIGNAL=0$
6-
IF.*"java::C".*THEN GOTO
7-
IF.*"java::D".*THEN GOTO
6+
IF.*"java::B".*THEN GOTO
7+
IF.*"java::E".*THEN GOTO
88
IF.*"java::A".*THEN GOTO

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,15 @@ void remove_virtual_functionst::get_functions(
445445
has_prefix(
446446
id2string(b.symbol_expr.get_identifier()), "java::java.lang.Object"))
447447
return true;
448-
else if(a.symbol_expr.get_identifier() == b.symbol_expr.get_identifier())
449-
return a.class_id < b.class_id;
450448
else
451-
return a.symbol_expr.get_identifier() < b.symbol_expr.get_identifier();
449+
{
450+
int cmp = a.symbol_expr.get_identifier().compare(
451+
b.symbol_expr.get_identifier());
452+
if(cmp == 0)
453+
return a.class_id < b.class_id;
454+
else
455+
return cmp < 0;
456+
}
452457
});
453458
}
454459

0 commit comments

Comments
 (0)