[llvm] r289101 - Don't emit .seh_handler directives for any cleanup funclets

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 12:38:46 PST 2016


Author: rnk
Date: Thu Dec  8 14:38:46 2016
New Revision: 289101

URL: http://llvm.org/viewvc/llvm-project?rev=289101&view=rev
Log:
Don't emit .seh_handler directives for any cleanup funclets

We were falsely claiming that we had an LSDA for the relevant EH
personality before this change, which could lead to the EH machinery
interpreting random adjacent data as an LSDA.

Fixes PR31317

This change is safe because cleanups can't contain exception handlers
today. We do these things to maintain that invariant:
- C++ destructors are naturally out-of-line
- __finally blocks are outlined in clang
- LLVM's inliner will not inline EH constructs into cleanups

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
    llvm/trunk/test/CodeGen/X86/seh-catchpad.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp?rev=289101&r1=289100&r2=289101&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/WinException.cpp Thu Dec  8 14:38:46 2016
@@ -221,12 +221,12 @@ void WinException::beginFunclet(const Ma
     const MCSymbol *PersHandlerSym =
         TLOF.getCFIPersonalitySymbol(PerFn, Asm->TM, MMI);
 
-    // Classify the personality routine so that we may reason about it.
-    EHPersonality Per = classifyEHPersonality(PerFn);
-
-    // Do not emit a .seh_handler directive if it is a C++ cleanup funclet.
-    if (Per != EHPersonality::MSVC_CXX ||
-        !CurrentFuncletEntry->isCleanupFuncletEntry())
+    // Do not emit a .seh_handler directives for cleanup funclets.
+    // FIXME: This means cleanup funclets cannot handle exceptions. Given that
+    // Clang doesn't produce EH constructs inside cleanup funclets and LLVM's
+    // inliner doesn't allow inlining them, this isn't a major problem in
+    // practice.
+    if (!CurrentFuncletEntry->isCleanupFuncletEntry())
       Asm->OutStreamer->EmitWinEHHandler(PersHandlerSym, true, true);
   }
 }

Modified: llvm/trunk/test/CodeGen/X86/seh-catchpad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/seh-catchpad.ll?rev=289101&r1=289100&r2=289101&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/seh-catchpad.ll (original)
+++ llvm/trunk/test/CodeGen/X86/seh-catchpad.ll Thu Dec  8 14:38:46 2016
@@ -147,7 +147,7 @@ __except.ret:
 
 ; CHECK: "?dtor$[[finbb]]@?0?main at 4HA":
 ; CHECK: .seh_proc "?dtor$[[finbb]]@?0?main at 4HA"
-; CHECK:         .seh_handler __C_specific_handler, @unwind, @except
+; CHECK-NOT:         .seh_handler
 ; CHECK: .LBB1_[[finbb]]:                                # %ehcleanup
 ; CHECK:         movq    %rdx, 16(%rsp)
 ; CHECK:         pushq   %rbp




More information about the llvm-commits mailing list