llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit);
int64_t NumElems = Ty->getNumElements();
int64_t LowerBound = 0;
+ int64_t Count = NumElems;
if (NumElems == 0)
// If number of elements are not known then this is an unbounded array.
// Use Low = 1, Hi = 0 to express such arrays.
else
--NumElems;
- llvm::Value *Subscript = DBuilder.getOrCreateSubrange(LowerBound, NumElems);
+ llvm::Value *Subscript = DBuilder.getOrCreateSubrange(LowerBound, NumElems,
+ Count);
llvm::DIArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
uint64_t Size = CGM.getContext().getTypeSize(Ty);
SmallVector<llvm::Value *, 8> Subscripts;
QualType EltTy(Ty, 0);
while ((Ty = dyn_cast<ArrayType>(EltTy))) {
+ // If the number of elements is known, then count is that number. Otherwise,
+ // it's -1. This allows us to represent a subrange with an array of 0
+ // elements, like this:
+ //
+ // struct foo {
+ // int x[0];
+ // };
int64_t UpperBound = 0;
int64_t LowerBound = 0;
+ int64_t Count = -1;
if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) {
- if (CAT->getSize().getZExtValue())
- UpperBound = CAT->getSize().getZExtValue() - 1;
- } else
+ Count = CAT->getSize().getZExtValue();
+ if (Count)
+ UpperBound = Count - 1;
+ } else {
// This is an unbounded array. Use Low = 1, Hi = 0 to express such
// arrays.
LowerBound = 1;
+ }
// FIXME: Verify this is right for VLAs.
Subscripts.push_back(DBuilder.getOrCreateSubrange(LowerBound,
- UpperBound));
+ UpperBound,
+ Count));
EltTy = Ty->getElementType();
}
--- /dev/null
+// RUN: %clang -fverbose-asm -g -O0 -S %s -o - | FileCheck %s
+// <rdar://problem/12566646>
+
+class A {
+ int x[];
+};
+A a;
+
+// CHECK: Abbrev [3] 0x2d:0x3 DW_TAG_base_type
+// CHECK-NEXT: DW_AT_byte_size
+// CHECK-NEXT: DW_AT_encoding
+// CHECK-NEXT: Abbrev [4] 0x30:0xb DW_TAG_array_type
+// CHECK-NEXT: DW_AT_type
+// CHECK-NEXT: Abbrev [5] 0x35:0x5 DW_TAG_subrange_type
+// CHECK-NEXT: DW_AT_type
+// CHECK-NEXT: End Of Children Mark