From 55789b6ba93faf388296233cb97fe19f4852674e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 28 Apr 2014 12:40:50 +0000 Subject: [PATCH] Produce an error instead of a crash in an expr we cannot represent. llvm-svn: 207414 --- lib/MC/ELFObjectWriter.cpp | 7 ++++++- test/MC/ELF/subtraction-error.s | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/MC/ELF/subtraction-error.s diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index e8b34d56f5b..12b5f595ca4 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/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/test/MC/ELF/subtraction-error.s b/test/MC/ELF/subtraction-error.s new file mode 100644 index 00000000000..6b93d3aee5b --- /dev/null +++ b/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