[PATCH] D151285: [MC] Check if register is non-null before calling isSubRegisterEq (NFCI)

Sergei Barannikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 23 21:15:30 PDT 2023


barannikov88 created this revision.
barannikov88 added a reviewer: Amir.
Herald added subscribers: ayermolo, hiraditya.
Herald added a reviewer: rafauler.
Herald added a reviewer: maksfb.
Herald added a project: All.
barannikov88 requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

D151036 <https://reviews.llvm.org/D151036> adds an assertions that prohibits iterating over sub- and
super-registers of a null register. This is already the case when
iterating over register units of a null register, and worked by
accident for sub- and super-registers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151285

Files:
  bolt/lib/Core/MCPlusBuilder.cpp
  llvm/lib/MC/MCInstrDesc.cpp


Index: llvm/lib/MC/MCInstrDesc.cpp
===================================================================
--- llvm/lib/MC/MCInstrDesc.cpp
+++ llvm/lib/MC/MCInstrDesc.cpp
@@ -40,7 +40,7 @@
 bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
                                   const MCRegisterInfo &RI) const {
   for (int i = 0, e = NumDefs; i != e; ++i)
-    if (MI.getOperand(i).isReg() &&
+    if (MI.getOperand(i).isReg() && MI.getOperand(i).getReg() &&
         RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
       return true;
   if (variadicOpsAreDefs())
Index: bolt/lib/Core/MCPlusBuilder.cpp
===================================================================
--- bolt/lib/Core/MCPlusBuilder.cpp
+++ bolt/lib/Core/MCPlusBuilder.cpp
@@ -425,7 +425,7 @@
 bool MCPlusBuilder::hasUseOfPhysReg(const MCInst &MI, unsigned Reg) const {
   const MCInstrDesc &InstInfo = Info->get(MI.getOpcode());
   for (int I = InstInfo.NumDefs; I < InstInfo.NumOperands; ++I)
-    if (MI.getOperand(I).isReg() &&
+    if (MI.getOperand(I).isReg() && MI.getOperand(i).getReg() &&
         RegInfo->isSubRegisterEq(Reg, MI.getOperand(I).getReg()))
       return true;
   for (MCPhysReg ImplicitUse : InstInfo.implicit_uses()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151285.524992.patch
Type: text/x-patch
Size: 1230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230524/c59dad95/attachment.bin>


More information about the llvm-commits mailing list