Skip to content

Commit

Permalink
[MC] Check if register is non-null before calling isSubRegisterEq (NFCI)
Browse files Browse the repository at this point in the history
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.

Reviewed By: Amir

Differential Revision: https://reviews.llvm.org/D151285
  • Loading branch information
s-barannikov committed May 25, 2023
1 parent 2517497 commit ee1d5f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bolt/lib/Core/MCPlusBuilder.cpp
Expand Up @@ -425,7 +425,7 @@ bool MCPlusBuilder::hasDefOfPhysReg(const MCInst &MI, unsigned Reg) const {
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()) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCInstrDesc.cpp
Expand Up @@ -40,7 +40,7 @@ bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
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())
Expand Down

0 comments on commit ee1d5f6

Please sign in to comment.