[llvm] 3bfb5b0 - [llvm][DebugInfo] Support versioned source language names in DwarfUnit (#162625)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 11 04:43:42 PDT 2025
Author: Michael Buch
Date: 2025-10-11T12:43:38+01:00
New Revision: 3bfb5b0e7ccbcb9f127f5b9c958e6499ba9c0523
URL: https://github.com/llvm/llvm-project/commit/3bfb5b0e7ccbcb9f127f5b9c958e6499ba9c0523
DIFF: https://github.com/llvm/llvm-project/commit/3bfb5b0e7ccbcb9f127f5b9c958e6499ba9c0523.diff
LOG: [llvm][DebugInfo] Support versioned source language names in DwarfUnit (#162625)
Depends on:
* https://github.com/llvm/llvm-project/pull/162621
Now we can start emitting `DW_AT_language_name`, make sure
`DwarfUnit::getSourceLanguage` is equipped to handle this. Otherwise the
new test-case would assert.
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index aa078f3f81d49..e40fb768027b8 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -704,9 +704,17 @@ void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
addDIEEntry(Entity, Attribute, DIEEntry(*getOrCreateTypeDIE(Ty)));
}
+// FIXME: change callsites to use the new DW_LNAME_ language codes.
llvm::dwarf::SourceLanguage DwarfUnit::getSourceLanguage() const {
- return static_cast<llvm::dwarf::SourceLanguage>(
- getLanguage().getUnversionedName());
+ const auto &Lang = getLanguage();
+
+ if (!Lang.hasVersionedName())
+ return static_cast<llvm::dwarf::SourceLanguage>(Lang.getName());
+
+ return llvm::dwarf::toDW_LANG(
+ static_cast<llvm::dwarf::SourceLanguageName>(Lang.getName()),
+ Lang.getVersion())
+ .value_or(llvm::dwarf::DW_LANG_hi_user);
}
std::string DwarfUnit::getParentContextString(const DIScope *Context) const {
diff --git a/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll b/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
index 211a7bc6ad236..e2b6167cab910 100644
--- a/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
+++ b/llvm/test/DebugInfo/Generic/compileunit-source-language-name.ll
@@ -4,6 +4,11 @@
@x = global i32 0, align 4, !dbg !0
+; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
+define void @_Z4funcv() !dbg !8 {
+ ret void, !dbg !11
+}
+
!llvm.dbg.cu = !{!2}
!llvm.module.flags = !{!6, !7}
@@ -15,3 +20,7 @@
!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}
+!8 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", scope: !3, file: !3, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
+!9 = !DISubroutineType(types: !10)
+!10 = !{null}
+!11 = !DILocation(line: 2, column: 14, scope: !8)
More information about the llvm-commits
mailing list