[PATCH] D99411: [debug-info] Emit DW_AT_byte_size for non-default pointer/reference types

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 2 02:11:57 PDT 2021


arichardson created this revision.
Herald added subscribers: jrtc27, hiraditya, kristof.beyls.
arichardson edited the summary of this revision.
arichardson added reviewers: bsdjhb, aprantl, dblaikie.
arichardson updated this revision to Diff 339179.
arichardson added a comment.
arichardson published this revision for review.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- update test


In the CHERI and Arm Morello targets we support a compilation mode that
has multiple pointer sizes (32/64-bit integers as well as capabilities that are
twice that size). In order to support this in the debugger we emit
DW_AT_byte_size for pointer and reference types if their size is different
from the target's pointer size for the alloca address space.

This patch found the pointer size mismatch that I fixed in D99410 <https://reviews.llvm.org/D99410>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99411

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
  llvm/test/DebugInfo/Generic/ptrsize-nonstandard.ll
  llvm/test/DebugInfo/Generic/ptrsize.ll


Index: llvm/test/DebugInfo/Generic/ptrsize.ll
===================================================================
--- llvm/test/DebugInfo/Generic/ptrsize.ll
+++ llvm/test/DebugInfo/Generic/ptrsize.ll
@@ -1,8 +1,9 @@
 ; RUN: %llc_dwarf -O0 -filetype=obj < %s > %t
 ; RUN: llvm-dwarfdump -v %t | FileCheck %s
 
-; Check that pointers and references get emitted without size information in
-; DWARF, even if they are so specified in the IR
+; Check that pointers and references with size equal to the target's pointer
+; size get emitted without size information in DWARF, even if they are so
+; specified in the IR.
 
 ; CHECK: 0x[[O1:[0-9a-f]+]]:   DW_TAG_pointer_type
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
Index: llvm/test/DebugInfo/Generic/ptrsize-nonstandard.ll
===================================================================
--- llvm/test/DebugInfo/Generic/ptrsize-nonstandard.ll
+++ llvm/test/DebugInfo/Generic/ptrsize-nonstandard.ll
@@ -1,17 +1,18 @@
 ; RUN: %llc_dwarf -O0 -filetype=obj < %s > %t
 ; RUN: llvm-dwarfdump -v %t | FileCheck %s
 
-; Check that pointers and references get emitted without size information in
-; DWARF, even if they are so specified in the IR
+; Check that pointers and references with size different to the target's pointer
+; size are emitted with size information in DWARF.
 
 ; CHECK: 0x[[O1:[0-9a-f]+]]:   DW_TAG_pointer_type
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-; CHECK-NOT: DW_AT_byte_size
-; CHECK: 0x[[O2:[0-9a-f]+]]:   DW_TAG_
+; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1] (0x10)
+; CHECK-NOT: DW_TAG_pointer_type
 
 ; CHECK: 0x[[O3:[0-9a-f]+]]:   DW_TAG_reference_type
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-; CHECK-NOT: DW_AT_byte_size
+; CHECK-NEXT: DW_AT_byte_size [DW_FORM_data1] (0x10)
+; CHECK-NOT: DW_TAG_reference_type
 
 define i32 @foo() !dbg !4 {
 entry:
@@ -29,13 +30,13 @@
 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
 !1 = !DIFile(filename: "dwarf-test.c", directory: "test")
 !2 = !{}
-!4 = distinct !DISubprogram(name: "foo", scope: !0, file: !1, line: 6, type: !6, isLocal: false, isDefinition: true, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
-!5 = distinct !DISubprogram(name: "bar", scope: !0, file: !1, line: 6, type: !15, isLocal: false, isDefinition: true, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "foo", scope: !0, file: !1, line: 6, type: !6, isLocal: false, isDefinition: true, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
+!5 = distinct !DISubprogram(name: "bar", scope: !0, file: !1, line: 6, type: !15, isLocal: false, isDefinition: true, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
 !6 = !DISubroutineType(types: !7)
 !7 = !{!9}
 !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
-!9 = !DIDerivedType(tag: DW_TAG_pointer_type, scope: !0, baseType: !8, size: 64, align: 64)
-!10 = !DIDerivedType(tag: DW_TAG_reference_type, scope: !0, baseType: !8, size: 64, align: 64)
+!9 = !DIDerivedType(tag: DW_TAG_pointer_type, scope: !0, baseType: !8, size: 128, align: 128)
+!10 = !DIDerivedType(tag: DW_TAG_reference_type, scope: !0, baseType: !8, size: 128, align: 128)
 !11 = !{i32 2, !"Dwarf Version", i32 3}
 !12 = !{i32 1, !"Debug Info Version", i32 3}
 !13 = !DILocation(line: 7, scope: !4)
Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -768,11 +768,13 @@
               AlignInBytes);
   }
 
-  // Add size if non-zero (derived types might be zero-sized.)
-  if (Size && Tag != dwarf::DW_TAG_pointer_type
-           && Tag != dwarf::DW_TAG_ptr_to_member_type
-           && Tag != dwarf::DW_TAG_reference_type
-           && Tag != dwarf::DW_TAG_rvalue_reference_type)
+  // Add size if non-zero or non-default (derived types might be zero-sized.)
+  if (Size && ((Tag != dwarf::DW_TAG_pointer_type &&
+                Tag != dwarf::DW_TAG_ptr_to_member_type &&
+                Tag != dwarf::DW_TAG_reference_type &&
+                Tag != dwarf::DW_TAG_rvalue_reference_type) ||
+               Size != Asm->getDataLayout().getPointerSize(
+                           Asm->getDataLayout().getAllocaAddrSpace())))
     addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
 
   if (Tag == dwarf::DW_TAG_ptr_to_member_type)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99411.339179.patch
Type: text/x-patch
Size: 4738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210702/09c3c421/attachment.bin>


More information about the llvm-commits mailing list