From: Rafael Espindola Date: Mon, 28 Apr 2014 12:40:50 +0000 (+0000) Subject: Produce an error instead of a crash in an expr we cannot represent. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c074b096d5d338659cf24a029c77c4b3e4c1ddb0;p=oota-llvm.git Produce an error instead of a crash in an expr we cannot represent. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207414 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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