Author: rtrieu Date: Thu Sep 13 18:15:28 2018 New Revision: 342199 URL: http://llvm.org/viewvc/llvm-project?rev=342199&view=rev Log: [ODRHash] Fix early exit that skipped code.
There is a bit of code at the end of AddDeclaration that should be run on every exit of the function. However, there was an early exit beforehand that could be triggered, which causes a small amount of data to skip the hashing, leading to false positive mismatch. Use a separate function so that this code is always run. Modified: cfe/trunk/include/clang/AST/ODRHash.h cfe/trunk/lib/AST/ODRHash.cpp cfe/trunk/test/Modules/Inputs/odr_hash-Unresolved/class.h Modified: cfe/trunk/include/clang/AST/ODRHash.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ODRHash.h?rev=342199&r1=342198&r2=342199&view=diff ============================================================================== --- cfe/trunk/include/clang/AST/ODRHash.h (original) +++ cfe/trunk/include/clang/AST/ODRHash.h Thu Sep 13 18:15:28 2018 @@ -91,6 +91,9 @@ public: void AddBoolean(bool value); static bool isWhitelistedDecl(const Decl* D, const DeclContext *Parent); + +private: + void AddDeclarationNameImpl(DeclarationName Name); }; } // end namespace clang Modified: cfe/trunk/lib/AST/ODRHash.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=342199&r1=342198&r2=342199&view=diff ============================================================================== --- cfe/trunk/lib/AST/ODRHash.cpp (original) +++ cfe/trunk/lib/AST/ODRHash.cpp Thu Sep 13 18:15:28 2018 @@ -34,8 +34,17 @@ void ODRHash::AddIdentifierInfo(const Id void ODRHash::AddDeclarationName(DeclarationName Name, bool TreatAsDecl) { if (TreatAsDecl) + // Matches the NamedDecl check in AddDecl AddBoolean(true); + AddDeclarationNameImpl(Name); + + if (TreatAsDecl) + // Matches the ClassTemplateSpecializationDecl check in AddDecl + AddBoolean(false); +} + +void ODRHash::AddDeclarationNameImpl(DeclarationName Name) { // Index all DeclarationName and use index numbers to refer to them. auto Result = DeclNameMap.insert(std::make_pair(Name, DeclNameMap.size())); ID.AddInteger(Result.first->second); @@ -91,9 +100,6 @@ void ODRHash::AddDeclarationName(Declara } } } - - if (TreatAsDecl) - AddBoolean(false); } void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) { Modified: cfe/trunk/test/Modules/Inputs/odr_hash-Unresolved/class.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr_hash-Unresolved/class.h?rev=342199&r1=342198&r2=342199&view=diff ============================================================================== --- cfe/trunk/test/Modules/Inputs/odr_hash-Unresolved/class.h (original) +++ cfe/trunk/test/Modules/Inputs/odr_hash-Unresolved/class.h Thu Sep 13 18:15:28 2018 @@ -6,6 +6,7 @@ class S { void run() { int x; A::Check(&Field, 1); + A::Check(&Field, 1); } }; #endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits