]> granicus.if.org Git - clang/commitdiff
Add a new EmitLValueForFieldInitialization that will be used for initializing fields...
authorAnders Carlsson <andersca@mac.com>
Fri, 29 Jan 2010 05:24:29 +0000 (05:24 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 29 Jan 2010 05:24:29 +0000 (05:24 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94799 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGClass.cpp
lib/CodeGen/CGExpr.cpp
lib/CodeGen/CodeGenFunction.h

index 2af3a15cdb6a4b5e885259e2e8068a8940c1ef28..7e78e7df52ec4067e048974aede192333123490d 100644 (file)
@@ -846,17 +846,8 @@ static void EmitMemberInitializer(CodeGenFunction &CGF,
   QualType FieldType = CGF.getContext().getCanonicalType(Field->getType());
 
   llvm::Value *ThisPtr = CGF.LoadCXXThis();
-  LValue LHS;
-  if (FieldType->isReferenceType()) {
-    // FIXME: This is really ugly; should be refactored somehow
-    unsigned idx = CGF.CGM.getTypes().getLLVMFieldNo(Field);
-    llvm::Value *V = CGF.Builder.CreateStructGEP(ThisPtr, idx, "tmp");
-    assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs");
-    LHS = LValue::MakeAddr(V, CGF.MakeQualifiers(FieldType));
-  } else {
-    LHS = CGF.EmitLValueForField(ThisPtr, Field, 0);
-  }
-
+  LValue LHS = CGF.EmitLValueForFieldInitialization(ThisPtr, Field, 0);
+  
   // If we are initializing an anonymous union field, drill down to the field.
   if (MemberInit->getAnonUnionMember()) {
     Field = MemberInit->getAnonUnionMember();
index da85626b86fe6a94a274560544645dd32956d3ca..605f77975f9587dc0c480c0aafcba2c3d684ef50 100644 (file)
@@ -1486,6 +1486,23 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
   return LValue::MakeAddr(V, Quals);
 }
 
+LValue 
+CodeGenFunction::EmitLValueForFieldInitialization(llvm::Value* BaseValue, 
+                                                  const FieldDecl* Field,
+                                                  unsigned CVRQualifiers) {
+  QualType FieldType = Field->getType();
+  
+  if (!FieldType->isReferenceType())
+    return EmitLValueForField(BaseValue, Field, CVRQualifiers);
+
+  unsigned idx = CGM.getTypes().getLLVMFieldNo(Field);
+  llvm::Value *V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
+
+  assert(!FieldType.getObjCGCAttr() && "fields cannot have GC attrs");
+
+  return LValue::MakeAddr(V, MakeQualifiers(FieldType));
+}
+
 LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E){
   const llvm::Type *LTy = ConvertType(E->getType());
   llvm::Value *DeclPtr = CreateTempAlloca(LTy, ".compoundliteral");
index 98e00ba04733171331d84a44534be4e508dac4a1..734e475fef41adcc071bb9bbfcf6ac289ebdcbfe 100644 (file)
@@ -1014,6 +1014,14 @@ public:
                               const ObjCIvarDecl *Ivar);
   LValue EmitLValueForField(llvm::Value* Base, const FieldDecl* Field,
                             unsigned CVRQualifiers);
+  
+  /// EmitLValueForFieldInitialization - Like EmitLValueForField, except that
+  /// if the Field is a reference, this will return the address of the reference
+  /// and not the address of the value stored in the reference.
+  LValue EmitLValueForFieldInitialization(llvm::Value* Base, 
+                                          const FieldDecl* Field,
+                                          unsigned CVRQualifiers);
+  
   LValue EmitLValueForIvar(QualType ObjectTy,
                            llvm::Value* Base, const ObjCIvarDecl *Ivar,
                            unsigned CVRQualifiers);