summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2016-09-16 22:04:10 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2016-09-16 22:04:10 +0000
commitaa84f050fcac97a66813fe446296c8f796e755f7 (patch)
tree748d41963cd33f4c9626148c494b067db72af445
parent318582f9f9ce8c24cf78d229fa2f3c958f2980a2 (diff)
downloadbcm5719-llvm-aa84f050fcac97a66813fe446296c8f796e755f7.tar.gz
bcm5719-llvm-aa84f050fcac97a66813fe446296c8f796e755f7.zip
[safestack] Fix assertion failure in stack coloring.
This is a fix for PR30318. Clang may generate IR where an alloca is already live when entering a BB with lifetime.start. In this case, conservatively extend the alloca lifetime all the way back to the block entry. llvm-svn: 281784
-rw-r--r--llvm/lib/CodeGen/SafeStackColoring.cpp10
-rw-r--r--llvm/test/Transforms/SafeStack/coloring2.ll39
2 files changed, 45 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SafeStackColoring.cpp b/llvm/lib/CodeGen/SafeStackColoring.cpp
index 795eb8d2719..7fbeaddb38e 100644
--- a/llvm/lib/CodeGen/SafeStackColoring.cpp
+++ b/llvm/lib/CodeGen/SafeStackColoring.cpp
@@ -214,10 +214,12 @@ void StackColoring::calculateLiveIntervals() {
unsigned AllocaNo = It.second.AllocaNo;
if (IsStart) {
- assert(!Started.test(AllocaNo));
- Started.set(AllocaNo);
- Ended.reset(AllocaNo);
- Start[AllocaNo] = InstNo;
+ assert(!Started.test(AllocaNo) || Start[AllocaNo] == BBStart);
+ if (!Started.test(AllocaNo)) {
+ Started.set(AllocaNo);
+ Ended.reset(AllocaNo);
+ Start[AllocaNo] = InstNo;
+ }
} else {
assert(!Ended.test(AllocaNo));
if (Started.test(AllocaNo)) {
diff --git a/llvm/test/Transforms/SafeStack/coloring2.ll b/llvm/test/Transforms/SafeStack/coloring2.ll
index 54ed812cfe2..f3ac6d735c9 100644
--- a/llvm/test/Transforms/SafeStack/coloring2.ll
+++ b/llvm/test/Transforms/SafeStack/coloring2.ll
@@ -474,6 +474,45 @@ entry:
ret i32 %z3
}
+define void @end_loop() safestack {
+; CHECK-LABEL: define void @end_loop()
+entry:
+; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
+; CHECK-NEXT: getelementptr i8, i8* %[[USP]], i32 -16
+ %x = alloca i8, align 4
+ call void @llvm.lifetime.start(i64 4, i8* %x) nounwind
+ br label %l2
+
+l2:
+ call void @capture8(i8* %x)
+ call void @llvm.lifetime.end(i64 4, i8* %x) nounwind
+ br label %l2
+}
+
+; Check that @x and @y get distinct stack slots => @x lifetime does not break
+; when control re-enters l2.
+define void @start_loop() safestack {
+; CHECK-LABEL: define void @start_loop()
+entry:
+; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
+; CHECK-NEXT: getelementptr i8, i8* %[[USP]], i32 -16
+ %x = alloca i8, align 4
+ %y = alloca i8, align 4
+ call void @llvm.lifetime.start(i64 4, i8* %x) nounwind
+ br label %l2
+
+l2:
+; CHECK: getelementptr i8, i8* %[[USP]], i32 -8
+ call void @llvm.lifetime.start(i64 4, i8* %y) nounwind
+ call void @capture8(i8* %y)
+ call void @llvm.lifetime.end(i64 4, i8* %y) nounwind
+
+; CHECK: getelementptr i8, i8* %[[USP]], i32 -4
+ call void @llvm.lifetime.start(i64 4, i8* %x) nounwind
+ call void @capture8(i8* %x)
+ br label %l2
+}
+
declare void @llvm.lifetime.start(i64, i8* nocapture)
declare void @llvm.lifetime.end(i64, i8* nocapture)
declare void @capture8(i8*)
OpenPOWER on IntegriCloud