Skip to content

Commit 99fb65f

Browse files
authored
[NFC]Add assert to avoid possibly deref nullptr (llvm#65564)
These 2 functions could be called by AsmPrinter::doInitialization in AsmPrinter.cpp. doInitialization init MMI in the beginning`MMI = MMIWP ? &MMIWP->getMMI() : nullptr;`, MMI has the possibility to be nullptr, which could make the later deref crash. I think in most time MMI could not be nullptr, but from the view of function implementation, it could be, so I'd like to add assert to it, if this could be a problem, then we could avoid crash.
1 parent 23f144e commit 99fb65f

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ void AsmPrinter::emitInlineAsm(const MachineInstr *MI) const {
400400
"Reserved registers on the clobber list may not be "
401401
"preserved across the asm statement, and clobbering them may "
402402
"lead to undefined behaviour.";
403+
assert(MMI && "MMI can not be nullptr!");
403404
MMI->getModule()->getContext().diagnose(DiagnosticInfoInlineAsm(
404405
LocCookie, Msg, DiagnosticSeverity::DS_Warning));
405406
MMI->getModule()->getContext().diagnose(

llvm/lib/Target/X86/X86AsmPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ void X86AsmPrinter::emitStartOfAsmFile(Module &M) {
769769
if (!TT.isArch32Bit() && !TT.isArch64Bit())
770770
llvm_unreachable("CFProtection used on invalid architecture!");
771771
MCSection *Cur = OutStreamer->getCurrentSectionOnly();
772+
assert(MMI && "MMI can not be nullptr!");
772773
MCSection *Nt = MMI->getContext().getELFSection(
773774
".note.gnu.property", ELF::SHT_NOTE, ELF::SHF_ALLOC);
774775
OutStreamer->switchSection(Nt);

0 commit comments

Comments
 (0)