@@ -621,21 +621,24 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF, const Module *M,
621621
622622bool SPIRVEmitNonSemanticDI::emitLineDI (MachineFunction &MF,
623623 LiveRepository &LR) const {
624+ bool IsModified = false ;
624625 for (auto &MBB : MF) {
625626 for (auto &MI : MBB) {
626627 if (MI.getDebugLoc ().get ()) {
627628 MachineIRBuilder MIRBuilder (MBB, MI);
628629 DebugLoc DL = MI.getDebugLoc ();
630+ assert (DL.getScope () && " DL.getScope() must exist and be DISubprogram" );
629631 const auto *File = cast<DISubprogram>(DL.getScope ())->getFile ();
630632 const size_t ScopeIdx = emitDebugSource (File, MIRBuilder, TM, LR);
631633 const size_t LineIdx = LR.push (DL.getLine (), MIRBuilder, TM);
632634 const size_t ColIdx = LR.push (DL.getCol (), MIRBuilder, TM);
633635 LR.push <DebugLine>({ScopeIdx, LineIdx, LineIdx, ColIdx, ColIdx},
634636 MIRBuilder, TM);
637+ IsModified = true ;
635638 }
636639 }
637640 }
638- return false ;
641+ return IsModified ;
639642}
640643
641644bool SPIRVEmitNonSemanticDI::runOnMachineFunction (MachineFunction &MF) {
@@ -653,9 +656,10 @@ bool SPIRVEmitNonSemanticDI::runOnMachineFunction(MachineFunction &MF) {
653656 const MachineModuleInfo &MMI =
654657 getAnalysis<MachineModuleInfoWrapperPass>().getMMI ();
655658 const Module *M = MMI.getModule ();
656- const NamedMDNode *DbgCu = M->getNamedMetadata (" llvm.dbg.cu" );
657- if (!DbgCu)
659+ if (!M || !M->getNamedMetadata (" llvm.dbg.cu" )) {
658660 IsDIInModule = false ;
661+ return false ;
662+ }
659663 IsFunctionModified = emitGlobalDI (MF, M, LR);
660664 }
661665 IsFunctionModified |= emitLineDI (MF, LR);
0 commit comments