[llvm-branch-commits] [cfe-branch] r214750 - Merging r213913:

Bill Wendling isanbard at gmail.com
Mon Aug 4 11:37:32 PDT 2014


Author: void
Date: Mon Aug  4 13:37:31 2014
New Revision: 214750

URL: http://llvm.org/viewvc/llvm-project?rev=214750&view=rev
Log:
Merging r213913:
------------------------------------------------------------------------
r213913 | rsmith | 2014-07-24 18:12:44 -0700 (Thu, 24 Jul 2014) | 4 lines

PR20445: Properly transform the initializer in a CXXNewExpr rather than running
it through the normal TreeTransform logic for Exprs (which will strip off
implicit parts of the initialization and never re-create them).

------------------------------------------------------------------------

Modified:
    cfe/branches/release_35/   (props changed)
    cfe/branches/release_35/lib/Sema/SemaExprCXX.cpp
    cfe/branches/release_35/lib/Sema/TreeTransform.h
    cfe/branches/release_35/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Propchange: cfe/branches/release_35/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  4 13:37:31 2014
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:213609,213611,213613,213741,213840,213902,213912,213993,213998-213999,214008,214050,214119,214208,214222,214369,214390,214471
+/cfe/trunk:213609,213611,213613,213741,213840,213902,213912-213913,213993,213998-213999,214008,214050,214119,214208,214222,214369,214390,214471
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_35/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_35/lib/Sema/SemaExprCXX.cpp?rev=214750&r1=214749&r2=214750&view=diff
==============================================================================
--- cfe/branches/release_35/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/branches/release_35/lib/Sema/SemaExprCXX.cpp Mon Aug  4 13:37:31 2014
@@ -1184,14 +1184,6 @@ Sema::BuildCXXNew(SourceRange Range, boo
     NumInits = List->getNumExprs();
   }
 
-  // Determine whether we've already built the initializer.
-  bool HaveCompleteInit = false;
-  if (Initializer && isa<CXXConstructExpr>(Initializer) &&
-      !isa<CXXTemporaryObjectExpr>(Initializer))
-    HaveCompleteInit = true;
-  else if (Initializer && isa<ImplicitValueInitExpr>(Initializer))
-    HaveCompleteInit = true;
-
   // C++11 [dcl.spec.auto]p6. Deduce the type which 'auto' stands in for.
   if (TypeMayContainAuto && AllocType->isUndeducedType()) {
     if (initStyle == CXXNewExpr::NoInit || NumInits == 0)
@@ -1481,8 +1473,7 @@ Sema::BuildCXXNew(SourceRange Range, boo
   // do it now.
   if (!AllocType->isDependentType() &&
       !Expr::hasAnyTypeDependentArguments(
-        llvm::makeArrayRef(Inits, NumInits)) &&
-      !HaveCompleteInit) {
+          llvm::makeArrayRef(Inits, NumInits))) {
     // C++11 [expr.new]p15:
     //   A new-expression that creates an object of type T initializes that
     //   object as follows:

Modified: cfe/branches/release_35/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_35/lib/Sema/TreeTransform.h?rev=214750&r1=214749&r2=214750&view=diff
==============================================================================
--- cfe/branches/release_35/lib/Sema/TreeTransform.h (original)
+++ cfe/branches/release_35/lib/Sema/TreeTransform.h Mon Aug  4 13:37:31 2014
@@ -344,7 +344,7 @@ public:
   /// TransformExpr or TransformExprs.
   ///
   /// \returns the transformed initializer.
-  ExprResult TransformInitializer(Expr *Init, bool CXXDirectInit);
+  ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
 
   /// \brief Transform the given list of expressions.
   ///
@@ -2858,7 +2858,7 @@ ExprResult TreeTransform<Derived>::Trans
 
 template<typename Derived>
 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
-                                                        bool CXXDirectInit) {
+                                                        bool NotCopyInit) {
   // Initializers are instantiated like expressions, except that various outer
   // layers are stripped.
   if (!Init)
@@ -2878,13 +2878,13 @@ ExprResult TreeTransform<Derived>::Trans
 
   if (CXXStdInitializerListExpr *ILE =
           dyn_cast<CXXStdInitializerListExpr>(Init))
-    return TransformInitializer(ILE->getSubExpr(), CXXDirectInit);
+    return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
 
-  // If this is not a direct-initializer, we only need to reconstruct
+  // If this is copy-initialization, we only need to reconstruct
   // InitListExprs. Other forms of copy-initialization will be a no-op if
   // the initializer is already the right type.
   CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
-  if (!CXXDirectInit && !(Construct && Construct->isListInitialization()))
+  if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
     return getDerived().TransformExpr(Init);
 
   // Revert value-initialization back to empty parens.
@@ -2907,12 +2907,12 @@ ExprResult TreeTransform<Derived>::Trans
   // If the initialization implicitly converted an initializer list to a
   // std::initializer_list object, unwrap the std::initializer_list too.
   if (Construct && Construct->isStdInitListInitialization())
-    return TransformInitializer(Construct->getArg(0), CXXDirectInit);
+    return TransformInitializer(Construct->getArg(0), NotCopyInit);
 
   SmallVector<Expr*, 8> NewArgs;
   bool ArgChanged = false;
   if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
-                     /*IsCall*/true, NewArgs, &ArgChanged))
+                                  /*IsCall*/true, NewArgs, &ArgChanged))
     return ExprError();
 
   // If this was list initialization, revert to list form.
@@ -8124,7 +8124,7 @@ TreeTransform<Derived>::TransformCXXNewE
   Expr *OldInit = E->getInitializer();
   ExprResult NewInit;
   if (OldInit)
-    NewInit = getDerived().TransformExpr(OldInit);
+    NewInit = getDerived().TransformInitializer(OldInit, true);
   if (NewInit.isInvalid())
     return ExprError();
 

Modified: cfe/branches/release_35/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_35/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=214750&r1=214749&r2=214750&view=diff
==============================================================================
--- cfe/branches/release_35/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/branches/release_35/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp Mon Aug  4 13:37:31 2014
@@ -455,3 +455,13 @@ namespace ArrayOfInitList {
   };
   S x[1] = {};
 }
+
+namespace PR20445 {
+  struct vector { vector(std::initializer_list<int>); };
+  struct MyClass { explicit MyClass(const vector &v); };
+  template<int x> void f() { new MyClass({42, 43}); }
+  template void f<0>();
+  // CHECK-LABEL: define {{.*}} @_ZN7PR204451fILi0EEEvv(
+  // CHECK: call void @_ZN7PR204456vectorC1ESt16initializer_listIiE(
+  // CHECK: call void @_ZN7PR204457MyClassC1ERKNS_6vectorE(
+}





More information about the llvm-branch-commits mailing list