[cfe-commits] r63491 - /cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Eli Friedman eli.friedman at gmail.com
Sun Feb 1 00:12:19 PST 2009


Author: efriedma
Date: Sun Feb  1 02:12:19 2009
New Revision: 63491

URL: http://llvm.org/viewvc/llvm-project?rev=63491&view=rev
Log:
Fix for PR3447: use padded sizes for computations on struct/union 
constants.


Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=63491&r1=63490&r2=63491&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Sun Feb  1 02:12:19 2009
@@ -124,7 +124,7 @@
     // 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 @@
     // 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 @@
     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);





More information about the cfe-commits mailing list