summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-01-08 08:03:55 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-01-08 08:03:55 +0000
commit086fec23ec438976a69e7232816e9c9d59d5d41c (patch)
tree66b6db578f4a125c89e30fc067a235db0ea8dd75 /llvm
parent249edf3d22c4b46059e1495ee120671aa47e3abd (diff)
downloadbcm5719-llvm-086fec23ec438976a69e7232816e9c9d59d5d41c.tar.gz
bcm5719-llvm-086fec23ec438976a69e7232816e9c9d59d5d41c.zip
[WinEH] Update WinEHFuncInfo if StackColoring merges allocas
Windows EH keeping track of which frame index corresponds to a catchpad in order to inform the runtime where the catch parameter should be initialized. LLVM's optimizations are able to prove that the memory used by the catch parameter can be reused with another memory optimization, changing it's frame index. We need to keep WinEHFuncInfo up to date with respect to this or we will miscompile/assert. This fixes PR26069. llvm-svn: 257158
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/StackColoring.cpp7
-rw-r--r--llvm/lib/CodeGen/WinEHPrepare.cpp7
-rw-r--r--llvm/test/CodeGen/X86/catchpad-lifetime.ll53
3 files changed, 64 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 3541b33a844..d0c0cf77702 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -43,6 +43,7 @@
#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/CodeGen/SlotIndexes.h"
#include "llvm/CodeGen/StackProtector.h"
+#include "llvm/CodeGen/WinEHFuncInfo.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
@@ -570,6 +571,12 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
}
}
+ if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
+ for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
+ for (WinEHHandlerType &H : TBME.HandlerArray)
+ if (SlotRemap.count(H.CatchObj.FrameIndex))
+ H.CatchObj.FrameIndex = SlotRemap[H.CatchObj.FrameIndex];
+
DEBUG(dbgs()<<"Fixed "<<FixedMemOp<<" machine memory operands.\n");
DEBUG(dbgs()<<"Fixed "<<FixedDbg<<" debug locations.\n");
DEBUG(dbgs()<<"Fixed "<<FixedInstr<<" machine instructions.\n");
diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index f112b1bb3b9..886c5f6070c 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -144,10 +144,11 @@ static void addTryBlockMapEntry(WinEHFuncInfo &FuncInfo, int TryLow,
HT.TypeDescriptor = cast<GlobalVariable>(TypeInfo->stripPointerCasts());
HT.Adjectives = cast<ConstantInt>(CPI->getArgOperand(1))->getZExtValue();
HT.Handler = CPI->getParent();
- if (isa<ConstantPointerNull>(CPI->getArgOperand(2)))
- HT.CatchObj.Alloca = nullptr;
+ if (auto *AI =
+ dyn_cast<AllocaInst>(CPI->getArgOperand(2)->stripPointerCasts()))
+ HT.CatchObj.Alloca = AI;
else
- HT.CatchObj.Alloca = cast<AllocaInst>(CPI->getArgOperand(2));
+ HT.CatchObj.Alloca = nullptr;
TBME.HandlerArray.push_back(HT);
}
FuncInfo.TryBlockMap.push_back(TBME);
diff --git a/llvm/test/CodeGen/X86/catchpad-lifetime.ll b/llvm/test/CodeGen/X86/catchpad-lifetime.ll
new file mode 100644
index 00000000000..38fc981d2b7
--- /dev/null
+++ b/llvm/test/CodeGen/X86/catchpad-lifetime.ll
@@ -0,0 +1,53 @@
+; RUN: llc < %s | FileCheck %s
+
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "x86_64-pc-windows-msvc"
+
+declare void @throw()
+
+declare i32 @__CxxFrameHandler3(...)
+
+define void @test1() personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+ %alloca2 = alloca i8*, align 4
+ %alloca1 = alloca i8*, align 4
+ store volatile i8* null, i8** %alloca1
+ invoke void @throw()
+ to label %unreachable unwind label %catch.dispatch
+
+; CHECK-LABEL: test1:
+; CHECK: movq $0, -16(%rbp)
+; CHECK: callq throw
+
+catch.dispatch: ; preds = %entry
+ %cs = catchswitch within none [label %catch.pad] unwind to caller
+
+catch.pad: ; preds = %catch.dispatch
+ %cp = catchpad within %cs [i8* null, i32 0, i8** %alloca1]
+ store volatile i8* null, i8** %alloca1
+ %bc1 = bitcast i8** %alloca1 to i8*
+ call void @llvm.lifetime.end(i64 4, i8* nonnull %bc1)
+ %bc2 = bitcast i8** %alloca2 to i8*
+ call void @llvm.lifetime.start(i64 4, i8* %bc2)
+ store volatile i8* null, i8** %alloca1
+ unreachable
+
+; CHECK-LABEL: "?catch$2@?0?test1@4HA"
+; CHECK: movq $0, -16(%rbp)
+; CHECK: movq $0, -16(%rbp)
+; CHECK: ud2
+
+unreachable: ; preds = %entry
+ unreachable
+}
+
+; CHECK-LABEL: $cppxdata$test1:
+; CHECK: .long 32 # CatchObjOffset
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.start(i64, i8* nocapture) #0
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.end(i64, i8* nocapture) #0
+
+attributes #0 = { argmemonly nounwind }
OpenPOWER on IntegriCloud