[llvm] r218726 - Implement DW_TAG_subrange_type with DW_AT_count rather than DW_AT_upper_bound

David Blaikie dblaikie at gmail.com
Tue Sep 30 17:56:55 PDT 2014


Author: dblaikie
Date: Tue Sep 30 19:56:55 2014
New Revision: 218726

URL: http://llvm.org/viewvc/llvm-project?rev=218726&view=rev
Log:
Implement DW_TAG_subrange_type with DW_AT_count rather than DW_AT_upper_bound

This allows proper disambiguation of unbounded arrays and arrays of zero
bound ("struct foo { int x[]; };" and "struct foo { int x[0]; }"). GCC
instead produces an upper bound of -1 in the latter situation, but count
seems tidier. This way lower_bound is provided if it's not the language
default and count is provided if the count is known, otherwise it's
omitted. Simple.

If someone wants to look at rdar://problem/12566646 and see if this
change is acceptable to that bug/fix, that might be helpful (see the
empty-and-one-elem-array.ll test case which cites that radar).

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/test/DebugInfo/X86/dbg-subrange.ll
    llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll
    llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=218726&r1=218725&r2=218726&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Tue Sep 30 19:56:55 2014
@@ -1748,9 +1748,7 @@ void DwarfUnit::constructSubrangeDIE(DIE
   // The LowerBound value defines the lower bounds which is typically zero for
   // C/C++. The Count value is the number of elements.  Values are 64 bit. If
   // Count == -1 then the array is unbounded and we do not emit
-  // DW_AT_lower_bound and DW_AT_upper_bound attributes. If LowerBound == 0 and
-  // Count == 0, then the array has zero elements in which case we do not emit
-  // an upper bound.
+  // DW_AT_lower_bound and DW_AT_count attributes.
   int64_t LowerBound = SR.getLo();
   int64_t DefaultLowerBound = getDefaultLowerBound();
   int64_t Count = SR.getCount();
@@ -1758,11 +1756,10 @@ void DwarfUnit::constructSubrangeDIE(DIE
   if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
     addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
 
-  if (Count != -1 && Count != 0)
+  if (Count != -1)
     // FIXME: An unbounded array should reference the expression that defines
     // the array.
-    addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, None,
-            LowerBound + Count - 1);
+    addUInt(DW_Subrange, dwarf::DW_AT_count, None, Count);
 }
 
 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.

Modified: llvm/trunk/test/DebugInfo/X86/dbg-subrange.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-subrange.ll?rev=218726&r1=218725&r2=218726&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dbg-subrange.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/dbg-subrange.ll Tue Sep 30 19:56:55 2014
@@ -4,7 +4,7 @@ target datalayout = "e-p:64:64:64-i1:8:8
 target triple = "x86_64-apple-macosx10.7.2"
 
 @s = common global [4294967296 x i8] zeroinitializer, align 16
-;CHECK: .long	4294967295
+; CHECK: .quad 4294967296 ## DW_AT_count
 
 define void @bar() nounwind uwtable ssp {
 entry:

Modified: llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll?rev=218726&r1=218725&r2=218726&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/empty-and-one-elem-array.ll Tue Sep 30 19:56:55 2014
@@ -25,9 +25,6 @@ entry:
 
 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
 
-; An empty array should not have an AT_upper_bound attribute. But an array of 1
-; should.
-
 ; CHECK:      DW_TAG_base_type
 ; CHECK-NEXT: DW_AT_name [DW_FORM_strp]  ( .debug_str[{{.*}}] = "int")
 ; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1]   (DW_ATE_signed)
@@ -46,7 +43,7 @@ declare void @llvm.dbg.declare(metadata,
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
 ; CHECK:      DW_TAG_subrange_type [{{.*}}]
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-; CHECK-NEXT: DW_AT_upper_bound [DW_FORM_data1]  (0x00)
+; CHECK-NEXT: DW_AT_count [DW_FORM_data1]  (0x01)
 
 ; int bar::b[0]:
 ; CHECK: DW_TAG_structure_type
@@ -59,9 +56,9 @@ declare void @llvm.dbg.declare(metadata,
 ; int[0]:
 ; CHECK:      DW_TAG_array_type [{{.*}}] *
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-; CHECK:      DW_TAG_subrange_type [11]
+; CHECK:      DW_TAG_subrange_type
 ; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
-; CHECK-NOT:  DW_AT_upper_bound
+; CHECK:      DW_AT_count [DW_FORM_data1]  (0x00)
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!33}

Modified: llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll?rev=218726&r1=218725&r2=218726&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/nondefault-subrange-array.ll Tue Sep 30 19:56:55 2014
@@ -19,7 +19,7 @@
 ; CHECK: DW_TAG_subrange_type
 ; CHECK-NEXT:                   DW_AT_type [DW_FORM_ref4]  (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]})
 ; CHECK-NEXT:                   DW_AT_lower_bound [DW_FORM_data8]       (0xfffffffffffffffd)
-; CHECK-NEXT:                   DW_AT_upper_bound [DW_FORM_data1]       (0x26)
+; CHECK-NEXT:                   DW_AT_count [DW_FORM_data1]       (0x2a)
 
 ; CHECK: [[BASE]]: DW_TAG_base_type
 ; CHECK: [[BASE2]]: DW_TAG_base_type





More information about the llvm-commits mailing list