Skip to content

Commit 1ddc997

Browse files
committed
[llvm][DebugInfo] Emit DW_AT_lanugage_name
1 parent 6c2781e commit 1ddc997

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,12 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit,
10391039
} else
10401040
NewCU.addString(Die, dwarf::DW_AT_producer, Producer);
10411041

1042-
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
1043-
DIUnit->getSourceLanguage().getUnversionedName());
1042+
if (auto Lang = DIUnit->getSourceLanguage(); Lang.hasVersionedName())
1043+
NewCU.addUInt(Die, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2,
1044+
Lang.getName());
1045+
else
1046+
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
1047+
Lang.getName());
10441048

10451049
NewCU.addString(Die, dwarf::DW_AT_name, FN);
10461050
StringRef SysRoot = DIUnit->getSysRoot();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info - | FileCheck %s --implicit-check-not "DW_AT_language"
2+
3+
; CHECK: DW_AT_language_name (DW_LNAME_ObjC_plus_plus)
4+
5+
source_filename = "cu.cpp"
6+
target triple = "arm64-apple-macosx"
7+
8+
@x = global i32 0, align 4, !dbg !0
9+
10+
!llvm.dbg.cu = !{!2}
11+
!llvm.module.flags = !{!6, !7}
12+
13+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
14+
!1 = !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
15+
!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: "/")
16+
!3 = !DIFile(filename: "cu.cpp", directory: "/tmp")
17+
!4 = !{!0}
18+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
19+
!6 = !{i32 7, !"Dwarf Version", i32 5}
20+
!7 = !{i32 2, !"Debug Info Version", i32 3}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info - | FileCheck %s --implicit-check-not "DW_AT_language_name"
2+
3+
; CHECK: DW_AT_language (DW_LANG_C)
4+
5+
source_filename = "cu.cpp"
6+
target triple = "arm64-apple-macosx"
7+
8+
@x = global i32 0, align 4, !dbg !0
9+
10+
!llvm.dbg.cu = !{!2}
11+
!llvm.module.flags = !{!6, !7}
12+
13+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
14+
!1 = !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
15+
!2 = distinct !DICompileUnit(language: DW_LANG_C, file: !3, producer: "handwritten", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
16+
!3 = !DIFile(filename: "cu.cpp", directory: "/tmp")
17+
!4 = !{!0}
18+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
19+
!6 = !{i32 7, !"Dwarf Version", i32 5}
20+
!7 = !{i32 2, !"Debug Info Version", i32 3}

0 commit comments

Comments
 (0)