[cfe-commits] r101678 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/bitfield-2.c
Anders Carlsson
andersca at mac.com
Sat Apr 17 14:52:23 PDT 2010
Author: andersca
Date: Sat Apr 17 16:52:22 2010
New Revision: 101678
URL: http://llvm.org/viewvc/llvm-project?rev=101678&view=rev
Log:
Fix an assert when assigning a boolean value to a bitfield of type _Bool.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGen/bitfield-2.c
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=101678&r1=101677&r2=101678&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Apr 17 16:52:22 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/trunk/test/CodeGen/bitfield-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bitfield-2.c?rev=101678&r1=101677&r2=101678&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/bitfield-2.c (original)
+++ cfe/trunk/test/CodeGen/bitfield-2.c Sat Apr 17 16:52:22 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 cfe-commits
mailing list