llvm-6502/test/CodeGen/X86/dynamic-alloca-lifetime.ll
Pete Cooper 185a992dcf 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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220099 91177308-0d34-0410-b5e6-96231b3b80d8
2014-10-17 22:59:33 +00:00

44 lines
1.3 KiB
LLVM

; 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 }