r322414 - When rebuilding an InitListExpr, don't give it a type.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 12 14:21:33 PST 2018


Author: rsmith
Date: Fri Jan 12 14:21:33 2018
New Revision: 322414

URL: http://llvm.org/viewvc/llvm-project?rev=322414&view=rev
Log:
When rebuilding an InitListExpr, don't give it a type.

InitListExprs without types (well, with type 'void') represent not-yet-analyzed
initializer lists; InitListExpr with types fool Sema into thinking they don't
need further analysis in some cases (particularly C++17 copy omission).

Modified:
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=322414&r1=322413&r2=322414&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Jan 12 14:21:33 2018
@@ -2352,18 +2352,8 @@ public:
   /// Subclasses may override this routine to provide different behavior.
   ExprResult RebuildInitList(SourceLocation LBraceLoc,
                              MultiExprArg Inits,
-                             SourceLocation RBraceLoc,
-                             QualType ResultTy) {
-    ExprResult Result
-      = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
-    if (Result.isInvalid() || ResultTy->isDependentType())
-      return Result;
-
-    // Patch in the result type we were given, which may have been computed
-    // when the initial InitListExpr was built.
-    InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
-    ILE->setType(ResultTy);
-    return Result;
+                             SourceLocation RBraceLoc) {
+    return SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
   }
 
   /// \brief Build a new designated initializer expression.
@@ -3394,11 +3384,10 @@ ExprResult TreeTransform<Derived>::Trans
                                   /*IsCall*/true, NewArgs, &ArgChanged))
     return ExprError();
 
-  // If this was list initialization, revert to list form.
+  // If this was list initialization, revert to syntactic list form.
   if (Construct->isListInitialization())
     return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
-                                        Construct->getLocEnd(),
-                                        Construct->getType());
+                                        Construct->getLocEnd());
 
   // Build a ParenListExpr to represent anything else.
   SourceRange Parens = Construct->getParenOrBraceRange();
@@ -9513,7 +9502,7 @@ TreeTransform<Derived>::TransformInitLis
   }
 
   return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
-                                      E->getRBraceLoc(), E->getType());
+                                      E->getRBraceLoc());
 }
 
 template<typename Derived>

Modified: cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp?rev=322414&r1=322413&r2=322414&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx1z-initializer-aggregate.cpp Fri Jan 12 14:21:33 2018
@@ -112,3 +112,21 @@ namespace Dynamic {
   //   A_CLEANUP:
   // CHECK: call void @_ZN7Dynamic1AD1Ev({{.*}} @_ZN7Dynamic2d3E
 }
+
+namespace Instantiated1 {
+  struct A { A(); };
+  struct B : A { using A::A; };
+  template<int> B v({});
+  template B v<0>;
+  // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN13Instantiated11vILi0EEE) {
+  // CHECK: call void @_ZN13Instantiated11BC1Ev(%{{.*}}* @_ZN13Instantiated11vILi0EEE)
+}
+
+namespace Instantiated2 {
+  struct A { A(); };
+  struct B : A {};
+  template<int> B v({});
+  template B v<0>;
+  // CHECK-LABEL: define {{.*}}global_var_init{{.*}} comdat($_ZN13Instantiated21vILi0EEE) {
+  // CHECK: call void @_ZN13Instantiated21AC2Ev(
+}




More information about the cfe-commits mailing list