Produce an error instead of a crash in an expr we cannot represent.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 28 Apr 2014 12:40:50 +0000 (12:40 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 28 Apr 2014 12:40:50 +0000 (12:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207414 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
test/MC/ELF/subtraction-error.s [new file with mode: 0644]

index e8b34d56f5b936108f74ce17060e583e30f1f584..12b5f595ca44c6285b11733f2c273a820fc5e05a 100644 (file)
@@ -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/test/MC/ELF/subtraction-error.s b/test/MC/ELF/subtraction-error.s
new file mode 100644 (file)
index 0000000..6b93d3a
--- /dev/null
@@ -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