This is cleaner and avoids a crash in a corner case.
llvm-svn: 232471
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.
}
}
-/// 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.
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.
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) {
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_",
/// Emits exception handling directives.
class EHStreamer : public AsmPrinterHandler {
+ MCSymbol *CurExceptionSym;
+
protected:
/// Target of directive emission.
AsmPrinter *Asm;
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 {}
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.
--- /dev/null
+; 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
+}