[clang] 443ab4d - [clang][Basic] Integrate SourceLocation with FoldingSet, NFCI
Mikhail Maltsev via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 27 03:44:19 PDT 2020
Author: Mikhail Maltsev
Date: 2020-10-27T10:43:39Z
New Revision: 443ab4d2e01246bf93cd410db945dc9ab6adf1b3
URL: https://github.com/llvm/llvm-project/commit/443ab4d2e01246bf93cd410db945dc9ab6adf1b3
DIFF: https://github.com/llvm/llvm-project/commit/443ab4d2e01246bf93cd410db945dc9ab6adf1b3.diff
LOG: [clang][Basic] Integrate SourceLocation with FoldingSet, NFCI
This patch removes the necessity to access the SourceLocation internal
representation in several places that use FoldingSet objects.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D69844
Added:
Modified:
clang/include/clang/Basic/SourceLocation.h
clang/lib/Analysis/PathDiagnostic.cpp
clang/lib/Basic/SourceLocation.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h
index 88ecb7c586d9..fc722b1d563d 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -26,6 +26,9 @@ namespace llvm {
template <typename T> struct DenseMapInfo;
+class FoldingSetNodeID;
+template <typename T> struct FoldingSetTrait;
+
} // namespace llvm
namespace clang {
@@ -87,6 +90,7 @@ class SourceLocation {
friend class ASTReader;
friend class ASTWriter;
friend class SourceManager;
+ friend struct llvm::FoldingSetTrait<SourceLocation>;
unsigned ID = 0;
@@ -501,6 +505,11 @@ namespace llvm {
}
};
+ // Allow calling FoldingSetNodeID::Add with SourceLocation object as parameter
+ template <> struct FoldingSetTrait<clang::SourceLocation> {
+ static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
+ };
+
// Teach SmallPtrSet how to handle SourceLocation.
template<>
struct PointerLikeTypeTraits<clang::SourceLocation> {
diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp
index f80b99b99806..b42f47fb68c5 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -1083,9 +1083,9 @@ unsigned PathDiagnostic::full_size() {
//===----------------------------------------------------------------------===//
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<const SourceLocation &>(Loc));
}
void PathDiagnosticPiece::Profile(llvm::FoldingSetNodeID &ID) const {
@@ -1095,8 +1095,8 @@ void PathDiagnosticPiece::Profile(llvm::FoldingSetNodeID &ID) const {
ID.AddInteger((unsigned) getDisplayHint());
ArrayRef<SourceRange> 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
index 2ff17973323e..fde139932c40 100644
--- 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 @@ unsigned SourceLocation::getHashValue() const {
return llvm::DenseMapInfo<unsigned>::getHashValue(ID);
}
+void llvm::FoldingSetTrait<SourceLocation>::Profile(
+ const SourceLocation &X, llvm::FoldingSetNodeID &ID) {
+ ID.AddInteger(X.ID);
+}
+
void SourceLocation::print(raw_ostream &OS, const SourceManager &SM)const{
if (!isValid()) {
OS << "<invalid loc>";
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index ebad1d1b67b4..bf38891b370a 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -2193,8 +2193,8 @@ void BasicBugReport::Profile(llvm::FoldingSetNodeID& hash) const {
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 @@ void PathSensitiveBugReport::Profile(llvm::FoldingSetNodeID &hash) const {
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());
}
}
More information about the cfe-commits
mailing list