aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCAssembler.cpp
diff options
context:
space:
mode:
authorOliver Stannard <oliver.stannard@arm.com>2015-11-17 10:00:43 +0000
committerOliver Stannard <oliver.stannard@arm.com>2015-11-17 10:00:43 +0000
commit9be59af3abe0b3bbee54e46720a75c96723da6cb (patch)
treed7b87d3a7144c56e73294288efcbd24109e3426e /llvm/lib/MC/MCAssembler.cpp
parent07b43d39a8ef5be442210c5ca21c780c19db0683 (diff)
downloadllvm-9be59af3abe0b3bbee54e46720a75c96723da6cb.zip
llvm-9be59af3abe0b3bbee54e46720a75c96723da6cb.tar.gz
llvm-9be59af3abe0b3bbee54e46720a75c96723da6cb.tar.bz2
[Assembler] Make fatal assembler errors non-fatal
Currently, if the assembler encounters an error after parsing (such as an out-of-range fixup), it reports this as a fatal error, and so stops after the first error. However, for most of these there is an obvious way to recover after emitting the error, such as emitting the fixup with a value of zero. This means that we can report on all of the errors in a file, not just the first one. MCContext::reportError records the fact that an error was encountered, so we won't actually emit an object file with the incorrect contents. Differential Revision: http://reviews.llvm.org/D14717 llvm-svn: 253328
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r--llvm/lib/MC/MCAssembler.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index 06f65fc..9f3ab18 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -179,14 +179,19 @@ const MCSymbol *MCAsmLayout::getBaseSymbol(const MCSymbol &Symbol) const {
const MCExpr *Expr = Symbol.getVariableValue();
MCValue Value;
- if (!Expr->evaluateAsValue(Value, *this))
- llvm_unreachable("Invalid Expression");
+ if (!Expr->evaluateAsValue(Value, *this)) {
+ Assembler.getContext().reportError(
+ SMLoc(), "expression could not be evaluated");
+ return nullptr;
+ }
const MCSymbolRefExpr *RefB = Value.getSymB();
- if (RefB)
- Assembler.getContext().reportFatalError(
+ if (RefB) {
+ Assembler.getContext().reportError(
SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() +
"' could not be evaluated in a subtraction expression");
+ return nullptr;
+ }
const MCSymbolRefExpr *A = Value.getSymA();
if (!A)
@@ -196,9 +201,10 @@ const MCSymbol *MCAsmLayout::getBaseSymbol(const MCSymbol &Symbol) const {
const MCAssembler &Asm = getAssembler();
if (ASym.isCommon()) {
// FIXME: we should probably add a SMLoc to MCExpr.
- Asm.getContext().reportFatalError(SMLoc(),
- "Common symbol " + ASym.getName() +
- " cannot be used in assignment expr");
+ Asm.getContext().reportError(SMLoc(),
+ "Common symbol '" + ASym.getName() +
+ "' cannot be used in assignment expr");
+ return nullptr;
}
return &ASym;
@@ -436,8 +442,13 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
// probably merge the two into a single callback that tries to evaluate a
// fixup and records a relocation if one is needed.
const MCExpr *Expr = Fixup.getValue();
- if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup))
- getContext().reportFatalError(Fixup.getLoc(), "expected relocatable expression");
+ if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup)) {
+ getContext().reportError(Fixup.getLoc(), "expected relocatable expression");
+ // Claim to have completely evaluated the fixup, to prevent any further
+ // processing from being done.
+ Value = 0;
+ return true;
+ }
bool IsPCRel = Backend.getFixupKindInfo(
Fixup.getKind()).Flags & MCFixupKindInfo::FKF_IsPCRel;