Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,40 +569,30 @@ void CodeViewDebug::emitCodeViewMagicVersion() {
OS.emitInt32(COFF::DEBUG_SECTION_MAGIC);
}

static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
switch (DWLang) {
case dwarf::DW_LANG_C:
case dwarf::DW_LANG_C89:
case dwarf::DW_LANG_C99:
case dwarf::DW_LANG_C11:
static SourceLanguage
MapDWARFLanguageToCVLang(dwarf::SourceLanguageName DWLName) {
switch (DWLName) {
case dwarf::DW_LNAME_C:
return SourceLanguage::C;
case dwarf::DW_LANG_C_plus_plus:
case dwarf::DW_LANG_C_plus_plus_03:
case dwarf::DW_LANG_C_plus_plus_11:
case dwarf::DW_LANG_C_plus_plus_14:
case dwarf::DW_LNAME_C_plus_plus:
return SourceLanguage::Cpp;
case dwarf::DW_LANG_Fortran77:
case dwarf::DW_LANG_Fortran90:
case dwarf::DW_LANG_Fortran95:
case dwarf::DW_LANG_Fortran03:
case dwarf::DW_LANG_Fortran08:
case dwarf::DW_LNAME_Fortran:
return SourceLanguage::Fortran;
case dwarf::DW_LANG_Pascal83:
case dwarf::DW_LNAME_Pascal:
return SourceLanguage::Pascal;
case dwarf::DW_LANG_Cobol74:
case dwarf::DW_LANG_Cobol85:
case dwarf::DW_LNAME_Cobol:
return SourceLanguage::Cobol;
case dwarf::DW_LANG_Java:
case dwarf::DW_LNAME_Java:
return SourceLanguage::Java;
case dwarf::DW_LANG_D:
case dwarf::DW_LNAME_D:
return SourceLanguage::D;
case dwarf::DW_LANG_Swift:
case dwarf::DW_LNAME_Swift:
return SourceLanguage::Swift;
case dwarf::DW_LANG_Rust:
case dwarf::DW_LNAME_Rust:
return SourceLanguage::Rust;
case dwarf::DW_LANG_ObjC:
case dwarf::DW_LNAME_ObjC:
return SourceLanguage::ObjC;
case dwarf::DW_LANG_ObjC_plus_plus:
case dwarf::DW_LNAME_ObjC_plus_plus:
return SourceLanguage::ObjCpp;
default:
// There's no CodeView representation for this language, and CV doesn't
Expand All @@ -612,6 +602,14 @@ static SourceLanguage MapDWLangToCVLang(unsigned DWLang) {
}
}

static SourceLanguage MapDWARFLanguageToCVLang(dwarf::SourceLanguage DWLang) {
auto MaybeLName = dwarf::toDW_LNAME(DWLang);
if (!MaybeLName)
return MapDWARFLanguageToCVLang(static_cast<dwarf::SourceLanguageName>(0));

return MapDWARFLanguageToCVLang(MaybeLName->first);
}

void CodeViewDebug::beginModule(Module *M) {
// If COFF debug section is not available, skip any debug info related stuff.
if (!Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
Expand All @@ -633,8 +631,13 @@ void CodeViewDebug::beginModule(Module *M) {
Node = *CUs->operands().begin();
}
const auto *CU = cast<DICompileUnit>(Node);
DISourceLanguageName Lang = CU->getSourceLanguage();
CurrentSourceLanguage =
MapDWLangToCVLang(CU->getSourceLanguage().getUnversionedName());
Lang.hasVersionedName()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this adjustment, the new compileunit-source-language-name.ll‎ test would assert in getUnversionedName on Windows bots (caught by pre-merge CI).

? MapDWARFLanguageToCVLang(
static_cast<dwarf::SourceLanguageName>(Lang.getName()))
: MapDWARFLanguageToCVLang(
static_cast<dwarf::SourceLanguage>(Lang.getName()));
if (!M->getCodeViewFlag() ||
CU->getEmissionKind() == DICompileUnit::NoDebug) {
Asm = nullptr;
Expand Down
8 changes: 6 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,12 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
} else
NewCU.addString(Die, dwarf::DW_AT_producer, Producer);

NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
DIUnit->getSourceLanguage().getUnversionedName());
if (auto Lang = DIUnit->getSourceLanguage(); Lang.hasVersionedName())
NewCU.addUInt(Die, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2,
Lang.getName());
else
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
Lang.getName());

NewCU.addString(Die, dwarf::DW_AT_name, FN);
StringRef SysRoot = DIUnit->getSysRoot();
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info - | FileCheck %s --implicit-check-not "DW_AT_language"

; CHECK: DW_AT_language_name (DW_LNAME_ObjC_plus_plus)

source_filename = "cu.cpp"
target triple = "arm64-apple-macosx"

@x = global i32 0, align 4, !dbg !0

!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!6, !7}

!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(sourceLanguageName: DW_LNAME_ObjC_plus_plus, file: !3, producer: "handwritten", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
!3 = !DIFile(filename: "cu.cpp", directory: "/tmp")
!4 = !{!0}
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!6 = !{i32 7, !"Dwarf Version", i32 5}
!7 = !{i32 2, !"Debug Info Version", i32 3}
20 changes: 20 additions & 0 deletions llvm/test/DebugInfo/Generic/compileunit-source-language.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info - | FileCheck %s --implicit-check-not "DW_AT_language_name"

; CHECK: DW_AT_language (DW_LANG_C)

source_filename = "cu.cpp"
target triple = "arm64-apple-macosx"

@x = global i32 0, align 4, !dbg !0

!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!6, !7}

!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
!1 = !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
!2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "handwritten", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
!3 = !DIFile(filename: "cu.cpp", directory: "/tmp")
!4 = !{!0}
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!6 = !{i32 7, !"Dwarf Version", i32 5}
!7 = !{i32 2, !"Debug Info Version", i32 3}