Skip to content

Commit 9595dee

Browse files
committed
[DebugInfo] Skip both pointer and reference type parameters
DWARFTypePrinter::appendTemplateParameters already skips pointer type parameters but didn't account for reference type parameters. This would result in tripping up the RawName assertion below. This updates the check for both `DW_TAG_pointer_type` and `DW_TAG_reference_type`. Thanks to Dave Blaikie for helping with the test. rdar://130297520
1 parent cf311a1 commit 9595dee

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,11 @@ bool DWARFTypePrinter::appendTemplateParameters(DWARFDie D,
351351
OS << std::to_string(*V->getAsSignedConstant());
352352
continue;
353353
}
354-
// /Maybe/ we could do pointer type parameters, looking for the
354+
// /Maybe/ we could do pointer/reference type parameters, looking for the
355355
// symbol in the ELF symbol table to get back to the variable...
356356
// but probably not worth it.
357-
if (T.getTag() == DW_TAG_pointer_type)
357+
if (T.getTag() == DW_TAG_pointer_type ||
358+
T.getTag() == DW_TAG_reference_type)
358359
continue;
359360
const char *RawName = dwarf::toString(T.find(DW_AT_name), nullptr);
360361
assert(RawName);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
; RUN: llc -O0 %s -filetype=obj -o %t.o
2+
; RUN: llvm-dwarfdump --verify %t.o
3+
4+
; $ cat ptr.cpp
5+
; int glbl = 42;
6+
; constexpr int *r = &glbl;
7+
; template<int *ref>
8+
; int x;
9+
; int main() {
10+
; x<r> = 3;
11+
; }
12+
13+
source_filename = "ptr.cpp"
14+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
15+
target triple = "arm64-apple-macosx15.0.0"
16+
17+
@glbl = global i32 42, align 4, !dbg !0
18+
@r = constant ptr @glbl, align 8, !dbg !5
19+
@_Z1xIL_Z4glblEE = linkonce_odr global i32 0, align 4, !dbg !9
20+
21+
; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable(sync)
22+
define noundef i32 @main() #0 !dbg !21 {
23+
entry:
24+
store i32 3, ptr @_Z1xIL_Z4glblEE, align 4, !dbg !24
25+
ret i32 0, !dbg !25
26+
}
27+
28+
attributes #0 = { mustprogress noinline norecurse nounwind optnone ssp uwtable(sync) "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a,+zcm,+zcz" }
29+
30+
!llvm.module.flags = !{!14, !15, !16, !17, !18, !19}
31+
!llvm.dbg.cu = !{!2}
32+
!llvm.linker.options = !{}
33+
!llvm.ident = !{!20}
34+
35+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
36+
!1 = distinct !DIGlobalVariable(name: "glbl", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
37+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 19.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk", sdk: "MacOSX15.0.sdk")
38+
!3 = !DIFile(filename: "ptr.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "b7b99c5692b757c3b50d0e841713927c")
39+
!4 = !{!0, !5, !9}
40+
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
41+
!6 = distinct !DIGlobalVariable(name: "r", scope: !2, file: !3, line: 2, type: !7, isLocal: false, isDefinition: true)
42+
!7 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !8, size: 64)
43+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
44+
!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
45+
!10 = distinct !DIGlobalVariable(name: "x", linkageName: "_Z1xIL_Z4glblEE", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, templateParams: !11)
46+
!11 = !{!12}
47+
!12 = !DITemplateValueParameter(name: "ref", type: !7, value: ptr @glbl)
48+
!14 = !{i32 7, !"Dwarf Version", i32 5}
49+
!15 = !{i32 2, !"Debug Info Version", i32 3}
50+
!16 = !{i32 1, !"wchar_size", i32 4}
51+
!17 = !{i32 8, !"PIC Level", i32 2}
52+
!18 = !{i32 7, !"uwtable", i32 1}
53+
!19 = !{i32 7, !"frame-pointer", i32 1}
54+
!20 = !{!"clang version 19.0.0git ([email protected]:llvm/llvm-project.git 5d15f606da4cb4346465956d935a2842f8e86200)"}
55+
!21 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 5, type: !22, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
56+
!22 = !DISubroutineType(types: !23)
57+
!23 = !{!8}
58+
!24 = !DILocation(line: 6, column: 8, scope: !21)
59+
!25 = !DILocation(line: 7, column: 1, scope: !21)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; RUN: llc -O0 %s -filetype=obj -o %t.o
2+
; RUN: llvm-dwarfdump --verify %t.o
3+
4+
; $ cat ref.cpp
5+
; int glbl = 42;
6+
; int &r = glbl;
7+
; template<int &ref>
8+
; int x;
9+
; int main() {
10+
; x<r> = 3;
11+
; }
12+
13+
source_filename = "ref.cpp"
14+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
15+
target triple = "arm64-apple-macosx15.0.0"
16+
17+
@glbl = global i32 42, align 4, !dbg !0
18+
@r = constant ptr @glbl, align 8, !dbg !5
19+
@_Z1xIL_Z4glblEE = linkonce_odr global i32 0, align 4, !dbg !9
20+
21+
; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable(sync)
22+
define noundef i32 @main() #0 !dbg !19 {
23+
entry:
24+
store i32 3, ptr @_Z1xIL_Z4glblEE, align 4, !dbg !22
25+
ret i32 0, !dbg !23
26+
}
27+
28+
attributes #0 = { mustprogress noinline norecurse nounwind optnone ssp uwtable(sync) "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+jsconv,+lse,+neon,+pauth,+perfmon,+predres,+ras,+rcpc,+rdm,+sb,+sha2,+sha3,+ssbs,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8a,+zcm,+zcz" }
29+
30+
!llvm.module.flags = !{!13, !14, !15, !16, !17, !18}
31+
!llvm.dbg.cu = !{!2}
32+
!llvm.linker.options = !{}
33+
34+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
35+
!1 = distinct !DIGlobalVariable(name: "glbl", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
36+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 19.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: Apple, sysroot: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk", sdk: "MacOSX15.0.sdk")
37+
!3 = !DIFile(filename: "ref.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "b7b99c5692b757c3b50d0e841713927c")
38+
!4 = !{!0, !5, !9}
39+
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
40+
!6 = distinct !DIGlobalVariable(name: "r", scope: !2, file: !3, line: 2, type: !7, isLocal: false, isDefinition: true)
41+
!7 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !8, size: 64)
42+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
43+
!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
44+
!10 = distinct !DIGlobalVariable(name: "x", linkageName: "_Z1xIL_Z4glblEE", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, templateParams: !11)
45+
!11 = !{!12}
46+
!12 = !DITemplateValueParameter(name: "ref", type: !7, value: ptr @glbl)
47+
!13 = !{i32 7, !"Dwarf Version", i32 5}
48+
!14 = !{i32 2, !"Debug Info Version", i32 3}
49+
!15 = !{i32 1, !"wchar_size", i32 4}
50+
!16 = !{i32 8, !"PIC Level", i32 2}
51+
!17 = !{i32 7, !"uwtable", i32 1}
52+
!18 = !{i32 7, !"frame-pointer", i32 1}
53+
!19 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 5, type: !20, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
54+
!20 = !DISubroutineType(types: !21)
55+
!21 = !{!8}
56+
!22 = !DILocation(line: 6, column: 8, scope: !19)
57+
!23 = !DILocation(line: 7, column: 1, scope: !19)

0 commit comments

Comments
 (0)