From: Eli Friedman Date: Thu, 7 May 2009 23:42:42 +0000 (+0000) Subject: Fix crash with constant initialization of bit-fields in unions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b03d9afa3f0522ca02139c9b55d1145369e32a0f;p=clang Fix crash with constant initialization of bit-fields in unions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71194 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index e618dab33e..1639ac0939 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -275,7 +275,7 @@ public: if (curField->isBitField()) { // Create a dummy struct for bit-field insertion - unsigned NumElts = CGM.getTargetData().getTypePaddedSize(Ty) / 8; + unsigned NumElts = CGM.getTargetData().getTypePaddedSize(Ty); llvm::Constant* NV = llvm::Constant::getNullValue(llvm::Type::Int8Ty); std::vector Elts(NumElts, NV); diff --git a/test/CodeGen/bitfield-init.c b/test/CodeGen/bitfield-init.c index f0cc0b1568..7459614a12 100644 --- a/test/CodeGen/bitfield-init.c +++ b/test/CodeGen/bitfield-init.c @@ -10,3 +10,5 @@ void sqlite3CodeSubselect(){ struct Token one = { 1 }; } +typedef union T0 { char field0 : 2; } T0; +T0 T0_values = { 0 };