r325040 - Update StmtProfile.cpp to handle zero template arguments.

Richard Trieu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 13 11:53:40 PST 2018


Author: rtrieu
Date: Tue Feb 13 11:53:40 2018
New Revision: 325040

URL: http://llvm.org/viewvc/llvm-project?rev=325040&view=rev
Log:
Update StmtProfile.cpp to handle zero template arguments.

Treat having no templates arguments differently than having zero template
arguments when profiling.

Modified:
    cfe/trunk/lib/AST/StmtProfile.cpp
    cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/lib/AST/StmtProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtProfile.cpp?rev=325040&r1=325039&r2=325040&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtProfile.cpp (original)
+++ cfe/trunk/lib/AST/StmtProfile.cpp Tue Feb 13 11:53:40 2018
@@ -966,8 +966,11 @@ void StmtProfiler::VisitDeclRefExpr(cons
   if (!Canonical)
     VisitNestedNameSpecifier(S->getQualifier());
   VisitDecl(S->getDecl());
-  if (!Canonical)
-    VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
+  if (!Canonical) {
+    ID.AddBoolean(S->hasExplicitTemplateArgs());
+    if (S->hasExplicitTemplateArgs())
+      VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
+  }
 }
 
 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {

Modified: cfe/trunk/test/Modules/odr_hash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr_hash.cpp?rev=325040&r1=325039&r2=325040&view=diff
==============================================================================
--- cfe/trunk/test/Modules/odr_hash.cpp (original)
+++ cfe/trunk/test/Modules/odr_hash.cpp Tue Feb 13 11:53:40 2018
@@ -2924,6 +2924,21 @@ int I10 = F10();
 // expected-note at first.h:* {{but in 'FirstModule' found a different body}}
 }  // namespace FunctionDecl
 
+namespace DeclTemplateArguments {
+#if defined(FIRST)
+int foo() { return 1; }
+int bar() { return foo(); }
+#elif defined(SECOND)
+template <class T = int>
+int foo() { return 2; }
+int bar() { return foo<>(); }
+#else
+int num = bar();
+// expected-error at second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}}
+// expected-note at first.h:* {{but in 'FirstModule' found a different body}}
+#endif
+}
+
 // Keep macros contained to one file.
 #ifdef FIRST
 #undef FIRST




More information about the cfe-commits mailing list