From 1b86a3446fe136cc5e76f087f19c513971c12b83 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 16 Sep 2015 17:19:44 +0000 Subject: [PATCH] [WinEH] Skip state numbering when no EH pads are present Otherwise we'd try to emit the thunk that passes the LSDA to __CxxFrameHandler3. We don't emit the LSDA if there were no landingpads, so we'd end up with an assembler error when trying to write the COFF object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247820 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineModuleInfo.h | 9 +++------ lib/Target/X86/X86WinEHState.cpp | 14 ++++++++++++++ test/CodeGen/WinEH/wineh-statenumbering.ll | 8 ++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index e7574bffe3b..70a771ee368 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -252,6 +252,9 @@ public: bool callsUnwindInit() const { return CallsUnwindInit; } void setCallsUnwindInit(bool b) { CallsUnwindInit = b; } + bool hasEHFunclets() const { return HasEHFunclets; } + void setHasEHFunclets(bool V) { HasEHFunclets = V; } + bool usesVAFloatArgument() const { return UsesVAFloatArgument; } @@ -365,12 +368,6 @@ public: return LandingPads; } - bool hasEHFunclets() const { - return HasEHFunclets; - } - - void setHasEHFunclets(bool V) { HasEHFunclets = true; } - /// setCallSiteLandingPad - Map the landing pad's EH symbol to the call /// site indexes. void setCallSiteLandingPad(MCSymbol *Sym, ArrayRef Sites); diff --git a/lib/Target/X86/X86WinEHState.cpp b/lib/Target/X86/X86WinEHState.cpp index 38dc5db3430..d1206ec0ee0 100644 --- a/lib/Target/X86/X86WinEHState.cpp +++ b/lib/Target/X86/X86WinEHState.cpp @@ -167,6 +167,20 @@ bool WinEHStatePass::runOnFunction(Function &F) { if (!isMSVCEHPersonality(Personality)) return false; + // Skip this function if there are no EH pads and we aren't using IR-level + // outlining. + if (WinEHParentName.empty()) { + bool HasPads = false; + for (BasicBlock &BB : F) { + if (BB.isEHPad()) { + HasPads = true; + break; + } + } + if (!HasPads) + return false; + } + // Disable frame pointer elimination in this function. // FIXME: Do the nested handlers need to keep the parent ebp in ebp, or can we // use an arbitrary register? diff --git a/test/CodeGen/WinEH/wineh-statenumbering.ll b/test/CodeGen/WinEH/wineh-statenumbering.ll index fcbb8bd2fc3..b54843635ab 100644 --- a/test/CodeGen/WinEH/wineh-statenumbering.ll +++ b/test/CodeGen/WinEH/wineh-statenumbering.ll @@ -82,6 +82,14 @@ unreachable.for.entry: ; preds = %entry unreachable } +define i32 @nopads() #0 personality i32 (...)* @__CxxFrameHandler3 { + ret i32 0 +} + +; CHECK-LABEL: define i32 @nopads() +; CHECK-NEXT: ret i32 0 +; CHECK-NOT: __ehhandler$nopads + declare void @g(i32) #0 declare x86_stdcallcc void @_CxxThrowException(i8*, %eh.ThrowInfo*) -- 2.34.1