-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MC][x86] Allow non-MCTargetExpr RHS when the LHS of a MCBinaryExpr is MCTargetExpr #75693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-mc Author: Chenyang Gao (cygao90) ChangesThis fixes #73109.
However, In Full diff: https://github.com/llvm/llvm-project/pull/75693.diff 1 Files Affected:
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;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a problem when built it locally:
$ echo 'setb %al %rbx' | llvm-mc --show-encoding
.text
setb (%al)%rbx # encoding: [0x0f,0x92,0x04,0x25,A,A,A,A]
# fixup A - offset: 4, value: (%al)%rbx, kind: reloc_signed_4byte
In this case, %rbx
is taken as a relocation, which is incorrect.
I think the cast
is intended here. What we should do is to make it user friendly by emitting an error with message. But it seems not easy to do here.
@phoebewang Thank you for your review. I tested on gcc. gcc will also accept such instruction:
|
I fixed I think this patch is correct but we need a test to A better subject line is probably |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, please address @MaskRay 's comments.
I don't know why this check failed... |
Check fail occurs sometimes for other reasons like infrastructure issue or problem in recent merged patches. You just need to take a look at the failed tests and ignore it if they are unrelated to your change. |
Seems unrelated. |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion
You don't need -unknown-unknown
, x86_64
is enough. Ony one check prefix is used, --check-prefix=CHECK-ERROR
is redundant.
Can someone with write access merge this PR if no further change is required? Thanks. |
…s and improve the test To actually address my review comment in #75693
We should add a test |
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.However, In
MCExpr::evaluateAsRelocatableImpl
, it only checks the left side of the expression. This patch ensures the right side will also be checked.