Skip to content

Commit e164e31

Browse files
committed
[llvm][DebugInfo] Support versioned source language names in DwarfUnit
1 parent 1ddc997 commit e164e31

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,15 @@ void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
705705
}
706706

707707
llvm::dwarf::SourceLanguage DwarfUnit::getSourceLanguage() const {
708-
return static_cast<llvm::dwarf::SourceLanguage>(
709-
getLanguage().getUnversionedName());
708+
const auto &Lang = getLanguage();
709+
710+
if (!Lang.hasVersionedName())
711+
return static_cast<llvm::dwarf::SourceLanguage>(Lang.getName());
712+
713+
return llvm::dwarf::toDW_LANG(
714+
static_cast<llvm::dwarf::SourceLanguageName>(Lang.getName()),
715+
Lang.getVersion())
716+
.value_or(llvm::dwarf::DW_LANG_hi_user);
710717
}
711718

712719
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
@@ -7,6 +7,11 @@ target triple = "arm64-apple-macosx"
77

88
@x = global i32 0, align 4, !dbg !0
99

10+
; Function Attrs: mustprogress noinline nounwind optnone ssp uwtable(sync)
11+
define void @_Z4funcv() !dbg !8 {
12+
ret void, !dbg !11
13+
}
14+
1015
!llvm.dbg.cu = !{!2}
1116
!llvm.module.flags = !{!6, !7}
1217

@@ -18,3 +23,7 @@ target triple = "arm64-apple-macosx"
1823
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
1924
!6 = !{i32 7, !"Dwarf Version", i32 5}
2025
!7 = !{i32 2, !"Debug Info Version", i32 3}
26+
!8 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", scope: !3, file: !3, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
27+
!9 = !DISubroutineType(types: !10)
28+
!10 = !{null}
29+
!11 = !DILocation(line: 2, column: 14, scope: !8)

0 commit comments

Comments
 (0)