[cfe-commits] r77462 - in /cfe/trunk: include/clang/AST/DeclTemplate.h include/clang/AST/Type.h lib/AST/ASTContext.cpp lib/AST/StmtProfile.cpp lib/AST/Type.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiateDecl.cpp test/CXX/temp/temp.decls/temp.fct/temp.over.link/p6.cpp test/SemaTemplate/injected-class-name.cpp

Douglas Gregor dgregor at apple.com
Wed Jul 29 09:09:58 PDT 2009


Author: dgregor
Date: Wed Jul 29 11:09:57 2009
New Revision: 77462

URL: http://llvm.org/viewvc/llvm-project?rev=77462&view=rev
Log:
Use the new statement/expression profiling code to unique dependent
template arguments, as in template specialization types. This permits
matching out-of-line definitions of members for class templates that
involve non-type template parameters.

Modified:
    cfe/trunk/include/clang/AST/DeclTemplate.h
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
    cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p6.cpp
    cfe/trunk/test/SemaTemplate/injected-class-name.cpp

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Wed Jul 29 11:09:57 2009
@@ -315,7 +315,7 @@
   void setArgumentPack(TemplateArgument *Args, unsigned NumArgs, bool CopyArgs);
   
   /// \brief Used to insert TemplateArguments into FoldingSets.
-  void Profile(llvm::FoldingSetNodeID &ID) const {
+  void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context) const {
     ID.AddInteger(Kind);
     switch (Kind) {
       case Null:
@@ -326,7 +326,7 @@
         break;
         
       case Declaration:
-        ID.AddPointer(getAsDecl()); // FIXME: Must be canonical!
+        ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : 0);
         break;
         
       case Integral:
@@ -335,14 +335,13 @@
         break;
         
       case Expression:
-        // FIXME: We need a canonical representation of expressions.
-        ID.AddPointer(getAsExpr());
+        getAsExpr()->Profile(ID, Context, true);
         break;
         
       case Pack:
         ID.AddInteger(Args.NumArgs);
         for (unsigned I = 0; I != Args.NumArgs; ++I)
-          Args.Args[I].Profile(ID);
+          Args.Args[I].Profile(ID, Context);
     }
   }
 };
@@ -534,15 +533,16 @@
   
   void Profile(llvm::FoldingSetNodeID &ID) {
     Profile(ID, TemplateArguments->getFlatArgumentList(), 
-            TemplateArguments->flat_size());    
+            TemplateArguments->flat_size(),
+            Function->getASTContext());    
   }
   
   static void 
   Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, 
-          unsigned NumTemplateArgs) {
+          unsigned NumTemplateArgs, ASTContext &Context) {
     ID.AddInteger(NumTemplateArgs);
     for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg)
-      TemplateArgs[Arg].Profile(ID);
+      TemplateArgs[Arg].Profile(ID, Context);
   }  
 };
   
