[cfe-commits] r94798 - in /cfe/trunk: include/clang/AST/Decl.h lib/CodeGen/CGCall.cpp lib/CodeGen/CGClass.cpp lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CodeGenFunction.h

Anders Carlsson andersca at mac.com
Thu Jan 28 21:05:46 PST 2010


Author: andersca
Date: Thu Jan 28 23:05:36 2010
New Revision: 94798

URL: http://llvm.org/viewvc/llvm-project?rev=94798&view=rev
Log:
Simplify EmitLValueForField - we can get whether the field is part of a union or not from the FieldDecl (through its DeclContext).

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=94798&r1=94797&r2=94798&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Jan 28 23:05:36 2010
@@ -1351,6 +1351,16 @@
   Expr *getBitWidth() const { return BitWidth; }
   void setBitWidth(Expr *BW) { BitWidth = BW; }
 
+  /// getParent - Returns the parent of this field declaration, which
+  /// is the struct in which this method is defined.
+  const RecordDecl *getParent() const {
+    return cast<RecordDecl>(getDeclContext());
+  }
+
+  RecordDecl *getParent() {
+    return cast<RecordDecl>(getDeclContext());
+  }
+  
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const FieldDecl *D) { return true; }

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Jan 28 23:05:36 2010
@@ -258,7 +258,7 @@
     QualType FT = FD->getType();
 
     // FIXME: What are the right qualifiers here?
