Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 06c1373

Browse files
committed
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218726 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d0d5b08 commit 06c1373

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

lib/CodeGen/AsmPrinter/DwarfUnit.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,21 +1748,18 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
17481748
// The LowerBound value defines the lower bounds which is typically zero for
17491749
// C/C++. The Count value is the number of elements. Values are 64 bit. If
17501750
// Count == -1 then the array is unbounded and we do not emit
1751-
// DW_AT_lower_bound and DW_AT_upper_bound attributes. If LowerBound == 0 and
1752-
// Count == 0, then the array has zero elements in which case we do not emit
1753-
// an upper bound.
1751+
// DW_AT_lower_bound and DW_AT_count attributes.
17541752
int64_t LowerBound = SR.getLo();
17551753
int64_t DefaultLowerBound = getDefaultLowerBound();
17561754
int64_t Count = SR.getCount();
17571755

17581756
if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
17591757
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
17601758

1761-
if (Count != -1 && Count != 0)
1759+
if (Count != -1)
17621760
// FIXME: An unbounded array should reference the expression that defines
17631761
// the array.
1764-
addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, None,
1765-
LowerBound + Count - 1);
1762+
addUInt(DW_Subrange, dwarf::DW_AT_count, None, Count);
17661763
}
17671764

17681765
/// constructArrayTypeDIE - Construct array type DIE from DICompositeType.

test/DebugInfo/X86/dbg-subrange.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
44
target triple = "x86_64-apple-macosx10.7.2"
55

66
@s = common global [4294967296 x i8] zeroinitializer, align 16
7-
;CHECK: .long 4294967295
7+
; CHECK: .quad 4294967296 ## DW_AT_count
88

99
define void @bar() nounwind uwtable ssp {
1010
entry:

test/DebugInfo/X86/empty-and-one-elem-array.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ entry:
2525

2626
declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
2727

28-
; An empty array should not have an AT_upper_bound attribute. But an array of 1
29-
; should.
30-
3128
; CHECK: DW_TAG_base_type
3229
; CHECK-NEXT: DW_AT_name [DW_FORM_strp] ( .debug_str[{{.*}}] = "int")
3330
; CHECK-NEXT: DW_AT_encoding [DW_FORM_data1] (DW_ATE_signed)
@@ -46,7 +43,7 @@ declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
4643
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
4744
; CHECK: DW_TAG_subrange_type [{{.*}}]
4845
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
49-
; CHECK-NEXT: DW_AT_upper_bound [DW_FORM_data1] (0x00)
46+
; CHECK-NEXT: DW_AT_count [DW_FORM_data1] (0x01)
5047

5148
; int bar::b[0]:
5249
; CHECK: DW_TAG_structure_type
@@ -59,9 +56,9 @@ declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
5956
; int[0]:
6057
; CHECK: DW_TAG_array_type [{{.*}}] *
6158
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
62-
; CHECK: DW_TAG_subrange_type [11]
59+
; CHECK: DW_TAG_subrange_type
6360
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4]
64-
; CHECK-NOT: DW_AT_upper_bound
61+
; CHECK: DW_AT_count [DW_FORM_data1] (0x00)
6562

6663
!llvm.dbg.cu = !{!0}
6764
!llvm.module.flags = !{!33}

test/DebugInfo/X86/nondefault-subrange-array.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
; CHECK: DW_TAG_subrange_type
2020
; CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[BASE2:0x[0-9a-f]*]]})
2121
; CHECK-NEXT: DW_AT_lower_bound [DW_FORM_data8] (0xfffffffffffffffd)
22-
; CHECK-NEXT: DW_AT_upper_bound [DW_FORM_data1] (0x26)
22+
; CHECK-NEXT: DW_AT_count [DW_FORM_data1] (0x2a)
2323

2424
; CHECK: [[BASE]]: DW_TAG_base_type
2525
; CHECK: [[BASE2]]: DW_TAG_base_type

0 commit comments

Comments
 (0)