diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -111,7 +111,8 @@ // Map all BB references in the WinEH data to MBBs. for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) { for (WinEHHandlerType &H : TBME.HandlerArray) { - if (const AllocaInst *AI = H.CatchObj.Alloca) + const AllocaInst *AI = H.CatchObj.Alloca; + if (AI && AI->isStaticAlloca()) CatchObjects.insert({AI, {}}).first->second.push_back( &H.CatchObj.FrameIndex); else diff --git a/llvm/test/CodeGen/X86/wineh-dyn-alloca.ll b/llvm/test/CodeGen/X86/wineh-dyn-alloca.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/wineh-dyn-alloca.ll @@ -0,0 +1,42 @@ +; RUN: llc -mtriple=x86_64-pc-windows-msvc19 -verify-machineinstrs < %s | FileCheck %s + +%struct.widget = type { ptr, ptr, [8 x i8] } + +@global = external global %struct.widget + +define dso_local void @hoist() local_unnamed_addr #0 personality ptr @__CxxFrameHandler3 { +bb: + br i1 poison, label %bb1, label %bb7 + +; CHECK:.Ltmp0: +; CHECK: subq $32, %rsp +; CHECK: callq snork +; CHECK: addq $32, %rsp +bb1: ; preds = %bb + %tmp = alloca i32, align 4 + invoke void @snork() + to label %bb6 unwind label %bb2 + +bb2: ; preds = %bb1 + %tmp3 = catchswitch within none [label %bb4] unwind label %bb8 + +bb4: ; preds = %bb2 + %tmp5 = catchpad within %tmp3 [ptr @global, i32 0, ptr %tmp] + unreachable + +bb6: ; preds = %bb1 + unreachable + +bb7: ; preds = %bb + ret void + +bb8: ; preds = %bb2 + %tmp9 = cleanuppad within none [] + unreachable +} + +declare dso_local i32 @__CxxFrameHandler3(...) #0 + +declare dso_local void @snork() local_unnamed_addr #0 + +attributes #0 = { nofree }