-
Notifications
You must be signed in to change notification settings - Fork 15k
[ARM] Verify that disassembled instruction is correct #157360
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
|
@llvm/pr-subscribers-backend-arm Author: Sergei Barannikov (s-barannikov) ChangesRFE instructions have only one operand, but the decoder was adding two. Full diff: https://github.com/llvm/llvm-project/pull/157360.diff 2 Files Affected:
diff --git a/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp b/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
index 41d554f2cece9..4c92490206d93 100644
--- a/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
+++ b/llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
@@ -1365,24 +1365,6 @@ static DecodeStatus DecodeRFEInstruction(MCInst &Inst, unsigned Insn,
DecodeStatus S = MCDisassembler::Success;
unsigned Rn = fieldFromInstruction(Insn, 16, 4);
- unsigned mode = fieldFromInstruction(Insn, 23, 2);
-
- switch (mode) {
- case 0:
- mode = ARM_AM::da;
- break;
- case 1:
- mode = ARM_AM::ia;
- break;
- case 2:
- mode = ARM_AM::db;
- break;
- case 3:
- mode = ARM_AM::ib;
- break;
- }
-
- Inst.addOperand(MCOperand::createImm(mode));
if (!Check(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)))
return MCDisassembler::Fail;
diff --git a/llvm/test/MC/Disassembler/ARM/arm-tests.txt b/llvm/test/MC/Disassembler/ARM/arm-tests.txt
index 008bb1154e57f..a1016cdb5c8cc 100644
--- a/llvm/test/MC/Disassembler/ARM/arm-tests.txt
+++ b/llvm/test/MC/Disassembler/ARM/arm-tests.txt
@@ -354,7 +354,7 @@
# CHECK: strheq r0, [r0, -r0]
0xb0 0x00 0x00 0x01
-# CHECK: rfedb #4!
+# CHECK: rfedb r2!
0x14 0x0 0x32 0xf9
# CHECK: stc2l p0, c0, [r2], #-96
|
21bbfcb to
3655b1e
Compare
3655b1e to
f8ea29f
Compare
| STI); | ||
| if (Result != MCDisassembler::Fail) { | ||
| Size = 4; | ||
| Check(Result, AddThumbPredicate(MI)); |
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'm not sure about this change.
AddThumbPredicate not only adds a predicate operand, but also advances IT/VPT block states.
We don't need to add the operand here (it is added by the generated decoder), but should we advance the states? Can these instructions appear in IT block?
Also, DecodePredicateOperand that adds the operand doesn't take into account IT state. Should it?
Note that we don't call this method for instructions in VFPV8 namespace above and v8Crypto/v8NEON below.
The tests magically pass, but that doesn't give me 100% confidence in this change.
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 think I've figure it out. I should call UpdateThumbVFPPredicate here instead.
Not sure about other tables I mentioned, but this should preserve the existing behavior for NEONDup.
| if (!MCID.isVariadic() && MI.getNumOperands() != MCID.getNumOperands()) { | ||
| reportFatalInternalError(MCII->getName(MI.getOpcode()) + ": expected " + | ||
| Twine(MCID.getNumOperands()) + " operands, got " + | ||
| Twine(MI.getNumOperands()) + "\n"); |
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.
Not sure if this should be a fatal error. Maybe report an error and continue? In case there are bugs not detected by tests.
|
gentle ping |
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 think this is OK. LGTM
|
Thanks |
|
I am investigating a failure when I compile a cortex-m33 target with ToT llvm: "tBcc: expected 3 operands, got 5" This change seems to be the root cause of the problem. Any help in investigating this will be highly appreciated @s-barannikov |
|
Sorry to hear that. but it looks like it can still add it if the branch is in an IT block. Is that the case? Are you disassembling a third-party binary or a just built one? If it is the latter, a source assembly snippet would be very helpful. |
|
Can you check if #156540 fixes the issue? patch link |
This was reported by a customer. I've shared a llvm-objdump binary with your fix with them to try and report back. |
We are not able to repro this failure anymore. I am not sure if this was a flake or not. We will keep an eye out for this failure and will try your patch if we can reproduce the failure again. Thanks for responding right away. |
This change adds basic
MCInstverification (checks the number of operands) and fixes detected bugs.RFE*instructions have only one operand, butDecodeRFEInstructionadded two.DecodeMVEModImmInstructionandDecodeMVEVCMPadded avpredoperand, but this is whatAddThumbPredicatenormally does. This resulted in an extravpredoperand.DecodeMVEVADCInstructionadded an extra immediate operand.getARMInstructionadded apredoperand to instructions that don't have one (viaDecodePredicateOperand).AddThumb1SBitappended an extra register operand to instructions that don't modify CPSR (such astBL).NEONDupnamespace havepredoperand that the generated code successfully decodes. The operand was added once again bygetARMInstruction/getThumbInstructionviaAddThumbPredicate.Functional changes extracted from #156540.