@@ -569,40 +569,30 @@ void CodeViewDebug::emitCodeViewMagicVersion() {
569569 OS.emitInt32 (COFF::DEBUG_SECTION_MAGIC);
570570}
571571
572- static SourceLanguage MapDWLangToCVLang (unsigned DWLang) {
573- switch (DWLang) {
574- case dwarf::DW_LANG_C:
575- case dwarf::DW_LANG_C89:
576- case dwarf::DW_LANG_C99:
577- case dwarf::DW_LANG_C11:
572+ static SourceLanguage
573+ MapDWARFLanguageToCVLang (dwarf::SourceLanguageName DWLName) {
574+ switch (DWLName) {
575+ case dwarf::DW_LNAME_C:
578576 return SourceLanguage::C;
579- case dwarf::DW_LANG_C_plus_plus:
580- case dwarf::DW_LANG_C_plus_plus_03:
581- case dwarf::DW_LANG_C_plus_plus_11:
582- case dwarf::DW_LANG_C_plus_plus_14:
577+ case dwarf::DW_LNAME_C_plus_plus:
583578 return SourceLanguage::Cpp;
584- case dwarf::DW_LANG_Fortran77:
585- case dwarf::DW_LANG_Fortran90:
586- case dwarf::DW_LANG_Fortran95:
587- case dwarf::DW_LANG_Fortran03:
588- case dwarf::DW_LANG_Fortran08:
579+ case dwarf::DW_LNAME_Fortran:
589580 return SourceLanguage::Fortran;
590- case dwarf::DW_LANG_Pascal83 :
581+ case dwarf::DW_LNAME_Pascal :
591582 return SourceLanguage::Pascal;
592- case dwarf::DW_LANG_Cobol74:
593- case dwarf::DW_LANG_Cobol85:
583+ case dwarf::DW_LNAME_Cobol:
594584 return SourceLanguage::Cobol;
595- case dwarf::DW_LANG_Java :
585+ case dwarf::DW_LNAME_Java :
596586 return SourceLanguage::Java;
597- case dwarf::DW_LANG_D :
587+ case dwarf::DW_LNAME_D :
598588 return SourceLanguage::D;
599- case dwarf::DW_LANG_Swift :
589+ case dwarf::DW_LNAME_Swift :
600590 return SourceLanguage::Swift;
601- case dwarf::DW_LANG_Rust :
591+ case dwarf::DW_LNAME_Rust :
602592 return SourceLanguage::Rust;
603- case dwarf::DW_LANG_ObjC :
593+ case dwarf::DW_LNAME_ObjC :
604594 return SourceLanguage::ObjC;
605- case dwarf::DW_LANG_ObjC_plus_plus :
595+ case dwarf::DW_LNAME_ObjC_plus_plus :
606596 return SourceLanguage::ObjCpp;
607597 default :
608598 // There's no CodeView representation for this language, and CV doesn't
@@ -612,6 +602,14 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
612602 }
613603}
614604
605+ static SourceLanguage MapDWARFLanguageToCVLang (dwarf::SourceLanguage DWLang) {
606+ auto MaybeLName = dwarf::toDW_LNAME (DWLang);
607+ if (!MaybeLName)
608+ return MapDWARFLanguageToCVLang (static_cast <dwarf::SourceLanguageName>(0 ));
609+
610+ return MapDWARFLanguageToCVLang (MaybeLName->first );
611+ }
612+
615613void CodeViewDebug::beginModule (Module *M) {
616614 // If COFF debug section is not available, skip any debug info related stuff.
617615 if (!Asm->getObjFileLowering ().getCOFFDebugSymbolsSection ()) {
@@ -633,8 +631,13 @@ void CodeViewDebug::beginModule(Module *M) {
633631 Node = *CUs->operands ().begin ();
634632 }
635633 const auto *CU = cast<DICompileUnit>(Node);
634+ DISourceLanguageName Lang = CU->getSourceLanguage ();
636635 CurrentSourceLanguage =
637- MapDWLangToCVLang (CU->getSourceLanguage ().getUnversionedName ());
636+ Lang.hasVersionedName ()
637+ ? MapDWARFLanguageToCVLang (
638+ static_cast <dwarf::SourceLanguageName>(Lang.getName ()))
639+ : MapDWARFLanguageToCVLang (
640+ static_cast <dwarf::SourceLanguage>(Lang.getName ()));
638641 if (!M->getCodeViewFlag () ||
639642 CU->getEmissionKind () == DICompileUnit::NoDebug) {
640643 Asm = nullptr ;
0 commit comments