MC: formalise some assertions into proper errors

Now that clang can be used as an assembler via the IAS, invalid assembler inputs
would cause the assertions to trigger.  Although we cannot recover from the
errors here, nor provide caret diagnostics, attempt to handle them slightly more
gracefully by reporting a fatal error.

llvm-svn: 209387
This commit is contained in:
Saleem Abdulrasool 2014-05-22 02:18:10 +00:00
parent 0e6e7cf385
commit 6663f8f2c0
8 changed files with 61 additions and 8 deletions

View File

@ -65,6 +65,9 @@ public:
protected:
const MCSymbol *CurSymbol;
void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &STI) override;
private:
LLVM_ATTRIBUTE_NORETURN void FatalError(const Twine &Msg) const;
};
}

View File

@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringExtras.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmLayout.h"
@ -125,30 +126,39 @@ void MCWinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
assert((!Symbol->isInSection() ||
Symbol->getSection().getVariant() == MCSection::SV_COFF) &&
"Got non-COFF section in the COFF backend!");
assert(!CurSymbol && "starting new symbol definition in a symbol definition");
if (CurSymbol)
FatalError("starting a new symbol definition without completing the "
"previous one");
CurSymbol = Symbol;
}
void MCWinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
assert(CurSymbol && "StorageClass specified outside of symbol definition");
assert((StorageClass & ~0xFF) == 0 &&
"StorageClass must only have data in the first byte!");
if (!CurSymbol)
FatalError("storage class specified outside of symbol definition");
if (StorageClass & ~0xff)
FatalError(Twine("storage class value '") + itostr(StorageClass) +
"' out of range");
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*CurSymbol);
SD.modifyFlags(StorageClass << COFF::SF_ClassShift, COFF::SF_ClassMask);
}
void MCWinCOFFStreamer::EmitCOFFSymbolType(int Type) {
assert(CurSymbol && "SymbolType specified outside of a symbol definition");
assert((Type & ~0xFFFF) == 0 &&
"Type must only have data in the first 2 bytes");
if (!CurSymbol)
FatalError("symbol type specified outside of a symbol definition");
if (Type & ~0xffff)
FatalError(Twine("type value '") + itostr(Type) + "' out of range");
MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*CurSymbol);
SD.modifyFlags(Type << COFF::SF_TypeShift, COFF::SF_TypeMask);
}
void MCWinCOFFStreamer::EndCOFFSymbolDef() {
assert(CurSymbol && "ending symbol definition without beginning one");
if (!CurSymbol)
FatalError("ending symbol definition without starting one");
CurSymbol = nullptr;
}
@ -239,5 +249,10 @@ void MCWinCOFFStreamer::EmitWin64EHHandlerData() {
void MCWinCOFFStreamer::FinishImpl() {
MCObjectStreamer::FinishImpl();
}
LLVM_ATTRIBUTE_NORETURN
void MCWinCOFFStreamer::FatalError(const Twine &Msg) const {
getContext().FatalError(SMLoc(), Msg);
}
}

View File

@ -0,0 +1,6 @@
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
# REQUIRES: asserts
.def first
.def second

View File

@ -0,0 +1,5 @@
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
# REQUIRES: asserts
.endef

View File

@ -0,0 +1,7 @@
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
# REQUIRES: asserts
.def storage_class_range
.scl 1337
.endef

View File

@ -0,0 +1,5 @@
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
# REQUIRES: asserts
.scl 1337

View File

@ -0,0 +1,7 @@
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
# REQUIRES: asserts
.def invalid_type_range
.type 65536
.endef

View File

@ -0,0 +1,5 @@
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
# REQUIRES: asserts
.type 65536