OSDN Git Service

ART: Fix crash in gtests
authorDavid Brazdil <dbrazdil@google.com>
Tue, 24 Mar 2015 18:49:14 +0000 (18:49 +0000)
committerDavid Brazdil <dbrazdil@google.com>
Tue, 24 Mar 2015 19:13:13 +0000 (19:13 +0000)
SsaLivenessAnalysis was crashing after change of iteration order in
142377 because gtests do not always build reverse post order.

Change-Id: If5ad5b7c52040b119c4415f0b942988049fa3c16

compiler/optimizing/codegen_test.cc
compiler/optimizing/nodes.h
compiler/optimizing/register_allocator_test.cc

index 868fc5b..40f0adc 100644 (file)
@@ -145,6 +145,7 @@ static void RunCodeOptimized(CodeGenerator* codegen,
                              std::function<void(HGraph*)> hook_before_codegen,
                              bool has_result,
                              Expected expected) {
+  graph->BuildDominatorTree();
   SsaLivenessAnalysis liveness(*graph, codegen);
   liveness.Analyze();
 
index 97ade0d..db7873b 100644 (file)
@@ -3483,7 +3483,10 @@ class HInsertionOrderIterator : public ValueObject {
 
 class HReversePostOrderIterator : public ValueObject {
  public:
-  explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {}
+  explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {
+    // Check that reverse post order of the graph has been built.
+    DCHECK(!graph.GetReversePostOrder().IsEmpty());
+  }
 
   bool Done() const { return index_ == graph_.GetReversePostOrder().Size(); }
   HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_); }
@@ -3499,7 +3502,10 @@ class HReversePostOrderIterator : public ValueObject {
 class HPostOrderIterator : public ValueObject {
  public:
   explicit HPostOrderIterator(const HGraph& graph)
-      : graph_(graph), index_(graph_.GetReversePostOrder().Size()) {}
+      : graph_(graph), index_(graph_.GetReversePostOrder().Size()) {
+    // Check that reverse post order of the graph has been built.
+    DCHECK(!graph.GetReversePostOrder().IsEmpty());
+  }
 
   bool Done() const { return index_ == 0; }
   HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_ - 1); }
index b757a3b..7a2d84b 100644 (file)
@@ -596,6 +596,8 @@ static HGraph* BuildFieldReturn(ArenaAllocator* allocator,
   graph->AddBlock(exit);
   block->AddSuccessor(exit);
   exit->AddInstruction(new (allocator) HExit());
+
+  graph->BuildDominatorTree();
   return graph;
 }
 
@@ -658,6 +660,8 @@ static HGraph* BuildTwoSubs(ArenaAllocator* allocator,
   block->AddInstruction(*second_sub);
 
   block->AddInstruction(new (allocator) HExit());
+
+  graph->BuildDominatorTree();
   return graph;
 }
 
@@ -719,6 +723,8 @@ static HGraph* BuildDiv(ArenaAllocator* allocator,
   block->AddInstruction(*div);
 
   block->AddInstruction(new (allocator) HExit());
+
+  graph->BuildDominatorTree();
   return graph;
 }