[clang] [analyzer] Allow SVals as llvm::Immutable{Map, Set} keys (PR #205319)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 23 05:27:22 PDT 2026


================
@@ -529,6 +534,31 @@ class ConcreteInt : public Loc {
 } // namespace clang
 
 namespace llvm {
+// Allow SVal to be used as a key in ImmutableSet / ImmutableMap.
+template <>
+struct ImutContainerInfo<clang::ento::SVal>
+    : public ImutProfileInfo<clang::ento::SVal> {
+  using value_type = clang::ento::SVal;
+  using value_type_ref = clang::ento::SVal;
+  using key_type = value_type;
+  using key_type_ref = value_type_ref;
+  using data_type = bool;
+  using data_type_ref = bool;
+
+  static key_type_ref KeyOfValue(value_type_ref D) { return D; }
+  static data_type_ref DataOfValue(value_type_ref) { return true; }
+
+  static bool isEqual(clang::ento::SVal L, clang::ento::SVal R) {
+    return L == R;
+  }
+
+  static bool isLess(clang::ento::SVal L, clang::ento::SVal R) {
+    return std::tie(L.Data, L.Kind) < std::tie(R.Data, R.Kind);
----------------
steakhal wrote:

Great idea. I've delegate to SVal::operator< in https://github.com/llvm/llvm-project/pull/205319/commits/a53966739756696c61f27227a97d1c52a733958d.

I've decided to swap the order of the fields in the equality check in https://github.com/llvm/llvm-project/pull/205319/commits/874d6af0d0f54b1ce78b42199d8fd1b8face8019.
This way it meets the expected order: declaration order, just like it would behave with the spaceship operator.

Remember, for equality checks the order didn't matter (module shorcircuiting).

https://github.com/llvm/llvm-project/pull/205319


More information about the cfe-commits mailing list