1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Split Finish into Finish and FinishImpl to have a common place to do end of

file error checking. Use that to error on an unfinished cfi_startproc.

The error is not nice, but is already better than a segmentation fault.

llvm-svn: 147717
This commit is contained in:
Rafael Espindola 2012-01-07 03:13:18 +00:00
parent 8af07ba749
commit 2d545fa143
16 changed files with 41 additions and 25 deletions

View File

@ -204,7 +204,9 @@ private:
const VariantKind Kind; const VariantKind Kind;
explicit MCSymbolRefExpr(const MCSymbol *_Symbol, 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: public:
/// @name Construction /// @name Construction

View File

@ -78,7 +78,7 @@ public:
virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, virtual void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
const MCSymbol *Label); const MCSymbol *Label);
virtual void EmitGPRel32Value(const MCExpr *Value); virtual void EmitGPRel32Value(const MCExpr *Value);
virtual void Finish(); virtual void FinishImpl();
/// @} /// @}
}; };

View File

@ -590,8 +590,10 @@ namespace llvm {
virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList, virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector); bool isVector);
/// FinishImpl - Streamer specific finalization.
virtual void FinishImpl() = 0;
/// Finish - Finish emission of machine code. /// Finish - Finish emission of machine code.
virtual void Finish() = 0; void Finish();
}; };
/// createNullStreamer - Create a dummy machine code streamer, which does /// createNullStreamer - Create a dummy machine code streamer, which does

View File

@ -255,7 +255,7 @@ public:
/// indicated by the hasRawTextSupport() predicate. /// indicated by the hasRawTextSupport() predicate.
virtual void EmitRawText(StringRef String); virtual void EmitRawText(StringRef String);
virtual void Finish(); virtual void FinishImpl();
/// @} /// @}
}; };
@ -1285,7 +1285,7 @@ void MCAsmStreamer::EmitRawText(StringRef String) {
EmitEOL(); EmitEOL();
} }
void MCAsmStreamer::Finish() { void MCAsmStreamer::FinishImpl() {
// Dump out the dwarf file & directory tables and line tables. // Dump out the dwarf file & directory tables and line tables.
if (getContext().hasDwarfFiles() && !UseLoc) if (getContext().hasDwarfFiles() && !UseLoc)
MCDwarfFileTable::Emit(this); MCDwarfFileTable::Emit(this);

View File

@ -356,7 +356,7 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
DF->getContents().append(Code.begin(), Code.end()); DF->getContents().append(Code.begin(), Code.end());
} }
void MCELFStreamer::Finish() { void MCELFStreamer::FinishImpl() {
EmitFrames(true); EmitFrames(true);
for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(), for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
@ -379,7 +379,7 @@ void MCELFStreamer::Finish() {
SectData.setAlignment(ByteAlignment); SectData.setAlignment(ByteAlignment);
} }
this->MCObjectStreamer::Finish(); this->MCObjectStreamer::FinishImpl();
} }
MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB, MCStreamer *llvm::createELFStreamer(MCContext &Context, MCAsmBackend &MAB,

View File

@ -94,7 +94,7 @@ public:
virtual void EmitFileDirective(StringRef Filename); virtual void EmitFileDirective(StringRef Filename);
virtual void Finish(); virtual void FinishImpl();
private: private:
virtual void EmitInstToFragment(const MCInst &Inst); virtual void EmitInstToFragment(const MCInst &Inst);

View File

@ -243,9 +243,9 @@ public:
return Child->EmitRawText(String); return Child->EmitRawText(String);
} }
virtual void Finish() { virtual void FinishImpl() {
LogCall("Finish"); LogCall("FinishImpl");
return Child->Finish(); return Child->FinishImpl();
} }
}; };

View File

@ -89,7 +89,7 @@ public:
//report_fatal_error("unsupported directive: '.file'"); //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()); DF->getContents().append(Code.begin(), Code.end());
} }
void MCMachOStreamer::Finish() { void MCMachOStreamer::FinishImpl() {
EmitFrames(true); EmitFrames(true);
// We have to set the fragment atom associations so we can relax properly for // 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, MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCAsmBackend &MAB,

View File

@ -94,7 +94,7 @@ namespace {
StringRef FileName) {} StringRef FileName) {}
virtual void EmitInstruction(const MCInst &Inst) {} virtual void EmitInstruction(const MCInst &Inst) {}
virtual void Finish() {} virtual void FinishImpl() {}
/// @} /// @}
}; };

