1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

Check for dynamic alloca's when selecting lifetime intrinsics.

TL;DR: Indexing maps with [] creates missing entries.

The long version:

When selecting lifetime intrinsics, we index the *static* alloca map with the AllocaInst we find for that lifetime.  Trouble is, we don't first check to see if this is a dynamic alloca.

On the attached example, this causes a dynamic alloca to create an entry in the static map, and returns 0 (the default) as the frame index for that lifetime.  0 was used for the frame index of the stack protector, which given that it now has a lifetime, is coloured, and merged with other stack slots.

PEI would later trigger an assert because it expects the stack protector to not be dead.

This fix ensures that we only get frame indices for static allocas, ie, those in the map.  Dynamic ones are effectively dropped, which is suboptimal, but at least isn't completely broken.

rdar://problem/18672951

llvm-svn: 220099
This commit is contained in:
Pete Cooper 2014-10-17 22:59:33 +00:00
parent 2a091228e8
commit bedb6f3c4b
2 changed files with 51 additions and 1 deletions

View File

@ -5396,7 +5396,13 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
if (!LifetimeObject)
continue;
int FI = FuncInfo.StaticAllocaMap[LifetimeObject];
// First check that the Alloca is static, otherwise it won't have a
// valid frame index.
auto SI = FuncInfo.StaticAllocaMap.find(LifetimeObject);
if (SI == FuncInfo.StaticAllocaMap.end())
return nullptr;
int FI = SI->second;
SDValue Ops[2];
Ops[0] = getRoot();

View File

@ -0,0 +1,44 @@
; RUN: llc -no-stack-coloring=false < %s | FileCheck %s
; This test crashed in PEI because the stack protector was dead.
; This was due to it being colored, which was in turn due to incorrect
; lifetimes being applied to the stack protector frame index.
; CHECK: stack_chk_guard
target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
target triple = "i386-apple-macosx10.10.0"
; Function Attrs: nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #0
; Function Attrs: nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #0
; Function Attrs: ssp
define void @foo(i1 %cond1, i1 %cond2) #1 {
entry:
%bitmapBuffer = alloca [8192 x i8], align 1
br i1 %cond1, label %end1, label %bb1
bb1:
%bitmapBuffer229 = alloca [8192 x i8], align 1
br i1 %cond2, label %end1, label %if.else130
end1:
ret void
if.else130: ; preds = %bb1
%tmp = getelementptr inbounds [8192 x i8]* %bitmapBuffer, i32 0, i32 0
call void @llvm.lifetime.start(i64 8192, i8* %tmp) #0
call void @llvm.lifetime.end(i64 8192, i8* %tmp) #0
%tmp25 = getelementptr inbounds [8192 x i8]* %bitmapBuffer229, i32 0, i32 0
call void @llvm.lifetime.start(i64 8192, i8* %tmp25) #0
call void @llvm.lifetime.end(i64 8192, i8* %tmp25) #0
br label %end1
}
declare void @bar()
attributes #0 = { nounwind }
attributes #1 = { ssp }