Do not place null check from unresolved field access.
Rationale:
These accesses go though the runtime anyway where various
checks are done, including null check. Since particular
checks, like access checks, need to occur prior to the
null check (to ensure link errors are not masked by
a null reference), the explicit null check should not
occur in the HIR.
BUG=29068831
Change-Id: I30fc9cb8cf4993e4176e235ceba3a38aef98d503
diff --git a/compiler/optimizing/instruction_builder.cc b/compiler/optimizing/instruction_builder.cc
index aaddc01..5e691c7 100644
--- a/compiler/optimizing/instruction_builder.cc
+++ b/compiler/optimizing/instruction_builder.cc
@@ -1204,7 +1204,12 @@
compiler_driver_->ComputeInstanceFieldInfo(field_index, dex_compilation_unit_, is_put, soa);
- HInstruction* object = LoadNullCheckedLocal(obj_reg, dex_pc);
+ // Generate an explicit null check on the reference, unless the field access
+ // is unresolved. In that case, we rely on the runtime to perform various
+ // checks first, followed by a null check.
+ HInstruction* object = (resolved_field == nullptr)
+ ? LoadLocal(obj_reg, Primitive::kPrimNot)
+ : LoadNullCheckedLocal(obj_reg, dex_pc);
Primitive::Type field_type = (resolved_field == nullptr)
? GetFieldAccessType(*dex_file_, field_index)