diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h --- a/clang/include/clang/Basic/SourceLocation.h +++ b/clang/include/clang/Basic/SourceLocation.h @@ -26,6 +26,9 @@ template struct DenseMapInfo; +class FoldingSetNodeID; +template struct FoldingSetTrait; + } // namespace llvm namespace clang { @@ -87,6 +90,7 @@ friend class ASTReader; friend class ASTWriter; friend class SourceManager; + friend class llvm::FoldingSetTrait; unsigned ID = 0; @@ -501,6 +505,10 @@ } }; + template <> struct FoldingSetTrait { + static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID); + }; + // Teach SmallPtrSet how to handle SourceLocation. template<> struct PointerLikeTypeTraits { diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -1083,9 +1083,9 @@ //===----------------------------------------------------------------------===// void PathDiagnosticLocation::Profile(llvm::FoldingSetNodeID &ID) const { - ID.AddInteger(Range.getBegin().getRawEncoding()); - ID.AddInteger(Range.getEnd().getRawEncoding()); - ID.AddInteger(Loc.getRawEncoding()); + ID.Add(Range.getBegin()); + ID.Add(Range.getEnd()); + ID.Add(static_cast(Loc)); } void PathDiagnosticPiece::Profile(llvm::FoldingSetNodeID &ID) const { @@ -1095,8 +1095,8 @@ ID.AddInteger((unsigned) getDisplayHint()); ArrayRef Ranges = getRanges(); for (const auto &I : Ranges) { - ID.AddInteger(I.getBegin().getRawEncoding()); - ID.AddInteger(I.getEnd().getRawEncoding()); + ID.Add(I.getBegin()); + ID.Add(I.getEnd()); } } diff --git a/clang/lib/Basic/SourceLocation.cpp b/clang/lib/Basic/SourceLocation.cpp --- a/clang/lib/Basic/SourceLocation.cpp +++ b/clang/lib/Basic/SourceLocation.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/PrettyStackTrace.h" #include "clang/Basic/SourceManager.h" #include "llvm/ADT/DenseMapInfo.h" +#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/MemoryBuffer.h" @@ -45,6 +46,11 @@ return llvm::DenseMapInfo::getHashValue(ID); } +void llvm::FoldingSetTrait::Profile( + const SourceLocation &X, llvm::FoldingSetNodeID &ID) { + ID.AddInteger(X.ID); +} + void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{ if (!isValid()) { OS << ""; diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp --- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -2193,8 +2193,8 @@ for (SourceRange range : Ranges) { if (!range.isValid()) continue; - hash.AddInteger(range.getBegin().getRawEncoding()); - hash.AddInteger(range.getEnd().getRawEncoding()); + hash.Add(range.getBegin()); + hash.Add(range.getEnd()); } } @@ -2216,8 +2216,8 @@ for (SourceRange range : Ranges) { if (!range.isValid()) continue; - hash.AddInteger(range.getBegin().getRawEncoding()); - hash.AddInteger(range.getEnd().getRawEncoding()); + hash.Add(range.getBegin()); + hash.Add(range.getEnd()); } }