From 6f72737c3bd66085e5196b7cb78ef4fdfc39e796 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Fri, 21 Oct 2016 20:08:52 +0000 Subject: [PATCH] [CUDA] Use FunctionDeclAndLoc for the Sema::LocsWithCUDACallDiags hashtable. Summary: NFC Reviewers: rnk Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25797 llvm-svn: 284869 --- clang/include/clang/Sema/Sema.h | 41 ++++++++++++++++++++++++++++++++++------- clang/lib/Sema/SemaCUDA.cpp | 2 +- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 70db36f..541451f 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9250,18 +9250,18 @@ public: std::vector> CUDADeferredDiags; - /// FunctionDecls plus raw encodings of SourceLocations for which - /// CheckCUDACall has emitted a (maybe deferred) "bad call" diagnostic. We - /// use this to avoid emitting the same deferred diag twice. - llvm::DenseSet, unsigned>> - LocsWithCUDACallDiags; - - /// A pair of a canonical FunctionDecl and a SourceLocation. + /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the + /// key in a hashtable, both the FD and location are hashed. struct FunctionDeclAndLoc { CanonicalDeclPtr FD; SourceLocation Loc; }; + /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a + /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the + /// same deferred diag twice. + llvm::DenseSet LocsWithCUDACallDiags; + /// An inverse call graph, mapping known-emitted functions to one of their /// known-emitted callers (plus the location of the call). /// @@ -10035,4 +10035,31 @@ struct LateParsedTemplate { } // end namespace clang +namespace llvm { +// Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its +// SourceLocation. +template <> struct DenseMapInfo { + using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; + using FDBaseInfo = DenseMapInfo>; + + static FunctionDeclAndLoc getEmptyKey() { + return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()}; + } + + static FunctionDeclAndLoc getTombstoneKey() { + return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()}; + } + + static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { + return hash_combine(FDBaseInfo::getHashValue(FDL.FD), + FDL.Loc.getRawEncoding()); + } + + static bool isEqual(const FunctionDeclAndLoc &LHS, + const FunctionDeclAndLoc &RHS) { + return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; + } +}; +} // namespace llvm + #endif diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index c578f92..fbaede1 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -774,7 +774,7 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) { // like this is unfortunate, but because we must continue parsing as normal // after encountering a deferred error, it's otherwise very tricky for us to // ensure that we only emit this deferred error once. - if (!LocsWithCUDACallDiags.insert({Caller, Loc.getRawEncoding()}).second) + if (!LocsWithCUDACallDiags.insert({Caller, Loc}).second) return true; CUDADiagBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller, *this) -- 2.7.4