From 4d3df5433622fb19e3cafaa58bf16e6b2f438a7e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 17 Mar 2015 12:54:04 +0000 Subject: [PATCH] Replace a use of GetTempSymbol with createTempSymbol. This is cleaner and avoids a crash in a corner case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232471 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/ARMException.cpp | 4 ++-- lib/CodeGen/AsmPrinter/DwarfCFIException.cpp | 8 +++---- lib/CodeGen/AsmPrinter/EHStreamer.cpp | 17 ++++++++++++--- lib/CodeGen/AsmPrinter/EHStreamer.h | 5 +++++ lib/CodeGen/AsmPrinter/Win64Exception.cpp | 4 ++-- test/CodeGen/X86/exception-label.ll | 23 ++++++++++++++++++++ 6 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 test/CodeGen/X86/exception-label.ll diff --git a/lib/CodeGen/AsmPrinter/ARMException.cpp b/lib/CodeGen/AsmPrinter/ARMException.cpp index 3cde13e3fad..034e34a9573 100644 --- a/lib/CodeGen/AsmPrinter/ARMException.cpp +++ b/lib/CodeGen/AsmPrinter/ARMException.cpp @@ -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. diff --git a/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp index 0631592c080..5263a2afd0f 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp @@ -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(const MachineFunction *MF) { 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. diff --git a/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/lib/CodeGen/AsmPrinter/EHStreamer.cpp index b428c4ee4fb..8a040d92aee 100644 --- a/lib/CodeGen/AsmPrinter/EHStreamer.cpp +++ b/lib/CodeGen/AsmPrinter/EHStreamer.cpp @@ -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_", diff --git a/lib/CodeGen/AsmPrinter/EHStreamer.h b/lib/CodeGen/AsmPrinter/EHStreamer.h index 94d0585347e..8cb7a31a1ad 100644 --- a/lib/CodeGen/AsmPrinter/EHStreamer.h +++ b/lib/CodeGen/AsmPrinter/EHStreamer.h @@ -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 {} diff --git a/lib/CodeGen/AsmPrinter/Win64Exception.cpp b/lib/CodeGen/AsmPrinter/Win64Exception.cpp index 356a35135d1..abf16f79a42 100644 --- a/lib/CodeGen/AsmPrinter/Win64Exception.cpp +++ b/lib/CodeGen/AsmPrinter/Win64Exception.cpp @@ -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. diff --git a/test/CodeGen/X86/exception-label.ll b/test/CodeGen/X86/exception-label.ll new file mode 100644 index 00000000000..cafa1e630b9 --- /dev/null +++ b/test/CodeGen/X86/exception-label.ll @@ -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 +} -- 2.40.0