[llvm] r207414 - Produce an error instead of a crash in an expr we cannot represent.
Rafael Espindola
rafael.espindola at gmail.com
Mon Apr 28 05:40:51 PDT 2014
Author: rafael
Date: Mon Apr 28 07:40:50 2014
New Revision: 207414
URL: http://llvm.org/viewvc/llvm-project?rev=207414&view=rev
Log:
Produce an error instead of a crash in an expr we cannot represent.
Added:
llvm/trunk/test/MC/ELF/subtraction-error.s
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=207414&r1=207413&r2=207414&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Mon Apr 28 07:40:50 2014
@@ -606,7 +606,12 @@ static const MCSymbol *getBaseSymbol(con
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;
Added: llvm/trunk/test/MC/ELF/subtraction-error.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/subtraction-error.s?rev=207414&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/subtraction-error.s (added)
+++ llvm/trunk/test/MC/ELF/subtraction-error.s Mon Apr 28 07:40:50 2014
@@ -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
More information about the llvm-commits
mailing list