Skip to content

Commit

Permalink
[ODRHash] Fix early exit that skipped code.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Weverything committed Sep 14, 2018
1 parent 1a5ee75 commit 7592787
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/clang/AST/ODRHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class ODRHash {
void AddBoolean(bool value);

static bool isWhitelistedDecl(const Decl* D, const DeclContext *Parent);

private:
void AddDeclarationNameImpl(DeclarationName Name);
};

} // end namespace clang
Expand Down
12 changes: 9 additions & 3 deletions lib/AST/ODRHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -91,9 +100,6 @@ void ODRHash::AddDeclarationName(DeclarationName Name, bool TreatAsDecl) {
}
}
}

if (TreatAsDecl)
AddBoolean(false);
}

void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
Expand Down
1 change: 1 addition & 0 deletions test/Modules/Inputs/odr_hash-Unresolved/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class S {
void run() {
int x;
A::Check(&Field, 1);
A::Check(&Field, 1);
}
};
#endif

0 comments on commit 7592787

Please sign in to comment.