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

Ken Dyck kd at kendyck.com
Thu Mar 17 17:55:06 PDT 2011


Author: kjdyck
Date: Thu Mar 17 19:55:06 2011
New Revision: 127844

URL: http://llvm.org/viewvc/llvm-project?rev=127844&view=rev
Log:
Convert variables to CharUnits in ConvertStructToPacked(). No change in
functionality intended.

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=127844&r1=127843&r2=127844&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Thu Mar 17 19:55:06 2011
@@ -297,36 +297,36 @@
 
 void ConstStructBuilder::ConvertStructToPacked() {
   std::vector<llvm::Constant *> PackedElements;
-  uint64_t ElementOffsetInBytes = 0;
+  CharUnits ElementOffsetInChars = CharUnits::Zero();
 
   for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
     llvm::Constant *C = Elements[i];
 
     unsigned ElementAlign =
       CGM.getTargetData().getABITypeAlignment(C->getType());
-    uint64_t AlignedElementOffsetInBytes =
-      llvm::RoundUpToAlignment(ElementOffsetInBytes, ElementAlign);
+    CharUnits AlignedElementOffsetInChars =
+      ElementOffsetInChars.RoundUpToAlignment(
+          CharUnits::fromQuantity(ElementAlign));
 
-    if (AlignedElementOffsetInBytes > ElementOffsetInBytes) {
+    if (AlignedElementOffsetInChars > ElementOffsetInChars) {
       // We need some padding.
-      uint64_t NumBytes =
-        AlignedElementOffsetInBytes - ElementOffsetInBytes;
+      CharUnits NumChars =
+        AlignedElementOffsetInChars - ElementOffsetInChars;
 
       const llvm::Type *Ty = llvm::Type::getInt8Ty(CGM.getLLVMContext());
-      if (NumBytes > 1)
-        Ty = llvm::ArrayType::get(Ty, NumBytes);
+      if (NumChars > CharUnits::One())
+        Ty = llvm::ArrayType::get(Ty, NumChars.getQuantity());
 
       llvm::Constant *Padding = llvm::UndefValue::get(Ty);
       PackedElements.push_back(Padding);
-      ElementOffsetInBytes += getSizeInBytes(Padding);
+      ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(Padding));
     }
 
     PackedElements.push_back(C);
-    ElementOffsetInBytes += getSizeInBytes(C);
+    ElementOffsetInChars += CharUnits::fromQuantity(getSizeInBytes(C));
   }
 
-  assert(CharUnits::fromQuantity(ElementOffsetInBytes) == 
-           NextFieldOffsetInChars &&
+  assert(ElementOffsetInChars == NextFieldOffsetInChars &&
          "Packing the struct changed its size!");
 
   Elements = PackedElements;





More information about the cfe-commits mailing list