[llvm] [MC][x86] Allow non-MCTargetExpr RHS when the LHS of a MCBinaryExpr is MCTargetExpr (PR #75693)
Chenyang Gao via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 17 00:24:48 PST 2023
https://github.com/cygao90 updated https://github.com/llvm/llvm-project/pull/75693
>From 5c05add3033c9737d8597b51b4dee4e886c65126 Mon Sep 17 00:00:00 2001
From: Chenyang Gao <cygao09 at gmail.com>
Date: Sat, 16 Dec 2023 15:35:27 +0800
Subject: [PATCH] [MC][x86] Allow non-MCTargetExpr RHS when the LHS of a
MCBinaryExpr is MCTargetExpr
---
llvm/lib/MC/MCExpr.cpp | 21 ++++++++++----------
llvm/test/MC/X86/register-assignment-error.s | 8 ++++++++
2 files changed, 19 insertions(+), 10 deletions(-)
create mode 100644 llvm/test/MC/X86/register-assignment-error.s
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp
index 73e6569f96e463..4bed3d2d7a1c94 100644
--- a/llvm/lib/MC/MCExpr.cpp
+++ b/llvm/lib/MC/MCExpr.cpp
@@ -942,16 +942,17 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
Addrs, InSet)) {
// Check if both are Target Expressions, see if we can compare them.
if (const MCTargetExpr *L = dyn_cast<MCTargetExpr>(ABE->getLHS())) {
- const MCTargetExpr *R = cast<MCTargetExpr>(ABE->getRHS());
- switch (ABE->getOpcode()) {
- case MCBinaryExpr::EQ:
- Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
- return true;
- case MCBinaryExpr::NE:
- Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
- return true;
- default:
- break;
+ if (const MCTargetExpr *R = dyn_cast<MCTargetExpr>(ABE->getRHS())) {
+ switch (ABE->getOpcode()) {
+ case MCBinaryExpr::EQ:
+ Res = MCValue::get(L->isEqualTo(R) ? -1 : 0);
+ return true;
+ case MCBinaryExpr::NE:
+ Res = MCValue::get(L->isEqualTo(R) ? 0 : -1);
+ return true;
+ default:
+ break;
+ }
}
}
return false;
diff --git a/llvm/test/MC/X86/register-assignment-error.s b/llvm/test/MC/X86/register-assignment-error.s
new file mode 100644
index 00000000000000..0c4265fdc1d4b7
--- /dev/null
+++ b/llvm/test/MC/X86/register-assignment-error.s
@@ -0,0 +1,8 @@
+// RUN: not llvm-mc -triple x86_64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
+
+var_xdata = %rcx
+
+// This used to crash.
+.if var_xdata == 1
+.endif
+// CHECK-ERROR: error: expected absolute expression
\ No newline at end of file
More information about the llvm-commits
mailing list