Skip to content

[DebugInfo] Skip both pointer and reference type parameters #97094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2024

Conversation

JDevlieghere
Copy link
Member

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

@llvmbot
Copy link
Member

llvmbot commented Jun 28, 2024

@llvm/pr-subscribers-debuginfo

Author: Jonas Devlieghere (JDevlieghere)

Changes

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


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

3 Files Affected:

  • (modified) llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp (+3-2)
  • (added) llvm/test/tools/llvm-dwarfdump/AArch64/template_ptr.ll (+59)
  • (added) llvm/test/tools/llvm-dwarfdump/AArch64/template_ref.ll (+57)
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
index 05dee8a3d7129..a26431e8313f6 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFTypePrinter.cpp
@@ -351,10 +351,11 @@ bool DWARFTypePrinter::appendTemplateParameters(DWARFDie D,
         OS << std::to_string(*V->getAsSignedConstant());
         continue;
       }
-      // /Maybe/ we could do pointer type parameters, looking for the
+      // /Maybe/ we could do pointer/reference type parameters, looking for the
       // symbol in the ELF symbol table to get back to the variable...
       // but probably not worth it.
-      if (T.getTag() == DW_TAG_pointer_type)
+      if (T.getTag() == DW_TAG_pointer_type ||
+          T.getTag() == DW_TAG_reference_type)
         continue;
       const char *RawName = dwarf::toString(T.find(DW_AT_name), nullptr);
       assert(RawName);
