Skip to content

Commit ee1d5f6

Browse files
committed
[MC] Check if register is non-null before calling isSubRegisterEq (NFCI)
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
1 parent 2517497 commit ee1d5f6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

bolt/lib/Core/MCPlusBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ bool MCPlusBuilder::hasDefOfPhysReg(const MCInst &MI, unsigned Reg) const {
425425
bool MCPlusBuilder::hasUseOfPhysReg(const MCInst &MI, unsigned Reg) const {
426426
const MCInstrDesc &InstInfo = Info->get(MI.getOpcode());
427427
for (int I = InstInfo.NumDefs; I < InstInfo.NumOperands; ++I)
428-
if (MI.getOperand(I).isReg() &&
428+
if (MI.getOperand(I).isReg() && MI.getOperand(I).getReg() &&
429429
RegInfo->isSubRegisterEq(Reg, MI.getOperand(I).getReg()))
430430
return true;
431431
for (MCPhysReg ImplicitUse : InstInfo.implicit_uses()) {

llvm/lib/MC/MCInstrDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
4040
bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
4141
const MCRegisterInfo &RI) const {
4242
for (int i = 0, e = NumDefs; i != e; ++i)
43-
if (MI.getOperand(i).isReg() &&
43+
if (MI.getOperand(i).isReg() && MI.getOperand(i).getReg() &&
4444
RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
4545
return true;
4646
if (variadicOpsAreDefs())

0 commit comments

Comments
 (0)