Skip to content

Commit

Permalink
Create stub globals: check for inherited globals
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smowton committed Feb 14, 2018
1 parent bea6371 commit e73e756
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/java_bytecode/java_bytecode_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,18 @@ static void create_stub_global_symbols(
irep_idt class_id = instruction.args[0].get_string(ID_class);
INVARIANT(
!class_id.empty(), "get/putstatic should specify a class");
irep_idt identifier = id2string(class_id) + "." + id2string(component);

if(!symbol_table.has_symbol(identifier))
resolve_inherited_componentt::inherited_componentt referred_component =
get_inherited_component(
class_id,
component,
"java::" + id2string(parse_tree.parsed_class.name),
symbol_table);
if(!referred_component.is_valid())
{
irep_idt identifier =
id2string(class_id) + "." + id2string(component);

create_stub_global_symbol(
symbol_table,
identifier,
Expand Down
5 changes: 4 additions & 1 deletion src/java_bytecode/java_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ resolve_inherited_componentt::inherited_componentt get_inherited_component(
const symbolt &component_symbol=
*symbol_table.lookup(resolved_component.get_full_component_identifier());

const auto &access=component_symbol.type.get(ID_access);
irep_idt access = component_symbol.type.get(ID_access);
if(access.empty())
access = component_symbol.type.get(ID_C_access);

if(access==ID_public || access==ID_protected)
{
// since the component is public, it is inherited
Expand Down

0 comments on commit e73e756

Please sign in to comment.