r213913 - PR20445: Properly transform the initializer in a CXXNewExpr rather than running

Bill Wendling isanbard at gmail.com
Mon Aug 4 11:46:19 PDT 2014


Done. Thanks!

-bw

On Jul 24, 2014, at 7:02 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> This fixes a wrong-code regression, and is a good candidate for the branch.
> 
> 
> On Thu, Jul 24, 2014 at 6:12 PM, Richard Smith <richard-llvm at metafoo.co.uk> wrote:
> Author: rsmith
> Date: Thu Jul 24 20:12:44 2014
> New Revision: 213913
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=213913&view=rev
> Log:
> 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/trunk/lib/Sema/SemaExprCXX.cpp
>     cfe/trunk/lib/Sema/TreeTransform.h
>     cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
> 
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=213913&r1=213912&r2=213913&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Jul 24 20:12:44 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/trunk/lib/Sema/TreeTransform.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=213913&r1=213912&r2=213913&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
> +++ cfe/trunk/lib/Sema/TreeTransform.h Thu Jul 24 20:12:44 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.
> @@ -8179,7 +8179,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/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=213913&r1=213912&r2=213913&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp Thu Jul 24 20:12:44 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(
> +}
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140804/ae9bf4d7/attachment.html>


More information about the cfe-commits mailing list