mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-13 22:58:50 +00:00
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:
parent
89e2a2b0bd
commit
d6d4c30745
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
6
test/MC/COFF/invalid-def.s
Normal file
6
test/MC/COFF/invalid-def.s
Normal file
@ -0,0 +1,6 @@
|
||||
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
|
||||
# REQUIRES: asserts
|
||||
|
||||
.def first
|
||||
.def second
|
||||
|
5
test/MC/COFF/invalid-endef.s
Normal file
5
test/MC/COFF/invalid-endef.s
Normal file
@ -0,0 +1,5 @@
|
||||
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
|
||||
# REQUIRES: asserts
|
||||
|
||||
.endef
|
||||
|
7
test/MC/COFF/invalid-scl-range.s
Normal file
7
test/MC/COFF/invalid-scl-range.s
Normal 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
|
||||
|
5
test/MC/COFF/invalid-scl.s
Normal file
5
test/MC/COFF/invalid-scl.s
Normal file
@ -0,0 +1,5 @@
|
||||
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
|
||||
# REQUIRES: asserts
|
||||
|
||||
.scl 1337
|
||||
|
7
test/MC/COFF/invalid-type-range.s
Normal file
7
test/MC/COFF/invalid-type-range.s
Normal 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
|
||||
|
5
test/MC/COFF/invalid-type.s
Normal file
5
test/MC/COFF/invalid-type.s
Normal file
@ -0,0 +1,5 @@
|
||||
# RUN: not llvm-mc -triple i686-windows -filetype obj -o /dev/null %s
|
||||
# REQUIRES: asserts
|
||||
|
||||
.type 65536
|
||||
|
Loading…
Reference in New Issue
Block a user