[llvm] [Mips] Fix clang crashes when assembling invalid MIPS beql instructions with --arch=mips (PR #156413)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 1 23:47:58 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-mips
Author: None (yingopq)
<details>
<summary>Changes</summary>
>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
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";
``````````
</details>
https://github.com/llvm/llvm-project/pull/156413
More information about the llvm-commits
mailing list