From 4ae432df025804031ea89285dd9f89051124a966 Mon Sep 17 00:00:00 2001 From: Igor Murashkin Date: Thu, 4 May 2017 14:15:08 -0700 Subject: optimizing: Fix undefined behavior in graph checker Checking a variable being null after dereference is undefed behavior and the null check is often optimized out. Change-Id: I4d80510af6d49def1f9f7bd82c25eb366169babb --- compiler/optimizing/graph_checker.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'compiler/optimizing/graph_checker.cc') diff --git a/compiler/optimizing/graph_checker.cc b/compiler/optimizing/graph_checker.cc index 6a140458a6..aea901dec7 100644 --- a/compiler/optimizing/graph_checker.cc +++ b/compiler/optimizing/graph_checker.cc @@ -338,19 +338,21 @@ void GraphChecker::VisitInstruction(HInstruction* instruction) { // Ensure the inputs of `instruction` are defined in a block of the graph. for (HInstruction* input : instruction->GetInputs()) { - const HInstructionList& list = input->IsPhi() - ? input->GetBlock()->GetPhis() - : input->GetBlock()->GetInstructions(); if (input->GetBlock() == nullptr) { AddError(StringPrintf("Input %d of instruction %d is not in any " "basic block of the control-flow graph.", input->GetId(), instruction->GetId())); - } else if (!list.Contains(input)) { - AddError(StringPrintf("Input %d of instruction %d is not defined " - "in a basic block of the control-flow graph.", - input->GetId(), - instruction->GetId())); + } else { + const HInstructionList& list = input->IsPhi() + ? input->GetBlock()->GetPhis() + : input->GetBlock()->GetInstructions(); + if (!list.Contains(input)) { + AddError(StringPrintf("Input %d of instruction %d is not defined " + "in a basic block of the control-flow graph.", + input->GetId(), + instruction->GetId())); + } } } -- cgit v1.2.3-59-g8ed1b