@@ -918,15 +918,16 @@
   }
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
-    Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size());
+    Profile(ID, TemplateArgs.getFlatArgumentList(), TemplateArgs.flat_size(),
+            getASTContext());
   }
 
   static void 
   Profile(llvm::FoldingSetNodeID &ID, const TemplateArgument *TemplateArgs, 
-          unsigned NumTemplateArgs) {
+          unsigned NumTemplateArgs, ASTContext &Context) {
     ID.AddInteger(NumTemplateArgs);
     for (unsigned Arg = 0; Arg != NumTemplateArgs; ++Arg)
-      TemplateArgs[Arg].Profile(ID);
+      TemplateArgs[Arg].Profile(ID, Context);
   }
 
   static bool classof(const Decl *D) { 

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Jul 29 11:09:57 2009
@@ -1782,14 +1782,18 @@
 class TemplateSpecializationType 
   : public Type, public llvm::FoldingSetNode {
 
-  /// \brief The name of the template being specialized.
+  // FIXME: Currently needed for profiling expressions; can we avoid this?
+  ASTContext &Context;
+    
+    /// \brief The name of the template being specialized.
   TemplateName Template;
 
   /// \brief - The number of template arguments named in this class
   /// template specialization.
   unsigned NumArgs;
 
-  TemplateSpecializationType(TemplateName T,
+  TemplateSpecializationType(ASTContext &Context,
+                             TemplateName T,
                              const TemplateArgument *Args,
                              unsigned NumArgs, QualType Canon);
 
@@ -1833,11 +1837,12 @@
                                    const PrintingPolicy &Policy) const;
 
   void Profile(llvm::FoldingSetNodeID &ID) {
-    Profile(ID, Template, getArgs(), NumArgs);
+    Profile(ID, Template, getArgs(), NumArgs, Context);
   }
 
   static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T,
-                      const TemplateArgument *Args, unsigned NumArgs);
+                      const TemplateArgument *Args, unsigned NumArgs,
+                      ASTContext &Context);
 
   static bool classof(const Type *T) { 
     return T->getTypeClass() == TemplateSpecialization; 

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Jul 29 11:09:57 2009
@@ -1682,7 +1682,7 @@
     // exists.
     llvm::FoldingSetNodeID ID;
     TemplateSpecializationType::Profile(ID, CanonTemplate, 
-                                        CanonArgs.data(), NumArgs);
+                                        CanonArgs.data(), NumArgs, *this);
 
     void *InsertPos = 0;
     TemplateSpecializationType *Spec
@@ -1693,7 +1693,7 @@
       void *Mem = Allocate((sizeof(TemplateSpecializationType) + 
                             sizeof(TemplateArgument) * NumArgs),
                            8);
-      Spec = new (Mem) TemplateSpecializationType(CanonTemplate, 
+      Spec = new (Mem) TemplateSpecializationType(*this, CanonTemplate, 
                                                   CanonArgs.data(), NumArgs,
                                                   QualType());
       Types.push_back(Spec);
@@ -1713,7 +1713,8 @@
                         sizeof(TemplateArgument) * NumArgs),
                        8);
   TemplateSpecializationType *Spec 
-    = new (Mem) TemplateSpecializationType(Template, Args, NumArgs, Canon);
+    = new (Mem) TemplateSpecializationType(*this, Template, Args, NumArgs, 
+                                           Canon);
   
   Types.push_back(Spec);
   return QualType(Spec, 0);  

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Wed Jul 29 11:09:57 2009
@@ -107,6 +107,10 @@
   VisitStmt(S);
 }
 
+void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
+  VisitStmt(S);
+}
+
 void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
   VisitStmt(S);
 }
@@ -330,6 +334,10 @@
   VisitExpr(S);
 }
 
+void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
+  VisitExpr(S);
+}
+
 void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
   if (S->getSyntacticForm()) {
     VisitInitListExpr(S->getSyntacticForm());
@@ -416,6 +424,10 @@
   ID.AddBoolean(S->getValue());
 }
 
+void StmtProfiler::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
+  VisitExpr(S);
+}
+
 void StmtProfiler::VisitCXXTypeidExpr(CXXTypeidExpr *S) {
   VisitExpr(S);
   if (S->isTypeOperand())
@@ -595,6 +607,7 @@
         = dyn_cast_or_null<NonTypeTemplateParmDecl>(D)) {
       ID.AddInteger(NTTP->getDepth());
       ID.AddInteger(NTTP->getIndex());
+      VisitType(NTTP->getType());
       return;
     }
     

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed Jul 29 11:09:57 2009
@@ -1033,11 +1033,13 @@
 }
 
 TemplateSpecializationType::
