Author: Balázs Benics
Date: 2026-06-23T13:35:32Z
New Revision: d957d2f2d8e718bd1101e7afad6be62901304cd1

URL: 
https://github.com/llvm/llvm-project/commit/d957d2f2d8e718bd1101e7afad6be62901304cd1
DIFF: 
https://github.com/llvm/llvm-project/commit/d957d2f2d8e718bd1101e7afad6be62901304cd1.diff

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

This will allow maps and sets being declared:
```
REGISTER_MAP_WITH_PROGRAMSTATE(MyMap, SVal, SVal)
REGISTER_SET_WITH_PROGRAMSTATE(MySet, SVal)
```

Added: 
    

Modified: 
    clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
index aeb57b28077c6..0561a2b8d1d77 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
@@ -22,6 +22,7 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/ImmutableList.h"
+#include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/iterator_range.h"
@@ -99,7 +100,12 @@ class SVal {
     ID.AddInteger(llvm::to_underlying(getKind()));
   }
 
-  bool operator==(SVal R) const { return Kind == R.Kind && Data == R.Data; }
+  bool operator<(SVal R) const {
+    return std::tie(Data, Kind) < std::tie(R.Data, R.Kind);
+  }
+  bool operator==(SVal R) const {
+    return std::tie(Data, Kind) == std::tie(R.Data, R.Kind);
+  }
   bool operator!=(SVal R) const { return !(*this == R); }
 
   bool isUnknown() const { return getKind() == UnknownValKind; }
@@ -529,6 +535,29 @@ 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 L < R; 
}
+
+  static bool isDataEqual(data_type_ref, data_type_ref) { return true; }
+};
+
 template <typename To, typename From>
 struct CastInfo<
     To, From,


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to