[cfe-commits] r51678 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/union.c

Eli Friedman eli.friedman at gmail.com
Thu May 29 04:33:35 PDT 2008


Author: efriedma
Date: Thu May 29 06:33:25 2008
New Revision: 51678

URL: http://llvm.org/viewvc/llvm-project?rev=51678&view=rev
Log:
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).


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGen/union.c

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=51678&r1=51677&r2=51678&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu May 29 06:33:25 2008
@@ -557,9 +557,7 @@
   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 @@
     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 @@
                               "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) {

Modified: cfe/trunk/test/CodeGen/union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/union.c?rev=51678&r1=51677&r2=51678&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/union.c (original)
+++ cfe/trunk/test/CodeGen/union.c Thu May 29 06:33:25 2008
@@ -36,3 +36,6 @@
 } q;
 int qfunc() {q buf; unsigned char* x = buf.x;}
 
+union RR {_Bool a : 1;} RRU;
+int RRF(void) {return RRU.a;}
+





More information about the cfe-commits mailing list