Skip to content

Commit fbe0cc2

Browse files
committed
[MC][x86] Allow non-MCTargetExpr RHS when the LHS of a MCBinaryExpr is MCTargetExpr
1 parent 4f1ddf7 commit fbe0cc2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

llvm/lib/MC/MCExpr.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -942,16 +942,17 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
942942
Addrs, InSet)) {
943943
// Check if both are Target Expressions, see if we can compare them.
944944
if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS())) {
945-
const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS());
946-
switch (ABE->getOpcode()) {
947-
case MCBinaryExpr::EQ:
948-
Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
949-
return true;
950-
case MCBinaryExpr::NE:
951-
Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
952-
return true;
953-
default:
954-
break;
945+
if (const MCTargetExpr *R = dyn_cast<MCTargetExpr>(ABE->getRHS())) {
946+
switch (ABE->getOpcode()) {
947+
case MCBinaryExpr::EQ:
948+
Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
949+
return true;
950+
case MCBinaryExpr::NE:
951+
Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
952+
return true;
953+
default:
954+
break;
955+
}
955956
}
956957
}
957958
return false;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: not llvm-mc -triple x86_64 %s -o /dev/null 2>&1 | FileCheck %s
2+
3+
var_xdata = %rcx
4+
5+
// This used to crash.
6+
.if var_xdata == 1
7+
.endif
8+
// CHECK: error: expected absolute expression

0 commit comments

Comments
 (0)