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

Ken Dyck kd at kendyck.com
Mon Mar 14 18:09:02 PDT 2011


Author: kjdyck
Date: Mon Mar 14 20:09:02 2011
New Revision: 127641

URL: http://llvm.org/viewvc/llvm-project?rev=127641&view=rev
Log:
Introduce a CharUnits FieldOffsetInChars variable in AppendField() to
replace some uses of FieldOffsetInBytes. The remaining uses of
FieldOffsetInBytes will be replaced once NextFieldOffsetInBytes is converted
to CharUnits. 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=127641&r1=127640&r2=127641&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Mon Mar 14 20:09:02 2011
@@ -77,7 +77,11 @@
 bool ConstStructBuilder::
 AppendField(const FieldDecl *Field, uint64_t FieldOffset,
             llvm::Constant *InitCst) {
-  uint64_t FieldOffsetInBytes = FieldOffset / 8;
+
+  const ASTContext &Context = CGM.getContext();
+
+  CharUnits FieldOffsetInChars = Context.toCharUnitsFromBits(FieldOffset);
+  uint64_t FieldOffsetInBytes = FieldOffsetInChars.getQuantity();
 
   assert(NextFieldOffsetInBytes <= FieldOffsetInBytes
          && "Field offset mismatch!");
@@ -100,9 +104,9 @@
   if (AlignedNextFieldOffsetInBytes < FieldOffsetInBytes) {
     // We need to append padding.
     AppendPadding(
-        CharUnits::fromQuantity(FieldOffsetInBytes - NextFieldOffsetInBytes));
+        FieldOffsetInChars - CharUnits::fromQuantity(NextFieldOffsetInBytes));
 
-    assert(NextFieldOffsetInBytes == FieldOffsetInBytes &&
+    assert(NextFieldOffsetInBytes == FieldOffsetInChars.getQuantity() &&
            "Did not add enough padding!");
 
     AlignedNextFieldOffsetInBytes = NextFieldOffsetInBytes;





More information about the cfe-commits mailing list