diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-12-04 06:21:27 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-12-04 06:21:27 +0000 |
commit | 003ec237adbabe93d5f87d8c23b4d148b4767617 (patch) | |
tree | 7cf73896ded2295e6b631c93d908ed0e6f294e79 /lib/CodeGen/CGDebugInfo.cpp | |
parent | 5c5eaa83b3c1a6f393105a1f394e7ea422bfc839 (diff) |
Add a 'count' field to the DWARF subrange.
The count field is necessary because there isn't a difference between the 'lo'
and 'hi' attributes for a one-element array and a zero-element array. When the
count is '0', we know that this is a zero-element array. When it's >=1, then
it's a normal constant sized array. When it's -1, then the array is unbounded.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169219 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 96cfd28e54..666b6a829f 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1475,6 +1475,7 @@ llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, llvm::DIFile Unit) { 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. @@ -1482,7 +1483,8 @@ llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, llvm::DIFile Unit) { 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); @@ -1523,19 +1525,30 @@ llvm::DIType CGDebugInfo::CreateType(const ArrayType *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(); } |