diff --git a/test/MC/AsmParser/exprs-invalid.s b/test/MC/AsmParser/exprs-invalid.s new file mode 100644 index 00000000000..4accc39087c --- /dev/null +++ b/test/MC/AsmParser/exprs-invalid.s @@ -0,0 +1,8 @@ +// RUN: not llvm-mc -triple i386-unknown-unknown %s 2> %t +// RUN: FileCheck -input-file %t %s + + .text +a: + .data +// CHECK: expected relocatable expression + .long -(0 + a) diff --git a/tools/llvm-mc/AsmExpr.cpp b/tools/llvm-mc/AsmExpr.cpp index c3362e4268c..fbb0c53b1cf 100644 --- a/tools/llvm-mc/AsmExpr.cpp +++ b/tools/llvm-mc/AsmExpr.cpp @@ -81,7 +81,7 @@ bool AsmExpr::EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const { break; case AsmUnaryExpr::Minus: /// -(a - b + const) ==> (b - a - const) - if (Value.getSymA() && !Value.getSymA()) + if (Value.getSymA() && !Value.getSymB()) return false; Res = MCValue::get(Value.getSymB(), Value.getSymA(), -Value.getConstant());