[llvm] [GISel] Fix crash in GlobalISel utils method (PR #153334)

Victor Mustya via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 13 15:22:23 PDT 2025


================
@@ -467,7 +467,10 @@ std::optional<DefinitionAndSourceRegister>
 llvm::getDefSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI) {
   Register DefSrcReg = Reg;
   auto *DefMI = MRI.getVRegDef(Reg);
-  auto DstTy = MRI.getType(DefMI->getOperand(0).getReg());
+  auto &Opnd = DefMI->getOperand(0);
+  if (!Opnd.isReg())
+    return DefinitionAndSourceRegister{DefMI, DefSrcReg};
----------------
vmustya wrote:

There is the `def_begin(Register)` method, that can be used to get the MachineOperand. I've re-implemented the fix using this method: https://github.com/llvm/llvm-project/pull/153334/commits/15bc48bed6ae3ec482e3c655a1859bdda8440772

https://github.com/llvm/llvm-project/pull/153334


More information about the llvm-commits mailing list