[llvm] r232471 - Replace a use of GetTempSymbol with createTempSymbol.

Rafael Espindola rafael.espindola at gmail.com
Tue Mar 17 05:54:04 PDT 2015


Author: rafael
Date: Tue Mar 17 07:54:04 2015
New Revision: 232471

URL: http://llvm.org/viewvc/llvm-project?rev=232471&view=rev
Log:
Replace a use of GetTempSymbol with createTempSymbol.

This is cleaner and avoids a crash in a corner case.

Added:
    llvm/trunk/test/CodeGen/X86/exception-label.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.h
    llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp?rev=232471&r1=232470&r2=232471&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/ARMException.cpp Tue Mar 17 07:54:04 2015
@@ -52,9 +52,9 @@ void ARMException::endModule() {
     Asm->OutStreamer.EmitCFISections(false, true);
 }
 
-/// beginFunction - Gather pre-function exception information. Assumes it's
-/// being emitted immediately after the function entry point.
 void ARMException::beginFunction(const MachineFunction *MF) {
+  DwarfCFIExceptionBase::beginFunction(MF);
+
   if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
     getTargetStreamer().emitFnStart();
   // See if we need call frame info.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp?rev=232471&r1=232470&r2=232471&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp Tue Mar 17 07:54:04 2015
@@ -87,9 +87,9 @@ void DwarfCFIException::endModule() {
   }
 }
 
-/// beginFunction - Gather pre-function exception information. Assumes it's
-/// being emitted immediately after the function entry point.
 void DwarfCFIException::beginFunction(const MachineFunction *MF) {
+  DwarfCFIExceptionBase::beginFunction(MF);
+
   shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
 
   // If any landing pads survive, we need an EH table.
@@ -133,9 +133,7 @@ void DwarfCFIException::beginFunction(co
   if (!shouldEmitLSDA)
     return;
 
-  Asm->OutStreamer.EmitCFILsda(Asm->GetTempSymbol("exception",
-                                                  Asm->getFunctionNumber()),
-                               LSDAEncoding);
+  Asm->OutStreamer.EmitCFILsda(getCurExceptionSym(), LSDAEncoding);
 }
 
 /// endFunction - Gather and emit post-function exception information.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp?rev=232471&r1=232470&r2=232471&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.cpp Tue Mar 17 07:54:04 2015
@@ -25,10 +25,22 @@
 
 using namespace llvm;
 
-EHStreamer::EHStreamer(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
+EHStreamer::EHStreamer(AsmPrinter *A)
+    : CurExceptionSym(nullptr), Asm(A), MMI(Asm->MMI) {}
 
 EHStreamer::~EHStreamer() {}
 
+MCSymbol *EHStreamer::getCurExceptionSym() {
+  if (!CurExceptionSym)
+    CurExceptionSym = Asm->OutContext.createTempSymbol(
+        "exception" + Twine(Asm->getFunctionNumber()));
+  return CurExceptionSym;
+}
+
+void EHStreamer::beginFunction(const MachineFunction *MF) {
+  CurExceptionSym = nullptr;
+}
+
 /// How many leading type ids two landing pads have in common.
 unsigned EHStreamer::sharedTypeIDs(const LandingPadInfo *L,
                                    const LandingPadInfo *R) {
@@ -436,8 +448,7 @@ void EHStreamer::emitExceptionTable() {
     Asm->OutContext.GetOrCreateSymbol(Twine("GCC_except_table")+
                                       Twine(Asm->getFunctionNumber()));
   Asm->OutStreamer.EmitLabel(GCCETSym);
-  Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("exception",
-                                                Asm->getFunctionNumber()));
+  Asm->OutStreamer.EmitLabel(getCurExceptionSym());
 
   if (IsSJLJ)
     Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("_LSDA_",

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.h?rev=232471&r1=232470&r2=232471&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/EHStreamer.h Tue Mar 17 07:54:04 2015
@@ -31,6 +31,8 @@ class SmallVectorImpl;
 
 /// Emits exception handling directives.
 class EHStreamer : public AsmPrinterHandler {
+  MCSymbol *CurExceptionSym;
+
 protected:
   /// Target of directive emission.
   AsmPrinter *Asm;
@@ -125,6 +127,9 @@ public:
   EHStreamer(AsmPrinter *A);
   virtual ~EHStreamer();
 
+  MCSymbol *getCurExceptionSym();
+  void beginFunction(const MachineFunction *MF) override;
+
   // Unused.
   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {}
   void beginInstruction(const MachineInstr *MI) override {}

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp?rev=232471&r1=232470&r2=232471&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/Win64Exception.cpp Tue Mar 17 07:54:04 2015
@@ -48,9 +48,9 @@ Win64Exception::~Win64Exception() {}
 void Win64Exception::endModule() {
 }
 
-/// beginFunction - Gather pre-function exception information. Assumes it's
-/// being emitted immediately after the function entry point.
 void Win64Exception::beginFunction(const MachineFunction *MF) {
+  EHStreamer::beginFunction(MF);
+
   shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
 
   // If any landing pads survive, we need an EH table.

Added: llvm/trunk/test/CodeGen/X86/exception-label.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/exception-label.ll?rev=232471&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/exception-label.ll (added)
+++ llvm/trunk/test/CodeGen/X86/exception-label.ll Tue Mar 17 07:54:04 2015
@@ -0,0 +1,23 @@
+; RUN: llc < %s -mtriple=x86_64-pc-linux | FileCheck %s
+
+; Test that we can handle .Lexception0 being defined. We used to crash.
+
+; CHECK: .cfi_lsda 3, [[LABEL:.*]]
+; CHECK: [[LABEL]]:
+; CHECK-NEXT: .byte   255                     # @LPStart Encoding = omit
+
+declare void @g()
+
+define void @f() {
+bb0:
+  call void asm ".Lexception0:", ""()
+  invoke void @g()
+          to label %bb2 unwind label %bb1
+bb1:
+  landingpad { i8*, i32 } personality i8* bitcast (void ()* @g to i8*)
+          catch i8* null
+  br label %bb2
+
+bb2:
+  ret void
+}





More information about the llvm-commits mailing list