-    LValue LV = EmitLValueForField(Addr, FD, false, 0);
+    LValue LV = EmitLValueForField(Addr, FD, 0);
     if (CodeGenFunction::hasAggregateLLVMType(FT)) {
       AI = ExpandTypeFromArgs(FT, LV, AI);
     } else {
@@ -285,7 +285,7 @@
     QualType FT = FD->getType();
 
     // FIXME: What are the right qualifiers here?
-    LValue LV = EmitLValueForField(Addr, FD, false, 0);
+    LValue LV = EmitLValueForField(Addr, FD, 0);
     if (CodeGenFunction::hasAggregateLLVMType(FT)) {
       ExpandTypeToArgs(FT, RValue::getAggregate(LV.getAddress()), Args);
     } else {

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Jan 28 23:05:36 2010
@@ -629,8 +629,8 @@
     if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
       CXXRecordDecl *FieldClassDecl
         = cast<CXXRecordDecl>(FieldClassType->getDecl());
-      LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
-      LValue RHS = EmitLValueForField(LoadOfSrc, Field, false, 0);
+      LValue LHS = EmitLValueForField(LoadOfThis, Field, 0);
+      LValue RHS = EmitLValueForField(LoadOfSrc, Field, 0);
       if (Array) {
         const llvm::Type *BasePtr = ConvertType(FieldType);
         BasePtr = llvm::PointerType::getUnqual(BasePtr);
@@ -665,8 +665,8 @@
       continue;
     }
     // Do a built-in assignment of scalar data members.
-    LValue LHS = EmitLValueForField(LoadOfThis, Field, false, 0);
-    LValue RHS = EmitLValueForField(LoadOfSrc, Field, false, 0);
+    LValue LHS = EmitLValueForField(LoadOfThis, Field, 0);
+    LValue RHS = EmitLValueForField(LoadOfSrc, Field, 0);
 
     if (!hasAggregateLLVMType(Field->getType())) {
       RValue RVRHS = EmitLoadOfLValue(RHS, Field->getType());
@@ -745,8 +745,8 @@
     if (const RecordType *FieldClassType = FieldType->getAs<RecordType>()) {
       CXXRecordDecl *FieldClassDecl
       = cast<CXXRecordDecl>(FieldClassType->getDecl());
-      LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
-      LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
+      LValue LHS = EmitLValueForField(LoadOfThis, *Field, 0);
+      LValue RHS = EmitLValueForField(LoadOfSrc, *Field, 0);
       if (Array) {
         const llvm::Type *BasePtr = ConvertType(FieldType);
         BasePtr = llvm::PointerType::getUnqual(BasePtr);
@@ -763,8 +763,8 @@
       continue;
     }
     // Do a built-in assignment of scalar data members.
-    LValue LHS = EmitLValueForField(LoadOfThis, *Field, false, 0);
-    LValue RHS = EmitLValueForField(LoadOfSrc, *Field, false, 0);
+    LValue LHS = EmitLValueForField(LoadOfThis, *Field, 0);
+    LValue RHS = EmitLValueForField(LoadOfSrc, *Field, 0);
     if (!hasAggregateLLVMType(Field->getType())) {
       RValue RVRHS = EmitLoadOfLValue(RHS, Field->getType());
       EmitStoreThroughLValue(RVRHS, LHS, Field->getType());
@@ -854,14 +854,13 @@
     assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs");
     LHS = LValue::MakeAddr(V, CGF.MakeQualifiers(FieldType));
   } else {
-    LHS = CGF.EmitLValueForField(ThisPtr, Field, ClassDecl->isUnion(), 0);
+    LHS = CGF.EmitLValueForField(ThisPtr, Field, 0);
   }
 
   // If we are initializing an anonymous union field, drill down to the field.
   if (MemberInit->getAnonUnionMember()) {
     Field = MemberInit->getAnonUnionMember();
-    LHS = CGF.EmitLValueForField(LHS.getAddress(), Field,
-                                 /*IsUnion=*/true, 0);
+    LHS = CGF.EmitLValueForField(LHS.getAddress(), Field, 0);
     FieldType = Field->getType();
   }
 
@@ -1002,7 +1001,6 @@
     llvm::Value *ThisPtr = LoadCXXThis();
 
     LValue LHS = EmitLValueForField(ThisPtr, Field, 
-                                    /*isUnion=*/false,
                                     // FIXME: Qualifiers?
                                     /*CVRQualifiers=*/0);
     if (Array) {

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jan 28 23:05:36 2010
@@ -1383,7 +1383,6 @@
 }
 
 LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) {
-  bool isUnion = false;
   bool isNonGC = false;
   Expr *BaseExpr = E->getBase();
   llvm::Value *BaseValue = NULL;
@@ -1394,16 +1393,12 @@
     BaseValue = EmitScalarExpr(BaseExpr);
     const PointerType *PTy =
       BaseExpr->getType()->getAs<PointerType>();
-    if (PTy->getPointeeType()->isUnionType())
-      isUnion = true;
     BaseQuals = PTy->getPointeeType().getQualifiers();
   } else if (isa<ObjCPropertyRefExpr>(BaseExpr->IgnoreParens()) ||
              isa<ObjCImplicitSetterGetterRefExpr>(
                BaseExpr->IgnoreParens())) {
     RValue RV = EmitObjCPropertyGet(BaseExpr);
     BaseValue = RV.getAggregateAddr();
-    if (BaseExpr->getType()->isUnionType())
-      isUnion = true;
     BaseQuals = BaseExpr->getType().getQualifiers();
   } else {
     LValue BaseLV = EmitLValue(BaseExpr);
@@ -1412,14 +1407,12 @@
     // FIXME: this isn't right for bitfields.
     BaseValue = BaseLV.getAddress();
     QualType BaseTy = BaseExpr->getType();
-    if (BaseTy->isUnionType())
-      isUnion = true;
     BaseQuals = BaseTy.getQualifiers();
   }
 
   NamedDecl *ND = E->getMemberDecl();
   if (FieldDecl *Field = dyn_cast<FieldDecl>(ND)) {
-    LValue LV = EmitLValueForField(BaseValue, Field, isUnion,
+    LValue LV = EmitLValueForField(BaseValue, Field, 
                                    BaseQuals.getCVRQualifiers());
     LValue::SetObjCNonGC(LV, isNonGC);
     setObjCGCLValueClass(getContext(), E, LV);
@@ -1463,7 +1456,6 @@
 
 LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
                                            const FieldDecl* Field,
-                                           bool isUnion,
                                            unsigned CVRQualifiers) {
   if (Field->isBitField())
     return EmitLValueForBitfield(BaseValue, Field, CVRQualifiers);
@@ -1472,7 +1464,7 @@
   llvm::Value *V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
 
   // Match union field type.
-  if (isUnion) {
+  if (Field->getParent()->isUnion()) {
     const llvm::Type *FieldTy =
       CGM.getTypes().ConvertTypeForMem(Field->getType());
     const llvm::PointerType * BaseTy =
@@ -1850,8 +1842,7 @@
       getContext().getTypeDeclType(const_cast<CXXRecordDecl*>(ClassDecl)));
   NNSpecTy = getContext().getPointerType(NNSpecTy);
   llvm::Value *V = llvm::Constant::getNullValue(ConvertType(NNSpecTy));
-  LValue MemExpLV = EmitLValueForField(V, Field, /*isUnion=*/false, 
-                                       /*Qualifiers=*/0);
+  LValue MemExpLV = EmitLValueForField(V, Field, /*Qualifiers=*/0);
   const llvm::Type *ResultType = ConvertType(getContext().getPointerDiffType());
   V = Builder.CreatePtrToInt(MemExpLV.getAddress(), ResultType, "datamember");
   return LValue::MakeAddr(V, MakeQualifiers(Field->getType()));

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Thu Jan 28 23:05:36 2010
@@ -627,7 +627,7 @@
 
     // FIXME: volatility
     FieldDecl *Field = E->getInitializedFieldInUnion();
-    LValue FieldLoc = CGF.EmitLValueForField(DestPtr, Field, true, 0);
+    LValue FieldLoc = CGF.EmitLValueForField(DestPtr, Field, 0);
 
     if (NumInitElements) {
       // Store the initializer into the field
@@ -653,7 +653,7 @@
       continue;
 
     // FIXME: volatility
-    LValue FieldLoc = CGF.EmitLValueForField(DestPtr, *Field, false, 0);
+    LValue FieldLoc = CGF.EmitLValueForField(DestPtr, *Field, 0);
     // We never generate write-barries for initialized fields.
     LValue::SetObjCNonGC(FieldLoc, true);
     if (CurInitVal < NumInitElements) {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=94798&r1=94797&r2=94798&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Jan 28 23:05:36 2010
@@ -1013,7 +1013,7 @@
   llvm::Value *EmitIvarOffset(const ObjCInterfaceDecl *Interface,
                               const ObjCIvarDecl *Ivar);
   LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
-                            bool isUnion, unsigned CVRQualifiers);
+                            unsigned CVRQualifiers);
   LValue EmitLValueForIvar(QualType ObjectTy,
                            llvm::Value* Base, const ObjCIvarDecl *Ivar,
                            unsigned CVRQualifiers);





More information about the cfe-commits mailing list