diff options
author | George Burgess IV <george.burgess.iv@gmail.com> | 2017-08-09 21:20:41 +0000 |
---|---|---|
committer | George Burgess IV <george.burgess.iv@gmail.com> | 2017-08-09 21:20:41 +0000 |
commit | b8709babd2b4683b8208876b3eaf4dc8d65ba5cc (patch) | |
tree | d04583b4b2244ba2bcb0ccc03d85c544194c1dae /clang/lib/AST/Linkage.h | |
parent | b1a9ad81c5d4850acd5429b03f59c4e7b6fe3466 (diff) | |
download | bcm5719-llvm-b8709babd2b4683b8208876b3eaf4dc8d65ba5cc.tar.gz bcm5719-llvm-b8709babd2b4683b8208876b3eaf4dc8d65ba5cc.zip |
Use unsigned instead of an enum for map keys
ubsan's enum sanitizer doesn't like the latter, and we had to have
out-of-bounds values for DenseMapInfo's tombstone/empty keys.
llvm-svn: 310523
Diffstat (limited to 'clang/lib/AST/Linkage.h')
-rw-r--r-- | clang/lib/AST/Linkage.h | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/clang/lib/AST/Linkage.h b/clang/lib/AST/Linkage.h index 5f3458dfb60..fde9841cdff 100644 --- a/clang/lib/AST/Linkage.h +++ b/clang/lib/AST/Linkage.h @@ -55,27 +55,7 @@ enum LVComputationKind { LVForLinkageOnly = LVForValue | IgnoreExplicitVisibilityBit | IgnoreAllVisibilityBit }; -} // namespace clang - -namespace llvm { -template <> struct DenseMapInfo<clang::LVComputationKind> { - static inline clang::LVComputationKind getEmptyKey() { - return static_cast<clang::LVComputationKind>(-1); - } - static inline clang::LVComputationKind getTombstoneKey() { - return static_cast<clang::LVComputationKind>(-2); - } - static unsigned getHashValue(const clang::LVComputationKind &Val) { - return Val; - } - static bool isEqual(const clang::LVComputationKind &LHS, - const clang::LVComputationKind &RHS) { - return LHS == RHS; - } -}; -} // namespace llvm -namespace clang { class LinkageComputer { // We have a cache for repeated linkage/visibility computations. This saves us // from exponential behavior in heavily templated code, such as: @@ -85,18 +65,27 @@ class LinkageComputer { // using B = Foo<A, A>; // using C = Foo<B, B>; // using D = Foo<C, C>; - using QueryType = std::pair<const NamedDecl *, LVComputationKind>; + // + // Note that the unsigned is actually a LVComputationKind; ubsan's enum + // sanitizer doesn't like tombstone/empty markers outside of + // LVComputationKind's range. + using QueryType = std::pair<const NamedDecl *, unsigned>; llvm::SmallDenseMap<QueryType, LinkageInfo, 8> CachedLinkageInfo; + + static QueryType makeCacheKey(const NamedDecl *ND, LVComputationKind Kind) { + return std::make_pair(ND, static_cast<unsigned>(Kind)); + } + llvm::Optional<LinkageInfo> lookup(const NamedDecl *ND, LVComputationKind Kind) const { - auto Iter = CachedLinkageInfo.find(std::make_pair(ND, Kind)); + auto Iter = CachedLinkageInfo.find(makeCacheKey(ND, Kind)); if (Iter == CachedLinkageInfo.end()) return None; return Iter->second; } void cache(const NamedDecl *ND, LVComputationKind Kind, LinkageInfo Info) { - CachedLinkageInfo[std::make_pair(ND, Kind)] = Info; + CachedLinkageInfo[makeCacheKey(ND, Kind)] = Info; } LinkageInfo getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args, |