Skip to content

Conversation

Michael137
Copy link
Member

Depends on:

Emit DW_AT_language_name (new in DWARFv6) if DICompileUnit has a sourceLanguageName field. Emit a DW_AT_language otherwise.

@Michael137 Michael137 force-pushed the llvm/dwarf-language-attrs-2-part-7 branch from b9e4b54 to 1ddc997 Compare October 10, 2025 09:06
@Michael137 Michael137 marked this pull request as ready for review October 10, 2025 09:07
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

@llvm/pr-subscribers-debuginfo

Author: Michael Buch (Michael137)

Changes

Depends on:

Emit DW_AT_language_name (new in DWARFv6) if DICompileUnit has a sourceLanguageName field. Emit a DW_AT_language otherwise.


Full diff: https://github.com/llvm/llvm-project/pull/162621.diff

3 Files Affected:

  • (modified) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (+6-2)
  • (added) llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll (+20)
  • (added) llvm/test/DebugInfo/Generic/compileunit-source-language.ll (+20)
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index d751a7f9f01efe..433877f3a8b986 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -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();
diff --git a/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll b/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
new file mode 100644
index 00000000000000..94e32ab8c65b25
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
@@ -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}
diff --git a/llvm/test/DebugInfo/Generic/compileunit-source-language.ll b/llvm/test/DebugInfo/Generic/compileunit-source-language.ll
new file mode 100644
index 00000000000000..0d0da4fa11d642
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/compileunit-source-language.ll
@@ -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}

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).

@Michael137 Michael137 merged commit 7dbf115 into llvm:main Oct 10, 2025
10 checks passed
@Michael137 Michael137 deleted the llvm/dwarf-language-attrs-2-part-7 branch October 10, 2025 17:58
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 10, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-sie-ubuntu-fast running on sie-linux-worker while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/37570

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: DebugInfo/Generic/compileunit-source-language.ll' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -filetype=obj -O0 < /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/DebugInfo/Generic/compileunit-source-language.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-dwarfdump -debug-info - | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/DebugInfo/Generic/compileunit-source-language.ll --implicit-check-not "DW_AT_language_name"
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc -filetype=obj -O0
# .---command stderr------------
# | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llc: error: unable to get target for 'arm64-apple-macosx', see --version and --triple.
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/llvm-dwarfdump -debug-info -
# .---command stderr------------
# | error: -: The file was not recognized as a valid object file
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/DebugInfo/Generic/compileunit-source-language.ll --implicit-check-not DW_AT_language_name
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/test/DebugInfo/Generic/compileunit-source-language.ll --implicit-check-not DW_AT_language_name
# `-----------------------------
# error: command failed with exit status: 2

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 10, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building llvm at step 8 "Add check check-llvm".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/15225

Here is the relevant piece of the build log for the reference
Step 8 (Add check check-llvm) failure: test (failure)
******************** TEST 'LLVM :: DebugInfo/Generic/compileunit-source-language-name.ll' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/llc -filetype=obj -O0 < /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/llvm-dwarfdump -debug-info - | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll --implicit-check-not "DW_AT_language"
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/llc -filetype=obj -O0
# .---command stderr------------
# | /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/llc: error: unable to get target for 'arm64-apple-macosx', see --version and --triple.
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/llvm-dwarfdump -debug-info -
# .---command stderr------------
# | error: -: The file was not recognized as a valid object file
# `-----------------------------
# error: command failed with exit status: 1
# executed command: /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll --implicit-check-not DW_AT_language
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/FileCheck /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll --implicit-check-not DW_AT_language
# `-----------------------------
# error: command failed with exit status: 2

--

********************


@Michael137
Copy link
Member Author

Bots failing because i specified arm64 triple but put it in the Generic directory

@Kewen12
Copy link
Contributor

Kewen12 commented Oct 10, 2025

Hello, will the fix land soon? It would help unblock our bots. Thanks

@Michael137
Copy link
Member Author

Hello, will the fix land soon? It would help unblock our bots. Thanks

Should be fixed now. Let me know if it's not

@Kewen12
Copy link
Contributor

Kewen12 commented Oct 10, 2025

Hello, will the fix land soon? It would help unblock our bots. Thanks

Should be fixed now. Let me know if it's not

It was fixed! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants