From: Richard Trieu Date: Tue, 13 Feb 2018 19:53:40 +0000 (+0000) Subject: Update StmtProfile.cpp to handle zero template arguments. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3dd36031ada95bb8eb2174f90e86c854fd0582f4;p=clang Update StmtProfile.cpp to handle zero template arguments. Treat having no templates arguments differently than having zero template arguments when profiling. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325040 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 00ef0da18b..08261205ef 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -966,8 +966,11 @@ void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) { 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) { diff --git a/test/Modules/odr_hash.cpp b/test/Modules/odr_hash.cpp index 054e41a9ea..5991dd0a73 100644 --- a/test/Modules/odr_hash.cpp +++ b/test/Modules/odr_hash.cpp @@ -2924,6 +2924,21 @@ int I10 = F10(); // expected-note@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 +int foo() { return 2; } +int bar() { return foo<>(); } +#else +int num = bar(); +// expected-error@second.h:* {{'DeclTemplateArguments::bar' has different definitions in different modules; definition in module 'SecondModule' first difference is function body}} +// expected-note@first.h:* {{but in 'FirstModule' found a different body}} +#endif +} + // Keep macros contained to one file. #ifdef FIRST #undef FIRST