Skip to content

[LLVM][ADT] Add specialization of DenseMapInfo for SourceRange#174524

Merged
localspook merged 4 commits intollvm:mainfrom
localspook:sourcerange-in-densemap
Jan 6, 2026
Merged

[LLVM][ADT] Add specialization of DenseMapInfo for SourceRange#174524
localspook merged 4 commits intollvm:mainfrom
localspook:sourcerange-in-densemap

Conversation

@localspook
Copy link
Contributor

No description provided.

@localspook localspook marked this pull request as ready for review January 6, 2026 04:05
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 6, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 6, 2026

@llvm/pr-subscribers-clang

Author: Victor Chernyakin (localspook)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/174524.diff

1 Files Affected:

  • (modified) clang/include/clang/Basic/SourceLocation.h (+21)
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

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this unit-testable

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add unit tests?

@localspook localspook force-pushed the sourcerange-in-densemap branch from 0f2b5b6 to adad670 Compare January 6, 2026 15:31
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

🐧 Linux x64 Test Results

  • 112555 tests passed
  • 4594 tests skipped

✅ The build succeeded and all tests passed.

@localspook localspook merged commit 9c2b1ba into llvm:main Jan 6, 2026
10 checks passed
@localspook localspook deleted the sourcerange-in-densemap branch January 6, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants