Skip to content

Commit f72b654

Browse files
authored
[MC][x86] Allow non-MCTargetExpr RHS when the LHS of a MCBinaryExpr is MCTargetExpr (#75693)
This fixes #73109. In instruction `addl %eax %rax`, because there is a missing comma in the middle of two registers, the asm parser will treat it as a binary expression. ``` %rax % rax --> register mod identifier ``` However, In `MCExpr::evaluateAsRelocatableImpl`, it only checks the left side of the expression. This patch ensures the right side will also be checked.
1 parent bbe6c81 commit f72b654

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
@@ -943,16 +943,17 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
943943
Addrs, InSet)) {
944944
// Check if both are Target Expressions, see if we can compare them.
945945
if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS())) {
946-
const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS());
947-
switch (ABE->getOpcode()) {
948-
case MCBinaryExpr::EQ:
949-
Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
950-
return true;
951-
case MCBinaryExpr::NE:
952-
Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
953-
return true;
954-
default:
955-
break;
946+
if (const MCTargetExpr *R = dyn_cast<MCTargetExpr>(ABE->getRHS())) {
947+
switch (ABE->getOpcode()) {
948+
case MCBinaryExpr::EQ:
949+
Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
950+
return true;
951+
case MCBinaryExpr::NE:
952+
Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
953+
return true;
954+
default:
955+
break;
956+
}
956957
}
957958
}
958959
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)