[llvm-branch-commits] [cfe-branch] r102084 - in /cfe/branches/Apple/williamson: lib/CodeGen/CGRecordLayoutBuilder.cpp test/CodeGen/bitfield-2.c
Daniel Dunbar
daniel at zuster.org
Thu Apr 22 10:18:05 PDT 2010
Author: ddunbar
Date: Thu Apr 22 12:18:05 2010
New Revision: 102084
URL: http://llvm.org/viewvc/llvm-project?rev=102084&view=rev
Log:
IRgen: Always use i8 arrays to access union bit-fields. This is ugly, but matches how we currently handle structs, and this correctly handles -fno-bitfield-type-align.
Modified:
cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp
cfe/branches/Apple/williamson/test/CodeGen/bitfield-2.c
Modified: cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=102084&r1=102083&r2=102084&view=diff
==============================================================================
--- cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/branches/Apple/williamson/lib/CodeGen/CGRecordLayoutBuilder.cpp Thu Apr 22 12:18:05 2010
@@ -323,28 +323,19 @@
if (FieldSize == 0)
return 0;
- const llvm::Type *FieldTy;
+ const llvm::Type *FieldTy = llvm::Type::getInt8Ty(Types.getLLVMContext());
+ unsigned NumBytesToAppend =
+ llvm::RoundUpToAlignment(FieldSize, 8) / 8;
+
+ if (NumBytesToAppend > 1)
+ FieldTy = llvm::ArrayType::get(FieldTy, NumBytesToAppend);
- if (!Field->getDeclName()) {
- // This is an unnamed bit-field, which shouldn't affect alignment on the
- // struct so we use an array of bytes for it.
-
- FieldTy = llvm::Type::getInt8Ty(Types.getLLVMContext());
-
- unsigned NumBytesToAppend =
- llvm::RoundUpToAlignment(FieldSize, 8) / 8;
-
- if (NumBytesToAppend > 1)
- FieldTy = llvm::ArrayType::get(FieldTy, NumBytesToAppend);
- } else
- FieldTy = Types.ConvertTypeForMemRecursive(Field->getType());
-
// Add the bit field info.
LLVMBitFields.push_back(
LLVMBitFieldInfo(Field, ComputeBitFieldInfo(Types, Field, 0, FieldSize)));
return FieldTy;
}
-
+
// This is a regular union field.
LLVMFields.push_back(LLVMFieldInfo(Field, 0));
return Types.ConvertTypeForMemRecursive(Field->getType());
Modified: cfe/branches/Apple/williamson/test/CodeGen/bitfield-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/test/CodeGen/bitfield-2.c?rev=102084&r1=102083&r2=102084&view=diff
==============================================================================
--- cfe/branches/Apple/williamson/test/CodeGen/bitfield-2.c (original)
+++ cfe/branches/Apple/williamson/test/CodeGen/bitfield-2.c Thu Apr 22 12:18:05 2010
@@ -175,7 +175,6 @@
/***/
-
struct s5 {
unsigned f0 : 2;
_Bool f1 : 1;
@@ -206,18 +205,32 @@
return res;
}
-struct A {
- _Bool b : 2;
+/***/
+
+struct s6 {
+ _Bool f0 : 2;
};
+struct s6 g6 = { 0xF };
+
+int f6_load(struct s6 *a0) {
+ return a0->f0;
+}
+int f6_store(struct s6 *a0) {
+ return a0->f0 = 0x0;
+}
+int f6_reload(struct s6 *a0) {
+ return (a0->f0 += 0xF);
+}
+
// CHECK-OPT: define zeroext i1 @test_6()
-// CHECK-OPT: ret i1 true
+// CHECK-OPT: ret i1 true
// CHECK-OPT: }
_Bool test_6() {
- struct A a;
-
- a.b = (_Bool)0;
-
- return (a.b = !a.b);
+ struct s6 g6 = { 0xF };
+ unsigned long long res = 0;
+ res ^= g6.f0;
+ res ^= f6_load(&g6);
+ res ^= g6.f0;
+ return res;
}
-
More information about the llvm-branch-commits
mailing list