r183875 - Simplify: we don't need any special-case lifetime extension when initializing

Richard Smith richard-llvm at metafoo.co.uk
Wed Jun 12 16:38:09 PDT 2013


Author: rsmith
Date: Wed Jun 12 18:38:09 2013
New Revision: 183875

URL: http://llvm.org/viewvc/llvm-project?rev=183875&view=rev
Log:
Simplify: we don't need any special-case lifetime extension when initializing
declarations of reference type; they're handled by the general case handling of
MaterializeTemporaryExpr.

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Wed Jun 12 18:38:09 2013
@@ -2013,8 +2013,7 @@ void CodeGenFunction::EmitCallArg(CallAr
 
   if (E->isGLValue()) {
     assert(E->getObjectKind() == OK_Ordinary);
-    return args.add(EmitReferenceBindingToExpr(E, /*InitializedDecl=*/0),
-                    type);
+    return args.add(EmitReferenceBindingToExpr(E), type);
   }
 
   if (hasAggregateEvaluationKind(type) &&

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Wed Jun 12 18:38:09 2013
@@ -1160,7 +1160,7 @@ void CodeGenFunction::EmitExprAsInit(con
   QualType type = D->getType();
 
   if (type->isReferenceType()) {
-    RValue rvalue = EmitReferenceBindingToExpr(init, D);
+    RValue rvalue = EmitReferenceBindingToExpr(init);
     if (capturedByInit)
       drillIntoBlockVariable(*this, lvalue, cast<VarDecl>(D));
     EmitStoreThroughLValue(rvalue, lvalue, true);

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Wed Jun 12 18:38:09 2013
@@ -149,7 +149,7 @@ void CodeGenFunction::EmitCXXGlobalVarDe
   assert(PerformInit && "cannot have constant initializer which needs "
          "destruction for reference");
   unsigned Alignment = getContext().getDeclAlign(&D).getQuantity();
-  RValue RV = EmitReferenceBindingToExpr(Init, &D);
+  RValue RV = EmitReferenceBindingToExpr(Init);
   EmitStoreOfScalar(RV.getScalarVal(), DeclPtr, false, Alignment, T);
 }
 

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Jun 12 18:38:09 2013
@@ -309,40 +309,22 @@ createReferenceTemporary(CodeGenFunction
   llvm_unreachable("unknown storage duration");
 }
 
-static llvm::Value *
-emitExprForReferenceBinding(CodeGenFunction &CGF, const Expr *E,
-                            const NamedDecl *InitializedDecl) {
-  if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(E)) {
-    CGF.enterFullExpression(EWC);
-    CodeGenFunction::RunCleanupsScope Scope(CGF);
-    return emitExprForReferenceBinding(CGF, EWC->getSubExpr(), InitializedDecl);
-  }
-
-  const MaterializeTemporaryExpr *M = 0;
-  E = E->findMaterializedTemporary(M);
-
-  if (E->isGLValue()) {
-    // Emit the expression as an lvalue.
-    LValue LV = CGF.EmitLValue(E);
-    assert(LV.isSimple());
-    return LV.getAddress();
-  }
-
-  assert(M && "prvalue reference initializer but not a materialized temporary");
+LValue CodeGenFunction::EmitMaterializeTemporaryExpr(
+                                           const MaterializeTemporaryExpr *M) {
+  const Expr *E = M->GetTemporaryExpr();
 
-  if (CGF.getLangOpts().ObjCAutoRefCount &&
+  if (getLangOpts().ObjCAutoRefCount &&
       M->getType()->isObjCLifetimeType() &&
       M->getType().getObjCLifetime() != Qualifiers::OCL_None &&
       M->getType().getObjCLifetime() != Qualifiers::OCL_ExplicitNone) {
     // FIXME: Fold this into the general case below.
-    llvm::Value *Object = createReferenceTemporary(CGF, M, E);
-    LValue RefTempDst = CGF.MakeAddrLValue(Object, M->getType());
+    llvm::Value *Object = createReferenceTemporary(*this, M, E);
+    LValue RefTempDst = MakeAddrLValue(Object, M->getType());
 
-    CGF.EmitScalarInit(E, dyn_cast_or_null<ValueDecl>(InitializedDecl),
-                       RefTempDst, false);
+    EmitScalarInit(E, M->getExtendingDecl(), RefTempDst, false);
 
-    pushTemporaryCleanup(CGF, M, E, Object);
-    return Object;
+    pushTemporaryCleanup(*this, M, E, Object);
+    return RefTempDst;
   }
 
   SmallVector<const Expr *, 2> CommaLHSs;
@@ -350,19 +332,19 @@ emitExprForReferenceBinding(CodeGenFunct
   E = E->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
 
   for (unsigned I = 0, N = CommaLHSs.size(); I != N; ++I)
-    CGF.EmitIgnoredExpr(CommaLHSs[I]);
+    EmitIgnoredExpr(CommaLHSs[I]);
 
   if (const OpaqueValueExpr *opaque = dyn_cast<OpaqueValueExpr>(E)) {
     if (opaque->getType()->isRecordType()) {
       assert(Adjustments.empty());
-      return CGF.EmitOpaqueValueLValue(opaque).getAddress();
+      return EmitOpaqueValueLValue(opaque);
     }
   }
 
   // Create and initialize the reference temporary.
-  llvm::Value *Object = createReferenceTemporary(CGF, M, E);
-  CGF.EmitAnyExprToMem(E, Object, Qualifiers(), /*IsInit*/true);
-  pushTemporaryCleanup(CGF, M, E, Object);
+  llvm::Value *Object = createReferenceTemporary(*this, M, E);
+  EmitAnyExprToMem(E, Object, Qualifiers(), /*IsInit*/true);
+  pushTemporaryCleanup(*this, M, E, Object);
 
   // Perform derived-to-base casts and/or field accesses, to get from the
   // temporary object we created (and, potentially, for which we extended
@@ -372,16 +354,15 @@ emitExprForReferenceBinding(CodeGenFunct
     switch (Adjustment.Kind) {
     case SubobjectAdjustment::DerivedToBaseAdjustment:
       Object =
-          CGF.GetAddressOfBaseClass(Object,
-                                    Adjustment.DerivedToBase.DerivedClass,
-                          Adjustment.DerivedToBase.BasePath->path_begin(),
-                          Adjustment.DerivedToBase.BasePath->path_end(),
-                                    /*NullCheckValue=*/false);
+          GetAddressOfBaseClass(Object, Adjustment.DerivedToBase.DerivedClass,
+                                Adjustment.DerivedToBase.BasePath->path_begin(),
+                                Adjustment.DerivedToBase.BasePath->path_end(),
+                                /*NullCheckValue=*/ false);
       break;
 
     case SubobjectAdjustment::FieldAdjustment: {
-      LValue LV = CGF.MakeAddrLValue(Object, E->getType());
-      LV = CGF.EmitLValueForField(LV, Adjustment.Field);
+      LValue LV = MakeAddrLValue(Object, E->getType());
+      LV = EmitLValueForField(LV, Adjustment.Field);
       assert(LV.isSimple() &&
              "materialized temporary field is not a simple lvalue");
       Object = LV.getAddress();
@@ -389,21 +370,23 @@ emitExprForReferenceBinding(CodeGenFunct
     }
 
     case SubobjectAdjustment::MemberPointerAdjustment: {
-      llvm::Value *Ptr = CGF.EmitScalarExpr(Adjustment.Ptr.RHS);
-      Object = CGF.CGM.getCXXABI().EmitMemberDataPointerAddress(
-                    CGF, Object, Ptr, Adjustment.Ptr.MPT);
+      llvm::Value *Ptr = EmitScalarExpr(Adjustment.Ptr.RHS);
+      Object = CGM.getCXXABI().EmitMemberDataPointerAddress(
+                    *this, Object, Ptr, Adjustment.Ptr.MPT);
       break;
     }
     }
   }
 
-  return Object;
+  return MakeAddrLValue(Object, M->getType());
 }
 
 RValue
-CodeGenFunction::EmitReferenceBindingToExpr(const Expr *E,
-                                            const NamedDecl *InitializedDecl) {
-  llvm::Value *Value = emitExprForReferenceBinding(*this, E, InitializedDecl);
+CodeGenFunction::EmitReferenceBindingToExpr(const Expr *E) {
+  // Emit the expression as an lvalue.
+  LValue LV = EmitLValue(E);
+  assert(LV.isSimple());
+  llvm::Value *Value = LV.getAddress();
 
   if (SanitizePerformTypeCheck && !E->getType()->isFunctionType()) {
     // C++11 [dcl.ref]p5 (as amended by core issue 453):
@@ -2831,12 +2814,6 @@ LValue CodeGenFunction::EmitOpaqueValueL
   return getOpaqueLValueMapping(e);
 }
 
-LValue CodeGenFunction::EmitMaterializeTemporaryExpr(
-                                           const MaterializeTemporaryExpr *E) {
-  RValue RV = EmitReferenceBindingToExpr(E, /*InitializedDecl=*/0);
-  return MakeAddrLValue(RV.getScalarVal(), E->getType());
-}
-
 RValue CodeGenFunction::EmitRValueForField(LValue LV,
                                            const FieldDecl *FD) {
   QualType FT = FD->getType();

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Jun 12 18:38:09 2013
@@ -1062,7 +1062,7 @@ AggExprEmitter::EmitInitializationToLVal
   } else if (isa<ImplicitValueInitExpr>(E) || isa<CXXScalarValueInitExpr>(E)) {
     return EmitNullInitializationToLValue(LV);
   } else if (type->isReferenceType()) {
-    RValue RV = CGF.EmitReferenceBindingToExpr(E, /*InitializedDecl=*/0);
+    RValue RV = CGF.EmitReferenceBindingToExpr(E);
     return CGF.EmitStoreThroughLValue(RV, LV);
   }
   

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Wed Jun 12 18:38:09 2013
@@ -840,7 +840,7 @@ void CodeGenFunction::EmitReturnStmt(con
   } else if (FnRetTy->isReferenceType()) {
     // If this function returns a reference, take the address of the expression
     // rather than the value.
-    RValue Result = EmitReferenceBindingToExpr(RV, /*InitializedDecl=*/0);
+    RValue Result = EmitReferenceBindingToExpr(RV);
     Builder.CreateStore(Result.getScalarVal(), ReturnValue);
   } else {
     switch (getEvaluationKind(RV->getType())) {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=183875&r1=183874&r2=183875&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Jun 12 18:38:09 2013
@@ -2238,10 +2238,8 @@ public:
   void EmitObjCAutoreleasePoolCleanup(llvm::Value *Ptr);
   void EmitObjCMRRAutoreleasePoolPop(llvm::Value *Ptr); 
 
-  /// EmitReferenceBindingToExpr - Emits a reference binding to the passed in
-  /// expression. Will emit a temporary variable if E is not an LValue.
-  RValue EmitReferenceBindingToExpr(const Expr* E,
-                                    const NamedDecl *InitializedDecl);
+  /// \brief Emits a reference binding to the passed in expression.
+  RValue EmitReferenceBindingToExpr(const Expr *E);
 
   //===--------------------------------------------------------------------===//
   //                           Expression Emission





More information about the cfe-commits mailing list