Skip to content

Commit 045ac05

Browse files
committed
Create stub globals on the first parent incomplete class
Previously if a reference to static field A.x did not resolve, then A.x would be created as a stub, but this is inappropriate if A is a complete (non-stub) class. Instead, create the field on A's first ancestor that is incomplete.
1 parent 5b3cde5 commit 045ac05

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/java_bytecode/java_bytecode_language.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,29 @@ static void create_stub_global_symbols(
460460
class_hierarchy);
461461
if(!referred_component.is_valid())
462462
{
463+
// Create a new stub global on the first incomplete (stub) parent of
464+
// the class that was referred to:
465+
irep_idt add_to_class_id = class_id;
466+
while(!symbol_table.lookup_ref(add_to_class_id).type.get_bool(
467+
ID_incomplete_class))
468+
{
469+
const class_hierarchyt::idst &parents =
470+
class_hierarchy.class_map.at(add_to_class_id).parents;
471+
INVARIANT(
472+
!parents.empty(),
473+
"unresolved global reference should come from incomplete class");
474+
add_to_class_id = parents[0];
475+
}
476+
463477
irep_idt identifier =
464-
id2string(class_id) + "." + id2string(component);
478+
id2string(add_to_class_id) + "." + id2string(component);
465479

466480
create_stub_global_symbol(
467481
symbol_table,
468482
identifier,
469483
component,
470484
instruction.args[0].type(),
471-
class_id);
485+
add_to_class_id);
472486
}
473487
}
474488
}

0 commit comments

Comments
 (0)