[llvm-branch-commits] [cfe-branch] r112956 - in /cfe/branches/Apple/whitney-IB/src/tools/clang: ./ lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/bitfield-access.m

Daniel Dunbar daniel at zuster.org
Fri Sep 3 07:55:15 PDT 2010


Author: ddunbar
Date: Fri Sep  3 09:55:15 2010
New Revision: 112956

URL: http://llvm.org/viewvc/llvm-project?rev=112956&view=rev
Log:
--- Merging r112914 into 'src/tools/clang':
A    src/tools/clang/test/CodeGenObjC/bitfield-access.m
U    src/tools/clang/lib/CodeGen/CGObjCMac.cpp
--- Merging r112917 into 'src/tools/clang':
U    src/tools/clang/test/CodeGenObjC/bitfield-access.m


Added:
    cfe/branches/Apple/whitney-IB/src/tools/clang/test/CodeGenObjC/bitfield-access.m
      - copied, changed from r112914, cfe/trunk/test/CodeGenObjC/bitfield-access.m
Modified:
    cfe/branches/Apple/whitney-IB/src/tools/clang/   (props changed)
    cfe/branches/Apple/whitney-IB/src/tools/clang/lib/CodeGen/CGObjCMac.cpp

Propchange: cfe/branches/Apple/whitney-IB/src/tools/clang/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Sep  3 09:55:15 2010
@@ -1,2 +1,2 @@
-/cfe/trunk:112263,112268,112274
+/cfe/trunk:112263,112268,112274,112914,112917
 /llvm/branches/Apple/Pertwee/tools/clang:110850,110961

Modified: cfe/branches/Apple/whitney-IB/src/tools/clang/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/lib/CodeGen/CGObjCMac.cpp?rev=112956&r1=112955&r2=112956&view=diff
==============================================================================
--- cfe/branches/Apple/whitney-IB/src/tools/clang/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/lib/CodeGen/CGObjCMac.cpp Fri Sep  3 09:55:15 2010
@@ -113,11 +113,27 @@
     return LV;
   }
 
-  // We need to compute the bit offset for the bit-field, the offset is to the
-  // byte. Note, there is a subtle invariant here: we can only call this routine
-  // on non-synthesized ivars but we may be called for synthesized ivars.
-  // However, a synthesized ivar can never be a bit-field, so this is safe.
-  uint64_t BitOffset = LookupFieldBitOffset(CGF.CGM, OID, 0, Ivar) % 8;
+  // We need to compute an access strategy for this bit-field. We are given the
+  // offset to the first byte in the bit-field, the sub-byte offset is taken
+  // from the original layout. We reuse the normal bit-field access strategy by
+  // treating this as an access to a struct where the bit-field is in byte 0,
+  // and adjust the containing type size as appropriate.
+  //
+  // FIXME: Note that currently we make a very conservative estimate of the
+  // alignment of the bit-field, because (a) it is not clear what guarantees the
+  // runtime makes us, and (b) we don't have a way to specify that the struct is
+  // at an alignment plus offset.
+  //
+  // Note, there is a subtle invariant here: we can only call this routine on
+  // non-synthesized ivars but we may be called for synthesized ivars.  However,
+  // a synthesized ivar can never be a bit-field, so this is safe.
+  const ASTRecordLayout &RL =
+    CGF.CGM.getContext().getASTObjCInterfaceLayout(OID);
+  uint64_t TypeSizeInBits = RL.getSize();
+  uint64_t FieldBitOffset = LookupFieldBitOffset(CGF.CGM, OID, 0, Ivar);
+  uint64_t BitOffset = FieldBitOffset % 8;
+  uint64_t ContainingTypeAlign = 8;
+  uint64_t ContainingTypeSize = TypeSizeInBits - (FieldBitOffset - BitOffset);
   uint64_t BitFieldSize =
     Ivar->getBitWidth()->EvaluateAsInt(CGF.getContext()).getZExtValue();
 
@@ -127,23 +143,10 @@
   // layout object. However, this is blocked on other cleanups to the
   // Objective-C code, so for now we just live with allocating a bunch of these
   // objects.
+  CGBitFieldInfo *Info = new (CGF.CGM.getContext()) CGBitFieldInfo(
+    CGBitFieldInfo::MakeInfo(CGF.CGM.getTypes(), Ivar, BitOffset, BitFieldSize,
+                             ContainingTypeSize, ContainingTypeAlign));
 
-  // We always construct a single, possibly unaligned, access for this case.
-  CGBitFieldInfo::AccessInfo AI;
-  AI.FieldIndex = 0;
-  AI.FieldByteOffset = 0;
-  AI.FieldBitStart = BitOffset;
-  AI.AccessWidth = CGF.CGM.getContext().getTypeSize(IvarTy);
-  AI.AccessAlignment = 0;
-  AI.TargetBitOffset = 0;
-  AI.TargetBitWidth = BitFieldSize;
-
-  CGBitFieldInfo *Info =
-    new (CGF.CGM.getContext()) CGBitFieldInfo(BitFieldSize, 1, &AI,
-                                              IvarTy->isSignedIntegerType());
-
-  // FIXME: We need to set a very conservative alignment on this, or make sure
-  // that the runtime is doing the right thing.
   return LValue::MakeBitfield(V, *Info,
                               IvarTy.getCVRQualifiers() | CVRQualifiers);
 }

Copied: cfe/branches/Apple/whitney-IB/src/tools/clang/test/CodeGenObjC/bitfield-access.m (from r112914, cfe/trunk/test/CodeGenObjC/bitfield-access.m)
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney-IB/src/tools/clang/test/CodeGenObjC/bitfield-access.m?p2=cfe/branches/Apple/whitney-IB/src/tools/clang/test/CodeGenObjC/bitfield-access.m&p1=cfe/trunk/test/CodeGenObjC/bitfield-access.m&r1=112914&r2=112956&rev=112956&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/bitfield-access.m (original)
+++ cfe/branches/Apple/whitney-IB/src/tools/clang/test/CodeGenObjC/bitfield-access.m Fri Sep  3 09:55:15 2010
@@ -28,7 +28,7 @@
 // CHECK-ARM:    [[t1_base:%.*]] = bitcast i8* [[t1_ptr]] to i32*
 // CHECK-ARM:    [[t1_0:%.*]] = load i32* [[t1_base]], align 1
 // CHECK-ARM:    lshr i32 [[t1_0]], 1
-// CHECK-ARM:    [[t1_base_2_cast:%.*]] = bitcast i32* %1 to i8*
+// CHECK-ARM:    [[t1_base_2_cast:%.*]] = bitcast i32* %{{.*}} to i8*
 // CHECK-ARM:    [[t1_base_2:%.*]] = getelementptr i8* [[t1_base_2_cast]]
 // CHECK-ARM:    [[t1_1:%.*]] = load i8* [[t1_base_2]], align 1
 // CHECK-ARM:    and i8 [[t1_1:%.*]], 1





More information about the llvm-branch-commits mailing list