[llvm] r304363 - [EH] Fix the LSDA that we emit for unknown EH personalities

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed May 31 15:18:50 PDT 2017


Author: rnk
Date: Wed May 31 17:18:49 2017
New Revision: 304363

URL: http://llvm.org/viewvc/llvm-project?rev=304363&view=rev
Log:
[EH] Fix the LSDA that we emit for unknown EH personalities

We should have a single call site entry with no landing pad. This
indicates that no EH action should be taken and the unwinder should
unwind to the next frame.

We currently don't recognize __gxx_personality_seh0 as a known
personality, so we forcibly emit a table, and that table was wrong. This
was filed as PR33220. Now we emit a correct table for that personality.
The next step is to recognize that we can completely skip the table for
this personality.

Added:
    llvm/trunk/test/CodeGen/X86/eh-unknown.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=304363&r1=304362&r2=304363&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed May 31 17:18:49 2017
@@ -949,6 +949,18 @@ void AsmPrinter::emitFrameAlloc(const Ma
                              MCConstantExpr::create(FrameOffset, OutContext));
 }
 
+static bool needFuncLabelsForEHOrDebugInfo(const MachineFunction &MF,
+                                           MachineModuleInfo *MMI) {
+  if (!MF.getLandingPads().empty() || MF.hasEHFunclets() || MMI->hasDebugInfo())
+    return true;
+
+  // We might emit an LSDA anyway if we have an EH personality.
+  const Constant *PerFn = MF.getFunction()->getPersonalityFn();
+  if (!PerFn)
+    return false;
+  return !isNoOpWithoutInvoke(classifyEHPersonality(PerFn));
+}
+
 /// EmitFunctionBody - This method emits the body and trailer for a
 /// function.
 void AsmPrinter::EmitFunctionBody() {
@@ -1076,8 +1088,8 @@ void AsmPrinter::EmitFunctionBody() {
   // Emit target-specific gunk after the function body.
   EmitFunctionBodyEnd();
 
-  if (!MF->getLandingPads().empty() || MMI->hasDebugInfo() ||
-      MF->hasEHFunclets() || MAI->hasDotTypeDotSizeDirective()) {
+  if (needFuncLabelsForEHOrDebugInfo(*MF, MMI) ||
+      MAI->hasDotTypeDotSizeDirective()) {
     // Create a symbol for the end of function.
     CurrentFnEnd = createTempSymbol("func_end");
     OutStreamer->EmitLabel(CurrentFnEnd);
@@ -1402,8 +1414,7 @@ void AsmPrinter::SetupMachineFunction(Ma
   CurrentFnBegin = nullptr;
   CurExceptionSym = nullptr;
   bool NeedsLocalForSize = MAI->needsLocalForSize();
-  if (!MF.getLandingPads().empty() || MMI->hasDebugInfo() ||
-      MF.hasEHFunclets() || NeedsLocalForSize) {
+  if (needFuncLabelsForEHOrDebugInfo(MF, MMI) || NeedsLocalForSize) {
     CurrentFnBegin = createTempSymbol("func_begin");
     if (NeedsLocalForSize)
       CurrentFnSymForSize = CurrentFnBegin;

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp?rev=304363&r1=304362&r2=304363&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp Wed May 31 17:18:49 2017
@@ -309,7 +309,7 @@ computeCallSiteTable(SmallVectorImpl<Cal
   // If some instruction between the previous try-range and the end of the
   // function may throw, create a call-site entry with no landing pad for the
   // region following the try-range.
-  if (SawPotentiallyThrowing && !IsSJLJ && LastLabel != nullptr) {
+  if (SawPotentiallyThrowing && !IsSJLJ) {
     CallSiteEntry Site = { LastLabel, nullptr, nullptr, 0 };
     CallSites.push_back(Site);
   }

Added: llvm/trunk/test/CodeGen/X86/eh-unknown.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/eh-unknown.ll?rev=304363&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/eh-unknown.ll (added)
+++ llvm/trunk/test/CodeGen/X86/eh-unknown.ll Wed May 31 17:18:49 2017
@@ -0,0 +1,32 @@
+; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s
+
+; An unknown personality forces us to emit an Itanium LSDA. Make sure that the
+; Itanium call site table actually tells the personality to keep unwinding,
+; i.e. we have an entry and it says "has no landing pad".
+
+declare void @throwit()
+declare void @__unknown_ehpersonality(...)
+
+define void @use_unknown_ehpersonality()
+    personality void (...)* @__unknown_ehpersonality {
+entry:
+  call void @throwit()
+  unreachable
+}
+
+; CHECK-LABEL: use_unknown_ehpersonality:
+; CHECK: .Lfunc_begin0:
+; CHECK: .seh_handler __unknown_ehpersonality, @unwind, @except
+; CHECK: callq throwit
+; CHECK: .Lfunc_end0:
+; CHECK: .seh_handlerdata
+; CHECK: .Lexception0:
+; CHECK:  .byte   255                     # @LPStart Encoding = omit
+; CHECK:  .byte   0                       # @TType Encoding = absptr
+; CHECK:  .asciz  "\217\200"              # @TType base offset
+; CHECK:  .byte   3                       # Call site Encoding = udata4
+; CHECK:  .byte   13                      # Call site table length
+; CHECK:  .long   .Lfunc_begin0-.Lfunc_begin0 # >> Call Site 1 <<
+; CHECK:  .long   .Lfunc_end0-.Lfunc_begin0 #   Call between .Lfunc_begin0 and .Lfunc_end0
+; CHECK:  .long   0                       #     has no landing pad
+; CHECK:  .byte   0                       #   On action: cleanup




More information about the llvm-commits mailing list