]> granicus.if.org Git - clang/commitdiff
Convert CGBitFieldInfo::FieldByteOffset to CharUnits. No change in
authorKen Dyck <kd@kendyck.com>
Sun, 24 Apr 2011 10:04:59 +0000 (10:04 +0000)
committerKen Dyck <kd@kendyck.com>
Sun, 24 Apr 2011 10:04:59 +0000 (10:04 +0000)
functionality intended.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130085 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
lib/CodeGen/CGRecordLayout.h
lib/CodeGen/CGRecordLayoutBuilder.cpp

index e0935ac0397f9f388ed495bac50ea86f67fb9ceb..892e9a34584788aa3c78f89388ddf5b443473f89 100644 (file)
@@ -726,9 +726,10 @@ RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV,
       Ptr = Builder.CreateStructGEP(Ptr, AI.FieldIndex, "bf.field");
 
     // Offset by the byte offset, if used.
-    if (AI.FieldByteOffset) {
+    if (!AI.FieldByteOffset.isZero()) {
       Ptr = EmitCastToVoidPtr(Ptr);
-      Ptr = Builder.CreateConstGEP1_32(Ptr, AI.FieldByteOffset,"bf.field.offs");
+      Ptr = Builder.CreateConstGEP1_32(Ptr, AI.FieldByteOffset.getQuantity(),
+                                       "bf.field.offs");
     }
 
     // Cast to the access type.
@@ -929,9 +930,10 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
       Ptr = Builder.CreateStructGEP(Ptr, AI.FieldIndex, "bf.field");
 
     // Offset by the byte offset, if used.
-    if (AI.FieldByteOffset) {
+    if (!AI.FieldByteOffset.isZero()) {
       Ptr = EmitCastToVoidPtr(Ptr);
-      Ptr = Builder.CreateConstGEP1_32(Ptr, AI.FieldByteOffset,"bf.field.offs");
+      Ptr = Builder.CreateConstGEP1_32(Ptr, AI.FieldByteOffset.getQuantity(),
+                                       "bf.field.offs");
     }
 
     // Cast to the access type.
index 30da05f421fe30b57ef2b4082667d0c78c8bafe9..245e74ce76a3bd247c50dbf1bce83fa9cd2a136b 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/DerivedTypes.h"
+#include "clang/AST/CharUnits.h"
 #include "clang/AST/Decl.h"
 namespace llvm {
   class raw_ostream;
@@ -53,7 +54,7 @@ public:
     /// unused as the cleanest IR comes from having a well-constructed LLVM type
     /// with proper GEP instructions, but sometimes its use is required, for
     /// example if an access is intended to straddle an LLVM field boundary.
-    unsigned FieldByteOffset;
+    CharUnits FieldByteOffset;
 
     /// Bit offset in the accessed value to use. The width is implied by \see
     /// TargetBitWidth.
index 5a8115639d3f7e4e6cbbdcf5ce7c37778186e2c1..7f52e31068000d8d4a85e54a662a06d11f9434ce 100644 (file)
@@ -309,9 +309,10 @@ CGBitFieldInfo CGBitFieldInfo::MakeInfo(CodeGenTypes &Types,
     // in higher bits. But this also reverts the bytes, so fix this here by reverting
     // the byte offset on big-endian machines.
     if (Types.getTargetData().isBigEndian()) {
-      AI.FieldByteOffset = (ContainingTypeSizeInBits - AccessStart - AccessWidth )/8;
+      AI.FieldByteOffset = Types.getContext().toCharUnitsFromBits(
+          ContainingTypeSizeInBits - AccessStart - AccessWidth);
     } else {
-      AI.FieldByteOffset = AccessStart / 8;
+      AI.FieldByteOffset = Types.getContext().toCharUnitsFromBits(AccessStart);
     }
     AI.FieldBitStart = AccessBitsInFieldStart - AccessStart;
     AI.AccessWidth = AccessWidth;
@@ -978,7 +979,7 @@ CGRecordLayout *CodeGenTypes::ComputeRecordLayout(const RecordDecl *D) {
       // Verify that every component access is within the structure.
       uint64_t FieldOffset = SL->getElementOffsetInBits(AI.FieldIndex);
       uint64_t AccessBitOffset = FieldOffset +
-        getContext().toBits(CharUnits::fromQuantity(AI.FieldByteOffset));
+        getContext().toBits(AI.FieldByteOffset);
       assert(AccessBitOffset + AI.AccessWidth <= TypeSizeInBits &&
              "Invalid bit-field access (out of range)!");
     }
@@ -1037,7 +1038,7 @@ void CGBitFieldInfo::print(llvm::raw_ostream &OS) const {
       OS.indent(8);
       OS << "<AccessInfo"
          << " FieldIndex:" << AI.FieldIndex
-         << " FieldByteOffset:" << AI.FieldByteOffset
+         << " FieldByteOffset:" << AI.FieldByteOffset.getQuantity()
          << " FieldBitStart:" << AI.FieldBitStart
          << " AccessWidth:" << AI.AccessWidth << "\n";
       OS.indent(8 + strlen("<AccessInfo"));