summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter
diff options
context:
space:
mode:
authorMatt Davis <Matthew.Davis@sony.com>2018-03-08 22:22:26 +0000
committerMatt Davis <Matthew.Davis@sony.com>2018-03-08 22:22:26 +0000
commit4c77cb7d125058d9e29f77c7a36006d1b66f3be8 (patch)
treef3f4734ac7387e752004fc8906b65c11fb236fd7 /llvm/lib/CodeGen/AsmPrinter
parentee770e9c4eb3d5582c2628d97335278d83b2fea9 (diff)
downloadbcm5719-llvm-4c77cb7d125058d9e29f77c7a36006d1b66f3be8.tar.gz
bcm5719-llvm-4c77cb7d125058d9e29f77c7a36006d1b66f3be8.zip
[DebugInfo] Add DW_AT_byte_size to vectors
Summary: This patch adds the DW_AT_byte_size dwarf attribute to vectors. This fixes PR21924 LLVM will round a vector up to the next alignable address, which can result in the vector's representation in the object file being larger than what the debugger will calculate via NumberOfElements * ElementSize. In such a case calling sizeof(MyVec) in the source will result in a different value than what a debugger might present. This situation can occur because LLVM permits non-power of two 'vector_size' attributes. Reviewers: echristo, dexonsmith, aprantl Reviewed By: aprantl Subscribers: probinson, aprantl, llvm-commits, JDevlieghere Tags: #debug-info Differential Revision: https://reviews.llvm.org/D44048 llvm-svn: 327072
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp33
1 files changed, 32 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index 377e557f637..171de3cd5d7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1408,9 +1408,40 @@ DIE *DwarfUnit::getIndexTyDie() {
return IndexTyDie;
}
+/// Returns true if the vector's size differs from the sum of sizes of elements
+/// the user specified. This can occur if the vector has been rounded up to
+/// fit memory alignment constraints.
+static bool hasVectorBeenPadded(const DICompositeType *CTy) {
+ assert(CTy && CTy->isVector() && "Composite type is not a vector");
+ const uint64_t ActualSize = CTy->getSizeInBits();
+
+ // Obtain the size of each element in the vector.
+ DIType *BaseTy = CTy->getBaseType().resolve();
+ assert(BaseTy && "Unknown vector element type.");
+ const uint64_t ElementSize = BaseTy->getSizeInBits();
+
+ // Locate the number of elements in the vector.
+ const DINodeArray Elements = CTy->getElements();
+ assert(Elements.size() == 1 &&
+ Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
+ "Invalid vector element array, expected one element of type subrange");
+ const auto Subrange = cast<DISubrange>(Elements[0]);
+ const auto CI = Subrange->getCount().get<ConstantInt *>();
+ const int32_t NumVecElements = CI->getSExtValue();
+
+ // Ensure we found the element count and that the actual size is wide
+ // enough to contain the requested size.
+ assert(ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size");
+ return ActualSize != (NumVecElements * ElementSize);
+}
+
void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
- if (CTy->isVector())
+ if (CTy->isVector()) {
addFlag(Buffer, dwarf::DW_AT_GNU_vector);
+ if (hasVectorBeenPadded(CTy))
+ addUInt(Buffer, dwarf::DW_AT_byte_size, None,
+ CTy->getSizeInBits() / CHAR_BIT);
+ }
// Emit the element type.
addType(Buffer, resolve(CTy->getBaseType()));
OpenPOWER on IntegriCloud