Skip to content

Commit 3bfb5b0

Browse files
authored
[llvm][DebugInfo] Support versioned source language names in DwarfUnit (#162625)
Depends on: * #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.
1 parent c16eaa4 commit 3bfb5b0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,17 @@ void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
704704
addDIEEntry(Entity, Attribute, DIEEntry(*getOrCreateTypeDIE(Ty)));
705705
}
706706

707+
// FIXME: change callsites to use the new DW_LNAME_ language codes.
707708
llvm::dwarf::SourceLanguage DwarfUnit::getSourceLanguage() const {
708-
return static_cast<llvm::dwarf::SourceLanguage>(
709-
getLanguage().getUnversionedName());
709+
const auto &Lang = getLanguage();
710+
711+
if (!Lang.hasVersionedName())
712+
return static_cast<llvm::dwarf::SourceLanguage>(Lang.getName());
713+
714+
return llvm::dwarf::toDW_LANG(
715+
static_cast<llvm::dwarf::SourceLanguageName>(Lang.getName()),
716+
Lang.getVersion())
717+
.value_or(llvm::dwarf::DW_LANG_hi_user);
710718
}
711719

712720
std::string DwarfUnit::getParentContextString(const DIScope *Context) const {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
@x = global i32 0, align 4, !dbg !0
66

7+
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
8+
define void @_Z4funcv() !dbg !8 {
9+
ret void, !dbg !11
10+
}
11+
712
!llvm.dbg.cu = !{!2}
813
!llvm.module.flags = !{!6, !7}
914

@@ -15,3 +20,7 @@
1520
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
1621
!6 = !{i32 7, !"Dwarf Version", i32 5}
1722
!7 = !{i32 2, !"Debug Info Version", i32 3}
23+
!8 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", scope: !3, file: !3, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
24+
!9 = !DISubroutineType(types: !10)
25+
!10 = !{null}
26+
!11 = !DILocation(line: 2, column: 14, scope: !8)

0 commit comments

Comments
 (0)