[clang] [LLVM][ADT] Add specialization of `DenseMapInfo` for `SourceRange` (PR #174524)

Victor Chernyakin via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 5 19:26:41 PST 2026


https://github.com/localspook created https://github.com/llvm/llvm-project/pull/174524

None

>From 0f765712a6c5586478656998f15a3b581f09d704 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Mon, 5 Jan 2026 19:24:37 -0800
Subject: [PATCH] [LLVM][ADT] Add specialization of `DenseMapInfo` for
 `SourceRange`

---
 clang/include/clang/Basic/SourceLocation.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/clang/include/clang/Basic/SourceLocation.h b/clang/include/clang/Basic/SourceLocation.h
index 14543cc41a38e..85fe65901d207 100644
--- a/clang/include/clang/Basic/SourceLocation.h
+++ b/clang/include/clang/Basic/SourceLocation.h
@@ -521,6 +521,27 @@ namespace llvm {
     static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID);
   };
 
+  template <> struct DenseMapInfo<clang::SourceRange, void> {
+    static clang::SourceRange getEmptyKey() {
+      return {DenseMapInfo<clang::SourceLocation>::getEmptyKey(),
+              DenseMapInfo<clang::SourceLocation>::getEmptyKey()};
+    }
+
+    static clang::SourceRange getTombstoneKey() {
+      return {DenseMapInfo<clang::SourceLocation>::getTombstoneKey(),
+              DenseMapInfo<clang::SourceLocation>::getTombstoneKey()};
+    }
+
+    static unsigned getHashValue(clang::SourceRange Range) {
+      return detail::combineHashValue(Range.getBegin().getHashValue(),
+                                      Range.getEnd().getHashValue());
+    }
+
+    static bool isEqual(clang::SourceRange LHS, clang::SourceRange RHS) {
+      return LHS == RHS;
+    }
+  };
+
 } // namespace llvm
 
 #endif // LLVM_CLANG_BASIC_SOURCELOCATION_H



More information about the cfe-commits mailing list