diff options
| author | Bill Wendling <isanbard@gmail.com> | 2012-12-04 21:34:03 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2012-12-04 21:34:03 +0000 |
| commit | d7767125d5b8e12db826aa7dd761a82e63ec235b (patch) | |
| tree | b53f593b8c4cc364bcbb1e7ee12ad122618cdace /llvm/lib | |
| parent | 751afdc3d1583dab43064892c90eb864cd69cd37 (diff) | |
| download | bcm5719-llvm-d7767125d5b8e12db826aa7dd761a82e63ec235b.tar.gz bcm5719-llvm-d7767125d5b8e12db826aa7dd761a82e63ec235b.zip | |
Use the 'count' attribute to calculate the upper bound of an array.
The count attribute is more accurate with regards to the size of an array. It
also obviates the upper bound attribute in the subrange. We can also better
handle an unbound array by setting the count to -1 instead of the lower bound to
1 and upper bound to 0.
llvm-svn: 169312
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 27 | ||||
| -rw-r--r-- | llvm/lib/VMCore/DIBuilder.cpp | 4 | ||||
| -rw-r--r-- | llvm/lib/VMCore/DebugInfo.cpp | 6 |
3 files changed, 20 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index f5f36e461f1..c8807079491 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -1250,24 +1250,25 @@ void CompileUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) { DIE *DW_Subrange = new DIE(dwarf::DW_TAG_subrange_type); addDIEEntry(DW_Subrange, dwarf::DW_AT_type, dwarf::DW_FORM_ref4, IndexTy); + + // The L 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 L == 0 and Count == 0, then the array has + // zero elements in which case we do not emit an upper bound. uint64_t L = SR.getLo(); - uint64_t H = SR.getHi(); int64_t Count = SR.getCount(); - // The L value defines the lower bounds which is typically zero for C/C++. The - // H value is the upper bounds. Values are 64 bit. H - L + 1 is the size - // of the array. If L > H then do not emit DW_AT_lower_bound and - // DW_AT_upper_bound attributes. If L is zero and H is also zero then the - // array has one element and in such case do not emit lower bound. + if (Count != -1) { + // FIXME: An unbounded array should reference the expression that defines + // the array. + if (L) + addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L); - if (L > H) { - Buffer.addChild(DW_Subrange); - return; + if (Count != 0) + addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, Count - 1); } - if (L) - addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, 0, L); - if (H > 0 || Count != 0) - addUInt(DW_Subrange, dwarf::DW_AT_upper_bound, 0, H); + Buffer.addChild(DW_Subrange); } diff --git a/llvm/lib/VMCore/DIBuilder.cpp b/llvm/lib/VMCore/DIBuilder.cpp index 2b77edc7f99..b3bbde86c54 100644 --- a/llvm/lib/VMCore/DIBuilder.cpp +++ b/llvm/lib/VMCore/DIBuilder.cpp @@ -741,12 +741,10 @@ DIArray DIBuilder::getOrCreateArray(ArrayRef<Value *> Elements) { /// getOrCreateSubrange - Create a descriptor for a value range. This /// implicitly uniques the values returned. -DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Hi, - int64_t Count) { +DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_subrange_type), ConstantInt::get(Type::getInt64Ty(VMContext), Lo), - ConstantInt::get(Type::getInt64Ty(VMContext), Hi), ConstantInt::get(Type::getInt64Ty(VMContext), Count) }; diff --git a/llvm/lib/VMCore/DebugInfo.cpp b/llvm/lib/VMCore/DebugInfo.cpp index 73eb92ee846..0b43cc0beba 100644 --- a/llvm/lib/VMCore/DebugInfo.cpp +++ b/llvm/lib/VMCore/DebugInfo.cpp @@ -1049,7 +1049,11 @@ void DIDescriptor::print(raw_ostream &OS) const { } void DISubrange::printInternal(raw_ostream &OS) const { - OS << " [" << getLo() << ", " << getHi() << ']'; + int64_t Count = getCount(); + if (Count != -1) + OS << " [" << getLo() << ", " << Count - 1 << ']'; + else + OS << " [unbound]"; } void DIScope::printInternal(raw_ostream &OS) const { |

