diff options
author | Richard Trieu <rtrieu@google.com> | 2018-02-22 05:32:25 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2018-02-22 05:32:25 +0000 |
commit | 41cbdd8656425348d3c99550783be0364d1555e2 (patch) | |
tree | 08b6d017d7c827c4ee621c3c25ce3f4a6d5ddadb /lib/AST/StmtProfile.cpp | |
parent | 30f9051d7d8b6f56c8149fd1bdcc714285f77527 (diff) | |
download | clang-41cbdd8656425348d3c99550783be0364d1555e2.tar.gz |
[ODRHash] Handle some template weirdness.
Build the index off of DeclarationName instead of Decl pointers. When finding
an UnresolvedLookupExprClass, hash it as if it were a DeclRefExpr. This will
allow methods to be hashed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325741 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/StmtProfile.cpp')
-rw-r--r-- | lib/AST/StmtProfile.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/AST/StmtProfile.cpp b/lib/AST/StmtProfile.cpp index 08261205ef..a12f4bc612 100644 --- a/lib/AST/StmtProfile.cpp +++ b/lib/AST/StmtProfile.cpp @@ -38,6 +38,8 @@ namespace { void VisitStmt(const Stmt *S); + virtual void HandleStmtClass(Stmt::StmtClass SC) = 0; + #define STMT(Node, Base) void Visit##Node(const Node *S); #include "clang/AST/StmtNodes.inc" @@ -50,7 +52,7 @@ namespace { virtual void VisitType(QualType T) = 0; /// \brief Visit a name that occurs within an expression or statement. - virtual void VisitName(DeclarationName Name) = 0; + virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0; /// \brief Visit identifiers that are not in Decl's or Type's. virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0; @@ -80,6 +82,10 @@ namespace { const ASTContext &Context, bool Canonical) : StmtProfiler(ID, Canonical), Context(Context) {} private: + void HandleStmtClass(Stmt::StmtClass SC) override { + ID.AddInteger(SC); + } + void VisitDecl(const Decl *D) override { ID.AddInteger(D ? D->getKind() : 0); @@ -134,7 +140,7 @@ namespace { ID.AddPointer(T.getAsOpaquePtr()); } - void VisitName(DeclarationName Name) override { + void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override { ID.AddPointer(Name.getAsOpaquePtr()); } @@ -163,11 +169,26 @@ namespace { : StmtProfiler(ID, false), Hash(Hash) {} private: + void HandleStmtClass(Stmt::StmtClass SC) override { + if (SC == Stmt::UnresolvedLookupExprClass) { + // Pretend that the name looked up is a Decl due to how templates + // handle some Decl lookups. + ID.AddInteger(Stmt::DeclRefExprClass); + } else { + ID.AddInteger(SC); + } + } + void VisitType(QualType T) override { Hash.AddQualType(T); } - void VisitName(DeclarationName Name) override { + void VisitName(DeclarationName Name, bool TreatAsDecl) override { + if (TreatAsDecl) { + // A Decl can be null, so each Decl is preceded by a boolean to + // store its nullness. Add a boolean here to match. + ID.AddBoolean(true); + } Hash.AddDeclarationName(Name); } void VisitIdentifierInfo(IdentifierInfo *II) override { @@ -196,7 +217,9 @@ namespace { void StmtProfiler::VisitStmt(const Stmt *S) { assert(S && "Requires non-null Stmt pointer"); - ID.AddInteger(S->getStmtClass()); + + HandleStmtClass(S->getStmtClass()); + for (const Stmt *SubStmt : S->children()) { if (SubStmt) Visit(SubStmt); @@ -1662,7 +1685,7 @@ StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { VisitExpr(S); VisitNestedNameSpecifier(S->getQualifier()); - VisitName(S->getName()); + VisitName(S->getName(), /*TreatAsDecl*/ true); ID.AddBoolean(S->hasExplicitTemplateArgs()); if (S->hasExplicitTemplateArgs()) VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); |