diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h index 195762e64b2..6f156b28447 100644 --- a/include/llvm/MC/MCExpr.h +++ b/include/llvm/MC/MCExpr.h @@ -204,7 +204,9 @@ private: const VariantKind Kind; explicit MCSymbolRefExpr(const MCSymbol *_Symbol, VariantKind _Kind) - : MCExpr(MCExpr::SymbolRef), Symbol(_Symbol), Kind(_Kind) {} + : MCExpr(MCExpr::SymbolRef), Symbol(_Symbol), Kind(_Kind) { + assert(Symbol); + } public: /// @name Construction diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h index 01d254a49c8..deed1cafb11 100644 --- a/include/llvm/MC/MCObjectStreamer.h +++ b/include/llvm/MC/MCObjectStreamer.h @@ -78,7 +78,7 @@ public: virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label); virtual void EmitGPRel32Value(const MCExpr *Value); - virtual void Finish(); + virtual void FinishImpl(); /// @} }; diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h index e550dfa3efa..e227c485fb1 100644 --- a/include/llvm/MC/MCStreamer.h +++ b/include/llvm/MC/MCStreamer.h @@ -590,8 +590,10 @@ namespace llvm { virtual void EmitRegSave(const SmallVectorImpl &RegList, bool isVector); + /// FinishImpl - Streamer specific finalization. + virtual void FinishImpl() = 0; /// Finish - Finish emission of machine code. - virtual void Finish() = 0; + void Finish(); }; /// createNullStreamer - Create a dummy machine code streamer, which does diff --git a/lib/MC/MCAsmStreamer.cpp b/lib/MC/MCAsmStreamer.cpp index 630a104b129..ca2f10ea7c7 100644 --- a/lib/MC/MCAsmStreamer.cpp +++ b/lib/MC/MCAsmStreamer.cpp @@ -255,7 +255,7 @@ public: /// indicated by the hasRawTextSupport() predicate. virtual void EmitRawText(StringRef String); - virtual void Finish(); + virtual void FinishImpl(); /// @} }; @@ -1285,7 +1285,7 @@ void MCAsmStreamer::EmitRawText(StringRef String) { EmitEOL(); } -void MCAsmStreamer::Finish() { +void MCAsmStreamer::FinishImpl() { // Dump out the dwarf file & directory tables and line tables. if (getContext().hasDwarfFiles() && !UseLoc) MCDwarfFileTable::Emit(this); diff --git a/lib/MC/MCELFStreamer.cpp b/lib/MC/MCELFStreamer.cpp index dcc4666a266..aaae21f68ba 100644 --- a/lib/MC/MCELFStreamer.cpp +++ b/lib/MC/MCELFStreamer.cpp @@ -356,7 +356,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) { DF->getContents().append(Code.begin(), Code.end()); } -void MCELFStreamer::Finish() { +void MCELFStreamer::FinishImpl() { EmitFrames(true); for (std::vector::const_iterator i = LocalCommons.begin(), @@ -379,7 +379,7 @@ void MCELFStreamer::Finish() { SectData.setAlignment(ByteAlignment); } - this->MCObjectStreamer::Finish(); + this->MCObjectStreamer::FinishImpl(); } MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, diff --git a/lib/MC/MCELFStreamer.h b/lib/MC/MCELFStreamer.h index 10bf7758099..e28a88461e3 100644 --- a/lib/MC/MCELFStreamer.h +++ b/lib/MC/MCELFStreamer.h @@ -94,7 +94,7 @@ public: virtual void EmitFileDirective(StringRef Filename); - virtual void Finish(); + virtual void FinishImpl(); private: virtual void EmitInstToFragment(const MCInst &Inst); diff --git a/lib/MC/MCLoggingStreamer.cpp b/lib/MC/MCLoggingStreamer.cpp index d59b6d7acaf..18a9a94412a 100644 --- a/lib/MC/MCLoggingStreamer.cpp +++ b/lib/MC/MCLoggingStreamer.cpp @@ -243,9 +243,9 @@ public: return Child->EmitRawText(String); } - virtual void Finish() { - LogCall("Finish"); - return Child->Finish(); + virtual void FinishImpl() { + LogCall("FinishImpl"); + return Child->FinishImpl(); } }; diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp index 50ab1f86443..af0f160d464 100644 --- a/lib/MC/MCMachOStreamer.cpp +++ b/lib/MC/MCMachOStreamer.cpp @@ -89,7 +89,7 @@ public: //report_fatal_error("unsupported directive: '.file'"); } - virtual void Finish(); + virtual void FinishImpl(); /// @} }; @@ -375,7 +375,7 @@ void MCMachOStreamer::EmitInstToData(const MCInst &Inst) { DF->getContents().append(Code.begin(), Code.end()); } -void MCMachOStreamer::Finish() { +void MCMachOStreamer::FinishImpl() { EmitFrames(true); // We have to set the fragment atom associations so we can relax properly for @@ -407,7 +407,7 @@ void MCMachOStreamer::Finish() { } } - this->MCObjectStreamer::Finish(); + this->MCObjectStreamer::FinishImpl(); } MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCAsmBackend &MAB, diff --git a/lib/MC/MCNullStreamer.cpp b/lib/MC/MCNullStreamer.cpp index ca74663693d..432974f8d77 100644 --- a/lib/MC/MCNullStreamer.cpp +++ b/lib/MC/MCNullStreamer.cpp @@ -94,7 +94,7 @@ namespace { StringRef FileName) {} virtual void EmitInstruction(const MCInst &Inst) {} - virtual void Finish() {} + virtual void FinishImpl() {} /// @} }; diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp index 663d0ca4911..76c853c3a8d 100644 --- a/lib/MC/MCObjectStreamer.cpp +++ b/lib/MC/MCObjectStreamer.cpp @@ -255,7 +255,7 @@ void MCObjectStreamer::EmitGPRel32Value(const MCExpr *Value) { DF->getContents().resize(DF->getContents().size() + 4, 0); } -void MCObjectStreamer::Finish() { +void MCObjectStreamer::FinishImpl() { // Dump out the dwarf file & directory tables and line tables. if (getContext().hasDwarfFiles()) MCDwarfFileTable::Emit(this); diff --git a/lib/MC/MCPureStreamer.cpp b/lib/MC/MCPureStreamer.cpp index 1a2a92e3293..20a3bdb0144 100644 --- a/lib/MC/MCPureStreamer.cpp +++ b/lib/MC/MCPureStreamer.cpp @@ -48,7 +48,7 @@ public: unsigned MaxBytesToEmit = 0); virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value = 0); - virtual void Finish(); + virtual void FinishImpl(); virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { @@ -224,10 +224,10 @@ void MCPureStreamer::EmitInstToData(const MCInst &Inst) { DF->getContents().append(Code.begin(), Code.end()); } -void MCPureStreamer::Finish() { +void MCPureStreamer::FinishImpl() { // FIXME: Handle DWARF tables? - this->MCObjectStreamer::Finish(); + this->MCObjectStreamer::FinishImpl(); } MCStreamer *llvm::createPureStreamer(MCContext &Context, MCAsmBackend &MAB, diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index 8567941c45a..ce9de9d4c51 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -652,3 +652,10 @@ void MCStreamer::EmitW64Tables() { MCWin64EHUnwindEmitter::Emit(*this); } + +void MCStreamer::Finish() { + if (!FrameInfos.empty() && !FrameInfos.back().End) + report_fatal_error("Unfinished frame!"); + + FinishImpl(); +} diff --git a/lib/MC/WinCOFFStreamer.cpp b/lib/MC/WinCOFFStreamer.cpp index f2fecae79c8..265f0daef0f 100644 --- a/lib/MC/WinCOFFStreamer.cpp +++ b/lib/MC/WinCOFFStreamer.cpp @@ -79,7 +79,7 @@ public: virtual void EmitFileDirective(StringRef Filename); virtual void EmitInstruction(const MCInst &Instruction); virtual void EmitWin64EHHandlerData(); - virtual void Finish(); + virtual void FinishImpl(); private: virtual void EmitInstToFragment(const MCInst &Inst) { @@ -401,9 +401,9 @@ void WinCOFFStreamer::EmitWin64EHHandlerData() { MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo()); } -void WinCOFFStreamer::Finish() { +void WinCOFFStreamer::FinishImpl() { EmitW64Tables(); - MCObjectStreamer::Finish(); + MCObjectStreamer::FinishImpl(); } namespace llvm diff --git a/lib/Target/PTX/PTXMCAsmStreamer.cpp b/lib/Target/PTX/PTXMCAsmStreamer.cpp index bc7aaa3e41d..270ed2d29fd 100644 --- a/lib/Target/PTX/PTXMCAsmStreamer.cpp +++ b/lib/Target/PTX/PTXMCAsmStreamer.cpp @@ -176,7 +176,7 @@ public: /// indicated by the hasRawTextSupport() predicate. virtual void EmitRawText(StringRef String); - virtual void Finish(); + virtual void FinishImpl(); /// @} @@ -540,7 +540,7 @@ void PTXMCAsmStreamer::EmitRawText(StringRef String) { EmitEOL(); } -void PTXMCAsmStreamer::Finish() {} +void PTXMCAsmStreamer::FinishImpl() {} namespace llvm { MCStreamer *createPTXAsmStreamer(MCContext &Context, diff --git a/test/MC/AsmParser/cfi-unfinished-frame.s b/test/MC/AsmParser/cfi-unfinished-frame.s new file mode 100644 index 00000000000..1182d52baed --- /dev/null +++ b/test/MC/AsmParser/cfi-unfinished-frame.s @@ -0,0 +1,5 @@ +// RUN: not llvm-mc -filetype=asm -triple x86_64-pc-linux-gnu %s -o %t 2>%t.out +// RUN: FileCheck -input-file=%t.out %s + +.cfi_startproc +// CHECK: Unfinished frame diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 0b737293ae2..2b89e6240c9 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -603,7 +603,7 @@ namespace { if (Inst.getOperand(i).isExpr()) AddValueSymbols(Inst.getOperand(i).getExpr()); } - virtual void Finish() {} + virtual void FinishImpl() {} }; }