View File

@ -255,7 +255,7 @@ void MCObjectStreamer::EmitGPRel32Value(const MCExpr *Value) {
DF->getContents().resize(DF->getContents().size() + 4, 0); DF->getContents().resize(DF->getContents().size() + 4, 0);
} }
void MCObjectStreamer::Finish() { void MCObjectStreamer::FinishImpl() {
// Dump out the dwarf file & directory tables and line tables. // Dump out the dwarf file & directory tables and line tables.
if (getContext().hasDwarfFiles()) if (getContext().hasDwarfFiles())
MCDwarfFileTable::Emit(this); MCDwarfFileTable::Emit(this);

View File

@ -48,7 +48,7 @@ public:
unsigned MaxBytesToEmit = 0); unsigned MaxBytesToEmit = 0);
virtual void EmitValueToOffset(const MCExpr *Offset, virtual void EmitValueToOffset(const MCExpr *Offset,
unsigned char Value = 0); unsigned char Value = 0);
virtual void Finish(); virtual void FinishImpl();
virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) { virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) {
@ -224,10 +224,10 @@ void MCPureStreamer::EmitInstToData(const MCInst &Inst) {
DF->getContents().append(Code.begin(), Code.end()); DF->getContents().append(Code.begin(), Code.end());
} }
void MCPureStreamer::Finish() { void MCPureStreamer::FinishImpl() {
// FIXME: Handle DWARF tables? // FIXME: Handle DWARF tables?
this->MCObjectStreamer::Finish(); this->MCObjectStreamer::FinishImpl();
} }
MCStreamer *llvm::createPureStreamer(MCContext &Context, MCAsmBackend &MAB, MCStreamer *llvm::createPureStreamer(MCContext &Context, MCAsmBackend &MAB,

View File

@ -652,3 +652,10 @@ void MCStreamer::EmitW64Tables() {
MCWin64EHUnwindEmitter::Emit(*this); MCWin64EHUnwindEmitter::Emit(*this);
} }
void MCStreamer::Finish() {
if (!FrameInfos.empty() && !FrameInfos.back().End)
report_fatal_error("Unfinished frame!");
FinishImpl();
}

View File

@ -79,7 +79,7 @@ public:
virtual void EmitFileDirective(StringRef Filename); virtual void EmitFileDirective(StringRef Filename);
virtual void EmitInstruction(const MCInst &Instruction); virtual void EmitInstruction(const MCInst &Instruction);
virtual void EmitWin64EHHandlerData(); virtual void EmitWin64EHHandlerData();
virtual void Finish(); virtual void FinishImpl();
private: private:
virtual void EmitInstToFragment(const MCInst &Inst) { virtual void EmitInstToFragment(const MCInst &Inst) {
@ -401,9 +401,9 @@ void WinCOFFStreamer::EmitWin64EHHandlerData() {
MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo()); MCWin64EHUnwindEmitter::EmitUnwindInfo(*this, getCurrentW64UnwindInfo());
} }
void WinCOFFStreamer::Finish() { void WinCOFFStreamer::FinishImpl() {
EmitW64Tables(); EmitW64Tables();
MCObjectStreamer::Finish(); MCObjectStreamer::FinishImpl();
} }
namespace llvm namespace llvm

View File

@ -176,7 +176,7 @@ public:
/// indicated by the hasRawTextSupport() predicate. /// indicated by the hasRawTextSupport() predicate.
virtual void EmitRawText(StringRef String); virtual void EmitRawText(StringRef String);
virtual void Finish(); virtual void FinishImpl();
/// @} /// @}
@ -540,7 +540,7 @@ void PTXMCAsmStreamer::EmitRawText(StringRef String) {
EmitEOL(); EmitEOL();
} }
void PTXMCAsmStreamer::Finish() {} void PTXMCAsmStreamer::FinishImpl() {}
namespace llvm { namespace llvm {
MCStreamer *createPTXAsmStreamer(MCContext &Context, MCStreamer *createPTXAsmStreamer(MCContext &Context,

View File

@ -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

View File

@ -603,7 +603,7 @@ namespace {
if (Inst.getOperand(i).isExpr()) if (Inst.getOperand(i).isExpr())
AddValueSymbols(Inst.getOperand(i).getExpr()); AddValueSymbols(Inst.getOperand(i).getExpr());
} }
virtual void Finish() {} virtual void FinishImpl() {}
}; };
} }