From c3a693dd5a31a6a747afa24dedfbd0720173b221 Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Tue, 7 Oct 2025 12:01:41 +0100 Subject: [PATCH 1/2] [llvm][DebugInfo] DW_AT_language_version (cherry picked from commit 0a859b8f75c71f46f0261f31e32b7f5212dfb978) --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 10 ++++++++-- .../Generic/compileunit-source-language-name.ll | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 433877f3a8b98..526b3130f317a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1039,12 +1039,18 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit, } else NewCU.addString(Die, dwarf::DW_AT_producer, Producer); - if (auto Lang = DIUnit->getSourceLanguage(); Lang.hasVersionedName()) + if (auto Lang = DIUnit->getSourceLanguage(); Lang.hasVersionedName()) { NewCU.addUInt(Die, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2, Lang.getName()); - else + + if (uint32_t LangVersion = Lang.getVersion(); + LangVersion != 0) + NewCU.addUInt(Die, dwarf::DW_AT_language_version, /*Form=*/std::nullopt, + LangVersion); + } 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(); diff --git a/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll b/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll index e2b6167cab910..c8cc8717ef66e 100644 --- a/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll +++ b/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll @@ -1,6 +1,10 @@ ; 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) +; CHECK: DW_AT_language_name (DW_LNAME_ObjC_plus_plus) +; CHECK: DW_AT_language_name (DW_LNAME_C_plus_plus) +; CHECK: DW_AT_language_version (201100) +; CHECK: DW_AT_language_name (DW_LNAME_Rust) +; CHECK-NOT: DW_AT_language_version @x = global i32 0, align 4, !dbg !0 @@ -9,7 +13,7 @@ define void @_Z4funcv() !dbg !8 { ret void, !dbg !11 } -!llvm.dbg.cu = !{!2} +!llvm.dbg.cu = !{!2, !12, !13} !llvm.module.flags = !{!6, !7} !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) @@ -24,3 +28,5 @@ define void @_Z4funcv() !dbg !8 { !9 = !DISubroutineType(types: !10) !10 = !{null} !11 = !DILocation(line: 2, column: 14, scope: !8) +!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: "/") +!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: "/") From 5d80efc375685a5a183d6f4ed5a064758d559d4f Mon Sep 17 00:00:00 2001 From: Michael Buch Date: Mon, 13 Oct 2025 10:21:07 +0100 Subject: [PATCH 2/2] fixup! clang-format --- llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 526b3130f317a..45e45720d51cd 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1043,8 +1043,7 @@ void DwarfDebug::finishUnitAttributes(const DICompileUnit *DIUnit, NewCU.addUInt(Die, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2, Lang.getName()); - if (uint32_t LangVersion = Lang.getVersion(); - LangVersion != 0) + if (uint32_t LangVersion = Lang.getVersion(); LangVersion != 0) NewCU.addUInt(Die, dwarf::DW_AT_language_version, /*Form=*/std::nullopt, LangVersion); } else {