[polly] r312451 - [ScopHelper] Do not crash on unreachable blocks

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 3 11:01:22 PDT 2017


Author: grosser
Date: Sun Sep  3 11:01:22 2017
New Revision: 312451

URL: http://llvm.org/viewvc/llvm-project?rev=312451&view=rev
Log:
[ScopHelper] Do not crash on unreachable blocks

This resolves llvm.org/PR34433. Thanks to Zhendong Su for reporting.

Added:
    polly/trunk/test/ScopDetect/error-block-unreachable.ll
Modified:
    polly/trunk/lib/Support/ScopHelper.cpp

Modified: polly/trunk/lib/Support/ScopHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/ScopHelper.cpp?rev=312451&r1=312450&r2=312451&view=diff
==============================================================================
--- polly/trunk/lib/Support/ScopHelper.cpp (original)
+++ polly/trunk/lib/Support/ScopHelper.cpp Sun Sep  3 11:01:22 2017
@@ -406,7 +406,15 @@ bool polly::isErrorBlock(BasicBlock &BB,
   //        not post dominated by the load and check if it is a conditional
   //        or a loop header.
   auto *DTNode = DT.getNode(&BB);
-  auto *IDomBB = DTNode->getIDom()->getBlock();
+  if (!DTNode)
+    return false;
+
+  DTNode = DTNode->getIDom();
+
+  if (!DTNode)
+    return false;
+
+  auto *IDomBB = DTNode->getBlock();
   if (LI.isLoopHeader(IDomBB))
     return false;
 

Added: polly/trunk/test/ScopDetect/error-block-unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/error-block-unreachable.ll?rev=312451&view=auto
==============================================================================
--- polly/trunk/test/ScopDetect/error-block-unreachable.ll (added)
+++ polly/trunk/test/ScopDetect/error-block-unreachable.ll Sun Sep  3 11:01:22 2017
@@ -0,0 +1,36 @@
+; RUN: opt %loadPolly -polly-detect -analyze < %s
+
+; Verify that the scop detection does not crash on inputs with unreachable
+; blocks. Earlier we crashed when detecting error blocks.
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+; Function Attrs: nounwind uwtable
+define void @foo() {
+entry:
+  br label %while.cond
+
+while.cond:                                       ; preds = %for.end, %entry
+  br i1 false, label %for.end, label %while.end8
+
+while.cond1:                                      ; preds = %while.cond4
+  br i1 undef, label %while.body3, label %for.inc
+
+while.body3:                                      ; preds = %while.cond1
+  br label %while.cond4
+
+while.cond4:                                      ; preds = %while.cond4, %while.body3
+  br i1 undef, label %while.cond4, label %while.cond1
+
+for.inc:                                          ; preds = %while.cond1
+  %conv = zext i16 undef to i32
+  br label %for.end
+
+for.end:                                          ; preds = %for.inc, %while.cond
+  %conv.sink = phi i32 [ %conv, %for.inc ], [ 0, %while.cond ]
+  br label %while.cond
+
+while.end8:                                       ; preds = %while.cond
+  ret void
+}




More information about the llvm-commits mailing list