Skip to content

Conversation

yingopq
Copy link
Contributor

@yingopq yingopq commented Sep 2, 2025

From clang version 4, mips append new instruction BeqImm and BEQLImmMacro, the second operand of instruction format is imm64:$imm. When Mips process beql $t0, ($t0), 1, it think the second operand was an imm, so match success. Then mips backend process expandBranchImm, check the Operand(1) was not imm, reported failure.
We can strengthen the instruction matching restrictions.

Fix #151453.

@llvmbot
Copy link
Member

llvmbot commented Sep 2, 2025

@llvm/pr-subscribers-backend-mips

Author: None (yingopq)

Changes

From clang version 4, mips append new instruction BeqImm and BEQLImmMacro, the second operand of instruction format is imm64:$imm. When Mips process beql $t0, ($t0), 1, it think the second operand was an imm, so match success. Then mips backend process expandBranchImm, check the Operand(1) was not imm, reported failure.
We can strengthen the instruction matching restrictions.

Fix #151453.


Full diff: https://github.com/llvm/llvm-project/pull/156413.diff

1 Files Affected:

  • (modified) llvm/lib/Target/Mips/MipsInstrInfo.td (+9-1)
diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.td b/llvm/lib/Target/Mips/MipsInstrInfo.td
index a124e84e9ca5f..0d6fa25fb8025 100644
--- a/llvm/lib/Target/Mips/MipsInstrInfo.td
+++ b/llvm/lib/Target/Mips/MipsInstrInfo.td
@@ -855,7 +855,15 @@ def calltarget  : Operand<iPTR> {
   let PrintMethod = "printJumpOperand";
 }
 
-def imm64: Operand<i64>;
+def ConstantImmAsmOperandClass : AsmOperandClass {
+  let Name = "ConstantImm";
+  let PredicateMethod = "isConstantImm";
+  let RenderMethod = "addImmOperands";
+}
+
+def imm64: Operand<i64> {
+  let ParserMatchClass = ConstantImmAsmOperandClass;
+}
 
 def simm19_lsl2 : Operand<i32> {
   let EncoderMethod = "getSimm19Lsl2Encoding";

…ns with --arch=mips

From clang version 4, mips append new instruction BeqImm and
BEQLImmMacro, the second operand of instruction format is imm64:$imm.
When Mips process `beql $t0, ($t0), 1`, it think the second operand
was an imm, so match success. Then mips backend process expandBranchImm,
check the Operand(1) was not imm, reported failure.
We can strengthen the instruction matching restrictions.

Fix llvm#151453.
@yingopq yingopq force-pushed the Fix_bug_issue_151453 branch from 3d53abf to 4cfe280 Compare September 2, 2025 08:36
@brad0
Copy link
Contributor

brad0 commented Sep 5, 2025

cc @topperc @s-barannikov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MC][MIPS]Clang Crashes When Assembling Invalid MIPS beql Instructions with --arch=mips
3 participants