]> granicus.if.org Git - clang/commitdiff
Use the new statement/expression profiling code to unique dependent
authorDouglas Gregor <dgregor@apple.com>
Wed, 29 Jul 2009 16:09:57 +0000 (16:09 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 29 Jul 2009 16:09:57 +0000 (16:09 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77462 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8601620931315bf4d0ddb1616c8356752977573d..17c8bc877d01f363f875a9ac1e43fe8a91982cf3 100644 (file)
@@ -315,7 +315,7 @@ public:
   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 @@ public:
         break;
         
       case Declaration:
-        ID.AddPointer(getAsDecl()); // FIXME: Must be canonical!
+        ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : 0);
         break;
         
       case Integral:
@@ -335,14 +335,13 @@ public:
         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 @@ public:
   
   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 @@ public:
   }
 
   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) { 
index be018026e36f511d63c6f8112273dd00186c84fa..66d23f3eb5617e05e01230099bf6fa37590c0572 100644 (file)
@@ -1782,14 +1782,18 @@ public:
 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 @@ public:
                                    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; 
index 931010d90465f0f73db6525f904b7723dc436701..f3a417181e7ec76e3bcd8e540977d46458a7fd7a 100644 (file)
@@ -1682,7 +1682,7 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,
     // exists.
     llvm::FoldingSetNodeID ID;
     TemplateSpecializationType::Profile(ID, CanonTemplate, 
-                                        CanonArgs.data(), NumArgs);
+                                        CanonArgs.data(), NumArgs, *this);
 
     void *InsertPos = 0;
     TemplateSpecializationType *Spec
@@ -1693,7 +1693,7 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,
       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 @@ ASTContext::getTemplateSpecializationType(TemplateName Template,
                         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);  
index 0f241c20ab2aec9e881de19e044c0bbc00fe41e7..688777d4aacbd15b9dc9afe04eea334a29799c53 100644 (file)
@@ -107,6 +107,10 @@ void StmtProfiler::VisitIfStmt(IfStmt *S) {
   VisitStmt(S);
 }
 
+void StmtProfiler::VisitSwitchStmt(SwitchStmt *S) {
+  VisitStmt(S);
+}
+
 void StmtProfiler::VisitWhileStmt(WhileStmt *S) {
   VisitStmt(S);
 }
@@ -330,6 +334,10 @@ void StmtProfiler::VisitGNUNullExpr(GNUNullExpr *S) {
   VisitExpr(S);
 }
 
+void StmtProfiler::VisitVAArgExpr(VAArgExpr *S) {
+  VisitExpr(S);
+}
+
 void StmtProfiler::VisitInitListExpr(InitListExpr *S) {
   if (S->getSyntacticForm()) {
     VisitInitListExpr(S->getSyntacticForm());
@@ -416,6 +424,10 @@ void StmtProfiler::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
   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 @@ void StmtProfiler::VisitDecl(Decl *D) {
         = dyn_cast_or_null<NonTypeTemplateParmDecl>(D)) {
       ID.AddInteger(NTTP->getDepth());
       ID.AddInteger(NTTP->getIndex());
+      VisitType(NTTP->getType());
       return;
     }
     
index 04961ed0fcb8ec29f402ab0653be7c33ad5c6758..f937d15ffb9fe64d4a2831e0bce6cc74ea3a0788 100644 (file)
@@ -1033,11 +1033,13 @@ anyDependentTemplateArguments(const TemplateArgument *Args, unsigned NumArgs) {
 }
 
 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 @@ void
 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) {
index 97812046f7f2c66641b065a7b9461cc9c80bdbe6..f27d551d102135bcaed031c710e5c9b4a77578e0 100644 (file)
@@ -930,7 +930,8 @@ QualType Sema::CheckTemplateIdType(TemplateName Name,
     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 @@ Sema::ActOnClassTemplateSpecialization(Scope *S, unsigned TagSpec, TagKind TK,
     // 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 @@ Sema::ActOnExplicitInstantiation(Scope *S, SourceLocation TemplateLoc,
   llvm::FoldingSetNodeID ID;
   ClassTemplateSpecializationDecl::Profile(ID, 
                                            Converted.getFlatArguments(),
-                                           Converted.flatSize());
+                                           Converted.flatSize(),
+                                           Context);
   void *InsertPos = 0;
   ClassTemplateSpecializationDecl *PrevDecl
     = ClassTemplate->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
index b04b63523df041d620b91cc62a884c04f2f094dc..6506cde2af851261862b6296d8afddcce65cd85d 100644 (file)
@@ -321,7 +321,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) {
     llvm::FoldingSetNodeID ID;
     FunctionTemplateSpecializationInfo::Profile(ID, 
                                           TemplateArgs.getFlatArgumentList(),
-                                                TemplateArgs.flat_size());
+                                                TemplateArgs.flat_size(),
+                                                SemaRef.Context);
     
     FunctionTemplateSpecializationInfo *Info 
       = FunctionTemplate->getSpecializations().FindNodeOrInsertPos(ID, 
index 7606a2a6eef0a5de2637c4808b173f36ee21a940..2571e45c5cde2aaea964b6e9e745bfe73a039204 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: clang-cc -fsyntax-only -verify %s
-// XFAIL
 
 template<int N, int M>
 struct A0 {
index c5f826d849ca350d0d0a3b137aafd4ebd79c17a3..f9674c39a58b9cb1ec0b164ec7cd4b782421aef5 100644 (file)
@@ -19,7 +19,7 @@ X<float>::X<int> xi = x;
 
 // [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 @@ struct X0 {
   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}}
+};
+