summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp7
-rw-r--r--llvm/test/MC/ELF/subtraction-error.s8
2 files changed, 14 insertions, 1 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index e8b34d56f5b..12b5f595ca4 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -606,7 +606,12 @@ static const MCSymbol *getBaseSymbol(const MCAsmLayout &Layout,
MCValue Value;
if (!Expr->EvaluateAsRelocatable(Value, &Layout))
llvm_unreachable("Invalid Expression");
- assert(!Value.getSymB());
+ const MCSymbolRefExpr *RefB = Value.getSymB();
+ if (RefB) {
+ Layout.getAssembler().getContext().FatalError(
+ SMLoc(), Twine("symbol '") + RefB->getSymbol().getName() +
+ "' could not be evaluated in a subtraction expression");
+ }
const MCSymbolRefExpr *A = Value.getSymA();
if (!A)
return nullptr;
diff --git a/llvm/test/MC/ELF/subtraction-error.s b/llvm/test/MC/ELF/subtraction-error.s
new file mode 100644
index 00000000000..6b93d3aee5b
--- /dev/null
+++ b/llvm/test/MC/ELF/subtraction-error.s
@@ -0,0 +1,8 @@
+// RUN: not llvm-mc -filetype=obj -triple x86_64-pc-linux < %s 2>&1 | FileCheck %s
+
+a:
+ .section foo
+b:
+c = b - a
+
+; CHECK: symbol 'a' could not be evaluated in a subtraction expression
OpenPOWER on IntegriCloud