[cfe-commits] r102067 - in /cfe/trunk: lib/CodeGen/CGRecordLayoutBuilder.cpp test/CodeGen/bitfield-2.c

Daniel Dunbar daniel at zuster.org
Thu Apr 22 07:56:11 PDT 2010


Author: ddunbar
Date: Thu Apr 22 09:56:10 2010
New Revision: 102067

URL: http://llvm.org/viewvc/llvm-project?rev=102067&view=rev
Log:
IRgen: Fix case where we might generate an access component with width == 0, if
we have to narrow the access side immediately (can happen with packed,
-fno-bitfield-type-align).

Modified:
    cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
    cfe/trunk/test/CodeGen/bitfield-2.c

Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=102067&r1=102066&r2=102067&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Thu Apr 22 09:56:10 2010
@@ -215,6 +215,16 @@
       std::min(AccessWidth - (AccessBitsInFieldStart - AccessStart),
                FieldSize - (AccessBitsInFieldStart-FieldOffset));
 
+    // If we haven't accessed any target bits yet and narrowed the access size,
+    // we might not have reached any target bits yet.
+    //
+    // FIXME: This test is unnecessarily once we choose the initial acccess size
+    // more intelligently.
+    if (!AccessedTargetBits && AccessBitsInFieldSize == 0) {
+      AccessStart += AccessWidth;
+      continue;
+    }
+
     assert(NumComponents < 3 && "Unexpected number of components!");
     CGBitFieldInfo::AccessInfo &AI = Components[NumComponents++];
     AI.FieldIndex = 0;

Modified: cfe/trunk/test/CodeGen/bitfield-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bitfield-2.c?rev=102067&r1=102066&r2=102067&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/bitfield-2.c (original)
+++ cfe/trunk/test/CodeGen/bitfield-2.c Thu Apr 22 09:56:10 2010
@@ -310,3 +310,38 @@
 int f7_load(struct s7 *a0) {
   return a0->f0;
 }
+
+/***/
+
+// This is a case where we narrow the access width immediately.
+
+struct __attribute__((packed)) s8 {
+  char f0 : 4;
+  char f1;
+  int  f2 : 4;
+  char f3 : 4;
+};
+
+struct s8 g8 = { 0xF };
+
+int f8_load(struct s8 *a0) {
+  return a0->f0 ^ a0 ->f2 ^ a0->f3;
+}
+int f8_store(struct s8 *a0) {
+  return (a0->f0 = 0xFD) ^ (a0->f2 = 0xFD) ^ (a0->f3 = 0xFD);
+}
+int f8_reload(struct s8 *a0) {
+  return (a0->f0 += 0xFD) ^ (a0->f2 += 0xFD) ^ (a0->f3 += 0xFD);
+}
+
+// CHECK-OPT: define i32 @test_8()
+// CHECK-OPT:  ret i32 -3
+// CHECK-OPT: }
+unsigned test_8() {
+  struct s8 g8 = { 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef };
+  unsigned long long res = 0;
+  res ^= g8.f0 ^ g8.f2 ^ g8.f3;
+  res ^= f8_load(&g8) ^ f8_store(&g8) ^ f8_reload(&g8);
+  res ^= g8.f0 ^ g8.f2 ^ g8.f3;
+  return res;
+}





More information about the cfe-commits mailing list