diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-29 11:33:25 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-29 11:33:25 +0000 |
commit | 133e8040ca85eceb58973922d174f83958b2274f (patch) | |
tree | 139c70de3f1cc73005ffced65fec2cbe24f48f04 | |
parent | 045bf4ff82d728be5e8305670716641fb9685def (diff) | |
download | bcm5719-llvm-133e8040ca85eceb58973922d174f83958b2274f.tar.gz bcm5719-llvm-133e8040ca85eceb58973922d174f83958b2274f.zip |
Rearrange EmitLValueForField a bit to work properly for _Bool bitfields
in unions (we don't want to do the union-specific bitcast for
bit-fields).
llvm-svn: 51678
-rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 19 | ||||
-rw-r--r-- | clang/test/CodeGen/union.c | 3 |
2 files changed, 12 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index d715b452297..f657d8f2888 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -557,9 +557,7 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue, llvm::Value *V; unsigned idx = CGM.getTypes().getLLVMFieldNo(Field); - if (!Field->isBitField()) { - V = Builder.CreateStructGEP(BaseValue, idx, "tmp"); - } else { + if (Field->isBitField()) { // FIXME: CodeGenTypes should expose a method to get the appropriate // type for FieldTy (the appropriate type is ABI-dependent). unsigned EltTySize = @@ -574,8 +572,15 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue, V = Builder.CreateGEP(BaseValue, llvm::ConstantInt::get(llvm::Type::Int32Ty, idx), "tmp"); + + CodeGenTypes::BitFieldInfo bitFieldInfo = + CGM.getTypes().getBitFieldInfo(Field); + return LValue::MakeBitfield(V, bitFieldInfo.Begin, bitFieldInfo.Size, + Field->getType()->isSignedIntegerType()); } + V = Builder.CreateStructGEP(BaseValue, idx, "tmp"); + // Match union field type. if (isUnion) { const llvm::Type * FieldTy = ConvertType(Field->getType()); @@ -587,13 +592,7 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue, "tmp"); } - if (!Field->isBitField()) - return LValue::MakeAddr(V); - - CodeGenTypes::BitFieldInfo bitFieldInfo = - CGM.getTypes().getBitFieldInfo(Field); - return LValue::MakeBitfield(V, bitFieldInfo.Begin, bitFieldInfo.Size, - Field->getType()->isSignedIntegerType()); + return LValue::MakeAddr(V); } LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E) { diff --git a/clang/test/CodeGen/union.c b/clang/test/CodeGen/union.c index 1e4346d471f..616cf56ece8 100644 --- a/clang/test/CodeGen/union.c +++ b/clang/test/CodeGen/union.c @@ -36,3 +36,6 @@ typedef union{ } q; int qfunc() {q buf; unsigned char* x = buf.x;} +union RR {_Bool a : 1;} RRU; +int RRF(void) {return RRU.a;} + |