[llvm] r340456 - [SafeStack] Handle unreachable code with safe stack coloring.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 22 14:38:58 PDT 2018


Author: efriedma
Date: Wed Aug 22 14:38:57 2018
New Revision: 340456

URL: http://llvm.org/viewvc/llvm-project?rev=340456&view=rev
Log:
[SafeStack] Handle unreachable code with safe stack coloring.

Instead of asserting that the function doesn't have any unreachable
code, just ignore it for the purpose of computing liveness.

Differential Revision: https://reviews.llvm.org/D51070


Added:
    llvm/trunk/test/Transforms/SafeStack/AArch64/unreachable.ll
Modified:
    llvm/trunk/lib/CodeGen/SafeStackColoring.cpp

Modified: llvm/trunk/lib/CodeGen/SafeStackColoring.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SafeStackColoring.cpp?rev=340456&r1=340455&r2=340456&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SafeStackColoring.cpp (original)
+++ llvm/trunk/lib/CodeGen/SafeStackColoring.cpp Wed Aug 22 14:38:57 2018
@@ -172,7 +172,9 @@ void StackColoring::calculateLocalLivene
       BitVector LocalLiveIn;
       for (auto *PredBB : predecessors(BB)) {
         LivenessMap::const_iterator I = BlockLiveness.find(PredBB);
-        assert(I != BlockLiveness.end() && "Predecessor not found");
+        // If a predecessor is unreachable, ignore it.
+        if (I == BlockLiveness.end())
+          continue;
         LocalLiveIn |= I->second.LiveOut;
       }
 

Added: llvm/trunk/test/Transforms/SafeStack/AArch64/unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SafeStack/AArch64/unreachable.ll?rev=340456&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SafeStack/AArch64/unreachable.ll (added)
+++ llvm/trunk/test/Transforms/SafeStack/AArch64/unreachable.ll Wed Aug 22 14:38:57 2018
@@ -0,0 +1,23 @@
+; RUN: opt -safe-stack -safe-stack-coloring -S -mtriple=aarch64-linux-android < %s -o - | FileCheck %s
+
+define void @foo() nounwind uwtable safestack {
+entry:
+; CHECK: %[[TP:.*]] = call i8* @llvm.thread.pointer()
+; CHECK: %[[SPA0:.*]] = getelementptr i8, i8* %[[TP]], i32 72
+; CHECK: %[[SPA:.*]] = bitcast i8* %[[SPA0]] to i8**
+; CHECK: %[[USP:.*]] = load i8*, i8** %[[SPA]]
+; CHECK: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
+; CHECK: store i8* %[[USST]], i8** %[[SPA]]
+
+  %a = alloca i8, align 8
+  br label %ret
+
+ret:
+  ret void
+
+dead:
+  call void @Capture(i8* %a)
+  br label %ret
+}
+
+declare void @Capture(i8*)




More information about the llvm-commits mailing list