Skip to content

Commit e73e756

Browse files
committed
Create stub globals: check for inherited globals
Bytecode can refer to a static field via a child class; for example, referring to B.f when the actual referee field is A.f, where B extends A. By missing this case we could previously accidentally create a stub global for (in this example) B.f.
1 parent bea6371 commit e73e756

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/java_bytecode/java_bytecode_language.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,18 @@ static void create_stub_global_symbols(
448448
irep_idt class_id = instruction.args[0].get_string(ID_class);
449449
INVARIANT(
450450
!class_id.empty(), "get/putstatic should specify a class");
451-
irep_idt identifier = id2string(class_id) + "." + id2string(component);
452451

453-
if(!symbol_table.has_symbol(identifier))
452+
resolve_inherited_componentt::inherited_componentt referred_component =
453+
get_inherited_component(
454+
class_id,
455+
component,
456+
"java::" + id2string(parse_tree.parsed_class.name),
457+
symbol_table);
458+
if(!referred_component.is_valid())
454459
{
460+
irep_idt identifier =
461+
id2string(class_id) + "." + id2string(component);
462+
455463
create_stub_global_symbol(
456464
symbol_table,
457465
identifier,

src/java_bytecode/java_utils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,10 @@ resolve_inherited_componentt::inherited_componentt get_inherited_component(
362362
const symbolt &component_symbol=
363363
*symbol_table.lookup(resolved_component.get_full_component_identifier());
364364

365-
const auto &access=component_symbol.type.get(ID_access);
365+
irep_idt access = component_symbol.type.get(ID_access);
366+
if(access.empty())
367+
access = component_symbol.type.get(ID_C_access);
368+
366369
if(access==ID_public || access==ID_protected)
367370
{
368371
// since the component is public, it is inherited

0 commit comments

Comments
 (0)