@@ -625,10 +625,13 @@ void CodeViewDebug::beginModule(Module *M) {
625625 if (Asm->hasDebugInfo ()) {
626626 Node = *M->debug_compile_units_begin ();
627627 } else {
628+ auto DebugCompileUnits = MMI->getModule ()->debug_compile_units ();
629+ if (DebugCompileUnits.empty ())
630+ return ;
631+
628632 // When emitting only compiler information, we may have only NoDebug CUs,
629633 // which would be skipped by debug_compile_units_begin.
630- NamedMDNode *CUs = MMI->getModule ()->getNamedMetadata (" llvm.dbg.cu" );
631- Node = *CUs->operands ().begin ();
634+ Node = *DebugCompileUnits.begin ();
632635 }
633636 const auto *CU = cast<DICompileUnit>(Node);
634637 DISourceLanguageName Lang = CU->getSourceLanguage ();
@@ -900,8 +903,11 @@ void CodeViewDebug::emitCompilerInformation() {
900903 OS.AddComment (" CPUType" );
901904 OS.emitInt16 (static_cast <uint64_t >(TheCPU));
902905
903- NamedMDNode *CUs = MMI->getModule ()->getNamedMetadata (" llvm.dbg.cu" );
904- const MDNode *Node = *CUs->operands ().begin ();
906+ auto CUs = MMI->getModule ()->debug_compile_units ();
907+ if (CUs.empty ())
908+ return ;
909+
910+ const MDNode *Node = *CUs.begin ();
905911 const auto *CU = cast<DICompileUnit>(Node);
906912
907913 StringRef CompilerVersion = CU->getProducer ();
@@ -948,8 +954,11 @@ void CodeViewDebug::emitBuildInfo() {
948954 // not clear if the compiler path should refer to the executable for the
949955 // frontend or the backend. Leave it blank for now.
950956 TypeIndex BuildInfoArgs[BuildInfoRecord::MaxArgs] = {};
951- NamedMDNode *CUs = MMI->getModule ()->getNamedMetadata (" llvm.dbg.cu" );
952- const MDNode *Node = *CUs->operands ().begin (); // FIXME: Multiple CUs.
957+ auto CUs = MMI->getModule ()->debug_compile_units ();
958+ if (CUs.empty ())
959+ return ;
960+
961+ const MDNode *Node = *CUs.begin (); // FIXME: Multiple CUs.
953962 const auto *CU = cast<DICompileUnit>(Node);
954963 const DIFile *MainSourceFile = CU->getFile ();
955964 BuildInfoArgs[BuildInfoRecord::CurrentDirectory] =
0 commit comments