Skip to content

Commit c3a693d

Browse files
committed
[llvm][DebugInfo] DW_AT_language_version
(cherry picked from commit 0a859b8)
1 parent d4f862a commit c3a693d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp

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

1042-
if (auto Lang = DIUnit->getSourceLanguage(); Lang.hasVersionedName())
1042+
if (auto Lang = DIUnit->getSourceLanguage(); Lang.hasVersionedName()) {
10431043
NewCU.addUInt(Die, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2,
10441044
Lang.getName());
1045-
else
1045+
1046+
if (uint32_t LangVersion = Lang.getVersion();
1047+
LangVersion != 0)
1048+
NewCU.addUInt(Die, dwarf::DW_AT_language_version, /*Form=*/std::nullopt,
1049+
LangVersion);
1050+
} else {
10461051
NewCU.addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
10471052
Lang.getName());
1053+
}
10481054

10491055
NewCU.addString(Die, dwarf::DW_AT_name, FN);
10501056
StringRef SysRoot = DIUnit->getSysRoot();

llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
; RUN: %llc_dwarf -filetype=obj -O0 < %s | llvm-dwarfdump -debug-info - | FileCheck %s --implicit-check-not "DW_AT_language"
22

3-
; CHECK: DW_AT_language_name (DW_LNAME_ObjC_plus_plus)
3+
; CHECK: DW_AT_language_name (DW_LNAME_ObjC_plus_plus)
4+
; CHECK: DW_AT_language_name (DW_LNAME_C_plus_plus)
5+
; CHECK: DW_AT_language_version (201100)
6+
; CHECK: DW_AT_language_name (DW_LNAME_Rust)
7+
; CHECK-NOT: DW_AT_language_version
48

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

@@ -9,7 +13,7 @@ define void @_Z4funcv() !dbg !8 {
913
ret void, !dbg !11
1014
}
1115

12-
!llvm.dbg.cu = !{!2}
16+
!llvm.dbg.cu = !{!2, !12, !13}
1317
!llvm.module.flags = !{!6, !7}
1418

1519
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
@@ -24,3 +28,5 @@ define void @_Z4funcv() !dbg !8 {
2428
!9 = !DISubroutineType(types: !10)
2529
!10 = !{null}
2630
!11 = !DILocation(line: 2, column: 14, scope: !8)
31+
!12 = distinct !DICompileUnit(sourceLanguageName: DW_LNAME_C_plus_plus, sourceLanguageVersion: 201100, file: !3, producer: "handwritten", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")
32+
!13 = distinct !DICompileUnit(sourceLanguageName: DW_LNAME_Rust, sourceLanguageVersion: 0, file: !3, producer: "handwritten", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/")

0 commit comments

Comments
 (0)