[llvm-branch-commits] [cfe-branch] r102079 - in /cfe/branches/Apple/williamson: lib/CodeGen/CGExpr.cpp test/CodeGen/bitfield-2.c
Daniel Dunbar
daniel at zuster.org
Thu Apr 22 10:01:32 PDT 2010
Author: ddunbar
Date: Thu Apr 22 12:01:32 2010
New Revision: 102079
URL: http://llvm.org/viewvc/llvm-project?rev=102079&view=rev
Log:
Fix an assert when assigning a boolean value to a bitfield of type _Bool.
Modified:
cfe/branches/Apple/williamson/lib/CodeGen/CGExpr.cpp
cfe/branches/Apple/williamson/test/CodeGen/bitfield-2.c
Modified: cfe/branches/Apple/williamson/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/lib/CodeGen/CGExpr.cpp?rev=102079&r1=102078&r2=102079&view=diff
==============================================================================
--- cfe/branches/Apple/williamson/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/branches/Apple/williamson/lib/CodeGen/CGExpr.cpp Thu Apr 22 12:01:32 2010
@@ -792,11 +792,15 @@
const CGBitFieldInfo &Info = Dst.getBitFieldInfo();
// Get the output type.
- const llvm::Type *ResLTy = ConvertType(Ty);
+ const llvm::Type *ResLTy = ConvertTypeForMem(Ty);
unsigned ResSizeInBits = CGM.getTargetData().getTypeSizeInBits(ResLTy);
// Get the source value, truncated to the width of the bit-field.
llvm::Value *SrcVal = Src.getScalarVal();
+
+ if (Ty->isBooleanType())
+ SrcVal = Builder.CreateIntCast(SrcVal, ResLTy, /*IsSigned=*/false);
+
SrcVal = Builder.CreateAnd(SrcVal, llvm::APInt::getLowBitsSet(ResSizeInBits,
Info.getSize()),
"bf.value");
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=102079&r1=102078&r2=102079&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:01:32 2010
@@ -205,3 +205,19 @@
res ^= g5.f0 ^ g5.f1 ^ g5.f2;
return res;
}
+
+struct A {
+ _Bool b : 2;
+};
+
+// CHECK-OPT: define zeroext i1 @test_6()
+// CHECK-OPT: ret i1 true
+// CHECK-OPT: }
+_Bool test_6() {
+ struct A a;
+
+ a.b = (_Bool)0;
+
+ return (a.b = !a.b);
+}
+
More information about the llvm-branch-commits
mailing list