]> granicus.if.org Git - clang/commitdiff
[ODRHash] Fix early exit that skipped code.
authorRichard Trieu <rtrieu@google.com>
Fri, 14 Sep 2018 01:15:28 +0000 (01:15 +0000)
committerRichard Trieu <rtrieu@google.com>
Fri, 14 Sep 2018 01:15:28 +0000 (01:15 +0000)
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.

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

include/clang/AST/ODRHash.h
lib/AST/ODRHash.cpp
test/Modules/Inputs/odr_hash-Unresolved/class.h

index 0298887d1b1d7133515268dadd6e04c2a4bbff27..feaa83844a1a501396f347d0b185fd6aa7e2e789 100644 (file)
@@ -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
index 1624468079a0ad153fe7a630e8676e0e8daa2097..3aeb7e6fbb213c311a4a403bc9a42fd9ec7633af 100644 (file)
@@ -34,8 +34,17 @@ void ODRHash::AddIdentifierInfo(const IdentifierInfo *II) {
 
 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(DeclarationName Name, bool TreatAsDecl) {
     }
   }
   }
-
-  if (TreatAsDecl)
-    AddBoolean(false);
 }
 
 void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
index fe3a7116f9bfcbd118ea7b39da308d870441413e..8a3c9f941f7ed356b1a7883f44bac12f0711afcd 100644 (file)
@@ -6,6 +6,7 @@ class S {
   void run() {
     int x;
     A::Check(&Field, 1);
+    A::Check(&Field, 1);
   }
 };
 #endif