Skip to content

Commit ed26d0a

Browse files
Merge pull request #2058 from peterschrammel/stable-disjuncts
Make disjuncts in instanceof and virtual method removal stable
2 parents 49ad1bd + 4222a94 commit ed26d0a

File tree

12 files changed

+110
-0
lines changed

12 files changed

+110
-0
lines changed
1.16 KB
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class A {
2+
}
3+
4+
class B extends A {
5+
}
6+
7+
public class Test {
8+
9+
public boolean foo(A x) {
10+
if (x instanceof A) {
11+
return true;
12+
} else {
13+
return false;
14+
}
15+
}
16+
}
1.15 KB
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
old.jar needs to be created by first adding B.class and Test.class and then
3+
updated to add A.class. This makes the class loader load the classes A and B
4+
in reverse order.
5+
*/
6+
7+
class A {
8+
}
9+
10+
class B extends A {
11+
}
12+
13+
public class Test {
14+
15+
public boolean foo(A x) {
16+
if (x instanceof A) {
17+
return true;
18+
} else {
19+
return false;
20+
}
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
new.jar
3+
old.jar
4+
// Enable multi-line checking
5+
activate-multi-line-match
6+
EXIT=0
7+
SIGNAL=0
8+
new functions:\nmodified functions:\ndeleted functions:
9+
--
10+
^warning: ignoring
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class A {
2+
boolean bar() {
3+
return true;
4+
}
5+
}
6+
7+
class B extends A {
8+
boolean bar() {
9+
return false;
10+
}
11+
}
12+
13+
public class Test {
14+
15+
public boolean foo(A x) {
16+
return x.bar();
17+
}
18+
}
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
old.jar needs to be created by first adding B.class and Test.class and then
3+
updated to add A.class. This makes the class loader load the classes A and B
4+
in reverse order.
5+
*/
6+
7+
class A {
8+
boolean bar() {
9+
return true;
10+
}
11+
}
12+
13+
class B extends A {
14+
boolean bar() {
15+
return false;
16+
}
17+
}
18+
19+
public class Test {
20+
21+
public boolean foo(A x) {
22+
return x.bar();
23+
}
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
new.jar
3+
old.jar
4+
// Enable multi-line checking
5+
activate-multi-line-match
6+
EXIT=0
7+
SIGNAL=0
8+
new functions:\nmodified functions:\ndeleted functions:
9+
--
10+
^warning: ignoring

src/goto-programs/remove_instanceof.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ std::size_t remove_instanceoft::lower_instanceof(
8787
std::vector<irep_idt> children=
8888
class_hierarchy.get_children_trans(target_name);
8989
children.push_back(target_name);
90+
// Sort alphabetically to make order of generated disjuncts
91+
// independent of class loading order
92+
std::sort(
93+
children.begin(),
94+
children.end(),
95+
[](const irep_idt &a, const irep_idt &b) { // NOLINT
96+
return a.compare(b) < 0;
97+
});
9098

9199
// Insert an instruction before the new check that assigns the clsid we're
92100
// checking for to a temporary, as GOTO program if-expressions should

src/goto-programs/remove_virtual_functions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ 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;
448450
else
449451
return a.symbol_expr.get_identifier() < b.symbol_expr.get_identifier();
450452
});

0 commit comments

Comments
 (0)