Skip to content

Commit 2f5a3a7

Browse files
committed
fixup! fix CodeView SourceLanguage mappings
1 parent 1ddc997 commit 2f5a3a7

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,40 @@ void CodeViewDebug::emitCodeViewMagicVersion() {
569569
OS.emitInt32(COFF::DEBUG_SECTION_MAGIC);
570570
}
571571

572-
static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
572+
static SourceLanguage
573+
MapDWARFLanguageToCVLang(dwarf::SourceLanguageName DWLName) {
574+
switch (DWLName) {
575+
case dwarf::DW_LNAME_C:
576+
return SourceLanguage::C;
577+
case dwarf::DW_LNAME_C_plus_plus:
578+
return SourceLanguage::Cpp;
579+
case dwarf::DW_LNAME_Fortran:
580+
return SourceLanguage::Fortran;
581+
case dwarf::DW_LNAME_Pascal:
582+
return SourceLanguage::Pascal;
583+
case dwarf::DW_LNAME_Cobol:
584+
return SourceLanguage::Cobol;
585+
case dwarf::DW_LNAME_Java:
586+
return SourceLanguage::Java;
587+
case dwarf::DW_LNAME_D:
588+
return SourceLanguage::D;
589+
case dwarf::DW_LNAME_Swift:
590+
return SourceLanguage::Swift;
591+
case dwarf::DW_LNAME_Rust:
592+
return SourceLanguage::Rust;
593+
case dwarf::DW_LNAME_ObjC:
594+
return SourceLanguage::ObjC;
595+
case dwarf::DW_LNAME_ObjC_plus_plus:
596+
return SourceLanguage::ObjCpp;
597+
default:
598+
// There's no CodeView representation for this language, and CV doesn't
599+
// have an "unknown" option for the language field, so we'll use MASM,
600+
// as it's very low level.
601+
return SourceLanguage::Masm;
602+
}
603+
}
604+
605+
static SourceLanguage MapDWARFLanguageToCVLang(dwarf::SourceLanguage DWLang) {
573606
switch (DWLang) {
574607
case dwarf::DW_LANG_C:
575608
case dwarf::DW_LANG_C89:
@@ -633,8 +666,13 @@ void CodeViewDebug::beginModule(Module *M) {
633666
Node = *CUs->operands().begin();
634667
}
635668
const auto *CU = cast<DICompileUnit>(Node);
669+
DISourceLanguageName Lang = CU->getSourceLanguage();
636670
CurrentSourceLanguage =
637-
MapDWLangToCVLang(CU->getSourceLanguage().getUnversionedName());
671+
Lang.hasVersionedName()
672+
? MapDWARFLanguageToCVLang(
673+
static_cast<dwarf::SourceLanguageName>(Lang.getName()))
674+
: MapDWARFLanguageToCVLang(
675+
static_cast<dwarf::SourceLanguage>(Lang.getName()));
638676
if (!M->getCodeViewFlag() ||
639677
CU->getEmissionKind() == DICompileUnit::NoDebug) {
640678
Asm = nullptr;

0 commit comments

Comments
 (0)