diff --git a/llvm/test/tools/llvm-dwarfdump/AArch64/template_ptr.ll b/llvm/test/tools/llvm-dwarfdump/AArch64/template_ptr.ll
new file mode 100644
index 0000000000000..5ac93bf41947b
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/AArch64/template_ptr.ll
@@ -0,0 +1,59 @@
+; RUN: llc -O0 %s -filetype=obj -o %t.o
+; RUN: llvm-dwarfdump --verify %t.o
+
+; $ cat ptr.cpp
+; int glbl = 42;
+; constexpr int *r = &glbl;
+; template<int *ref>
+; int x;
+; int main() {
+;   x<r> = 3;
+; }
+
+source_filename = "ptr.cpp"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
+target triple = "arm64-apple-macosx15.0.0"
+
+@glbl = global i32 42, align 4, !dbg !0
+@r = constant ptr @glbl, align 8, !dbg !5
+@_Z1xIL_Z4glblEE = linkonce_odr global i32 0, align 4, !dbg !9
+
+; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable(sync)
+define noundef i32 @main() #0 !dbg !21 {
+entry:
+  store i32 3, ptr @_Z1xIL_Z4glblEE, align 4, !dbg !24
+  ret i32 0, !dbg !25
+}
+
+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" }
+
+!llvm.module.flags = !{!14, !15, !16, !17, !18, !19}
+!llvm.dbg.cu = !{!2}
+!llvm.linker.options = !{}
+!llvm.ident = !{!20}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "glbl", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
+!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/XcodeBuilder.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk", sdk: "MacOSX15.0.sdk")
+!3 = !DIFile(filename: "ptr.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "b7b99c5692b757c3b50d0e841713927c")
+!4 = !{!0, !5, !9}
+!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
+!6 = distinct !DIGlobalVariable(name: "r", scope: !2, file: !3, line: 2, type: !7, isLocal: false, isDefinition: true)
+!7 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
+!10 = distinct !DIGlobalVariable(name: "x", linkageName: "_Z1xIL_Z4glblEE", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, templateParams: !11)
+!11 = !{!12}
+!12 = !DITemplateValueParameter(name: "ref", type: !7, value: ptr @glbl)
+!14 = !{i32 7, !"Dwarf Version", i32 5}
+!15 = !{i32 2, !"Debug Info Version", i32 3}
+!16 = !{i32 1, !"wchar_size", i32 4}
+!17 = !{i32 8, !"PIC Level", i32 2}
+!18 = !{i32 7, !"uwtable", i32 1}
+!19 = !{i32 7, !"frame-pointer", i32 1}
+!20 = !{!"clang version 19.0.0git ([email protected]:llvm/llvm-project.git 5d15f606da4cb4346465956d935a2842f8e86200)"}
+!21 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 5, type: !22, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
+!22 = !DISubroutineType(types: !23)
+!23 = !{!8}
+!24 = !DILocation(line: 6, column: 8, scope: !21)
+!25 = !DILocation(line: 7, column: 1, scope: !21)
diff --git a/llvm/test/tools/llvm-dwarfdump/AArch64/template_ref.ll b/llvm/test/tools/llvm-dwarfdump/AArch64/template_ref.ll
new file mode 100644
index 0000000000000..50a8534b79c1d
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/AArch64/template_ref.ll
@@ -0,0 +1,57 @@
+; RUN: llc -O0 %s -filetype=obj -o %t.o
+; RUN: llvm-dwarfdump --verify %t.o
+
+; $ cat ref.cpp
+; int glbl = 42;
+; int &r = glbl;
+; template<int &ref>
+; int x;
+; int main() {
+;   x<r> = 3;
+; }
+
+source_filename = "ref.cpp"
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
+target triple = "arm64-apple-macosx15.0.0"
+
+@glbl = global i32 42, align 4, !dbg !0
+@r = constant ptr @glbl, align 8, !dbg !5
+@_Z1xIL_Z4glblEE = linkonce_odr global i32 0, align 4, !dbg !9
+
+; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable(sync)
+define noundef i32 @main() #0 !dbg !19 {
+entry:
+  store i32 3, ptr @_Z1xIL_Z4glblEE, align 4, !dbg !22
+  ret i32 0, !dbg !23
+}
+
+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" }
+
+!llvm.module.flags = !{!13, !14, !15, !16, !17, !18}
+!llvm.dbg.cu = !{!2}
+!llvm.linker.options = !{}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "glbl", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
+!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/XcodeBuilder.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk", sdk: "MacOSX15.0.sdk")
+!3 = !DIFile(filename: "ref.cpp", directory: "/tmp", checksumkind: CSK_MD5, checksum: "b7b99c5692b757c3b50d0e841713927c")
+!4 = !{!0, !5, !9}
+!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
+!6 = distinct !DIGlobalVariable(name: "r", scope: !2, file: !3, line: 2, type: !7, isLocal: false, isDefinition: true)
+!7 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression())
+!10 = distinct !DIGlobalVariable(name: "x", linkageName: "_Z1xIL_Z4glblEE", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true, templateParams: !11)
+!11 = !{!12}
+!12 = !DITemplateValueParameter(name: "ref", type: !7, value: ptr @glbl)
+!13 = !{i32 7, !"Dwarf Version", i32 5}
+!14 = !{i32 2, !"Debug Info Version", i32 3}
+!15 = !{i32 1, !"wchar_size", i32 4}
+!16 = !{i32 8, !"PIC Level", i32 2}
+!17 = !{i32 7, !"uwtable", i32 1}
+!18 = !{i32 7, !"frame-pointer", i32 1}
+!19 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 5, type: !20, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2)
+!20 = !DISubroutineType(types: !21)
+!21 = !{!8}
+!22 = !DILocation(line: 6, column: 8, scope: !19)
+!23 = !DILocation(line: 7, column: 1, scope: !19)

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
Copy link
Collaborator

@dwblaikie dwblaikie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could put both ref and pointer cases in one test if you like

@JDevlieghere JDevlieghere merged commit eed9141 into llvm:main Jul 1, 2024
7 checks passed
@JDevlieghere JDevlieghere deleted the template-ptr-ref branch July 1, 2024 18:58
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
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
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
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
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Jul 12, 2024
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
(cherry picked from commit eed9141)
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Jul 12, 2024
[DebugInfo] Skip both pointer and reference type parameters (llvm#97094)
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.

3 participants