-TemplateSpecializationType(TemplateName T, const TemplateArgument *Args,
+TemplateSpecializationType(ASTContext &Context, TemplateName T, 
+                           const TemplateArgument *Args,
                            unsigned NumArgs, QualType Canon)
   : Type(TemplateSpecialization, 
          Canon.isNull()? QualType(this, 0) : Canon,
          T.isDependent() || anyDependentTemplateArguments(Args, NumArgs)),
+    Context(Context),
     Template(T), NumArgs(NumArgs)
 {
   assert((!Canon.isNull() || 
@@ -1074,10 +1076,11 @@
 TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID, 
                                     TemplateName T, 
                                     const TemplateArgument *Args, 
-                                    unsigned NumArgs) {
+                                    unsigned NumArgs,
+                                    ASTContext &Context) {
   T.Profile(ID);
   for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
-    Args[Idx].Profile(ID);
+    Args[Idx].Profile(ID, Context);
 }
 
 const Type *QualifierSet::strip(const Type* T) {

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Jul 29 11:09:57 2009
@@ -930,7 +930,8 @@
     llvm::FoldingSetNodeID ID;
     ClassTemplateSpecializationDecl::Profile(ID, 
                                              Converted.getFlatArguments(),
-                                             Converted.flatSize());
+                                             Converted.flatSize(),
+                                             Context);
     void *InsertPos = 0;
     ClassTemplateSpecializationDecl *Decl
       = ClassTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
@@ -2433,12 +2434,14 @@
     // FIXME: Template parameter list matters, too
     ClassTemplatePartialSpecializationDecl::Profile(ID, 
                                                    Converted.getFlatArguments(),
-                                                   Converted.flatSize());
+                                                   Converted.flatSize(),
+                                                    Context);
   }
   else
     ClassTemplateSpecializationDecl::Profile(ID,
                                              Converted.getFlatArguments(),
-                                             Converted.flatSize());
+                                             Converted.flatSize(),
+                                             Context);
   void *InsertPos = 0;
   ClassTemplateSpecializationDecl *PrevDecl = 0;
 
@@ -2703,7 +2706,8 @@
   llvm::FoldingSetNodeID ID;
   ClassTemplateSpecializationDecl::Profile(ID, 
                                            Converted.getFlatArguments(),
-                                           Converted.flatSize());
+                                           Converted.flatSize(),
+                                           Context);
   void *InsertPos = 0;
   ClassTemplateSpecializationDecl *PrevDecl
     = ClassTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Jul 29 11:09:57 2009
@@ -321,7 +321,8 @@
     llvm::FoldingSetNodeID ID;
     FunctionTemplateSpecializationInfo::Profile(ID, 
                                           TemplateArgs.getFlatArgumentList(),
-                                                TemplateArgs.flat_size());
+                                                TemplateArgs.flat_size(),
+                                                SemaRef.Context);
     
     FunctionTemplateSpecializationInfo *Info 
       = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, 

Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p6.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p6.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p6.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.fct/temp.over.link/p6.cpp Wed Jul 29 11:09:57 2009
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-// XFAIL
 
 template<int N, int M>
 struct A0 {

Modified: cfe/trunk/test/SemaTemplate/injected-class-name.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/injected-class-name.cpp?rev=77462&r1=77461&r2=77462&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/injected-class-name.cpp (original)
+++ cfe/trunk/test/SemaTemplate/injected-class-name.cpp Wed Jul 29 11:09:57 2009
@@ -19,7 +19,7 @@
 
 // [temp.local]p1:
 
-// FIXME: test non-type and template template parameters
+// FIXME: test template template parameters
 template<typename T, typename U>
 struct X0 {
   typedef T type;
@@ -38,3 +38,11 @@
   void f2(X0&);
   void f2(const ::X0<type, U_type2>&); // expected-error{{redecl}}
 };
+
+template<typename T, T N>
+struct X1 {
+  void f0(const X1&); // expected-note{{here}}
+  void f0(X1&);
+  void f0(const X1<T, N>&); // expected-error{{redecl}}
+};
+





More information about the cfe-commits mailing list