diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-02-01 08:12:19 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-02-01 08:12:19 +0000 |
commit | 7f5221b023bca69a3f5fdbe03934edb74a25fa18 (patch) | |
tree | 1cb7beced5c646b13b46c4cd7bcfe0c6483b1fd0 /lib/CodeGen/CGExprConstant.cpp | |
parent | b95907d6b65ac759ac8ccd6be4f2a1f3eb389e87 (diff) |
Fix for PR3447: use padded sizes for computations on struct/union
constants.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63491 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r-- | lib/CodeGen/CGExprConstant.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 604090e2b3..838452d476 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -124,7 +124,7 @@ public: // Calculate information about the relevant field const llvm::Type* Ty = CI->getType(); const llvm::TargetData &TD = CGM.getTypes().getTargetData(); - unsigned size = TD.getTypeStoreSizeInBits(Ty); + unsigned size = TD.getTypePaddedSizeInBits(Ty); unsigned fieldOffset = CGM.getTypes().getLLVMFieldNo(Field) * size; CodeGenTypes::BitFieldInfo bitFieldInfo = CGM.getTypes().getBitFieldInfo(Field); @@ -135,11 +135,11 @@ public: // FIXME: This won't work if the struct isn't completely packed! unsigned offset = 0, i = 0; while (offset < (fieldOffset & -8)) - offset += TD.getTypeStoreSizeInBits(Elts[i++]->getType()); + offset += TD.getTypePaddedSizeInBits(Elts[i++]->getType()); // Advance over 0 sized elements (must terminate in bounds since // the bitfield must have a size). - while (TD.getTypeStoreSizeInBits(Elts[i]->getType()) == 0) + while (TD.getTypePaddedSizeInBits(Elts[i]->getType()) == 0) ++i; // Promote the size of V if necessary @@ -223,8 +223,8 @@ public: std::vector<const llvm::Type*> Types; Elts.push_back(C); Types.push_back(C->getType()); - unsigned CurSize = CGM.getTargetData().getTypeStoreSize(C->getType()); - unsigned TotalSize = CGM.getTargetData().getTypeStoreSize(Ty); + unsigned CurSize = CGM.getTargetData().getTypePaddedSize(C->getType()); + unsigned TotalSize = CGM.getTargetData().getTypePaddedSize(Ty); while (CurSize < TotalSize) { Elts.push_back(llvm::Constant::getNullValue(llvm::Type::Int8Ty)); Types.push_back(llvm::Type::Int8Ty); |