[llvm] [SCEVPatternMatch] Fix constness issues (PR #138834)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Wed May 7 04:06:01 PDT 2025


================
@@ -18,13 +18,12 @@
 namespace llvm {
 namespace SCEVPatternMatch {
 
-template <typename Val, typename Pattern>
-bool match(const SCEV *S, const Pattern &P) {
-  return P.match(S);
+template <typename Pattern> bool match(const SCEV *S, const Pattern &P) {
+  return const_cast<Pattern &>(P).match(S);
----------------
artagnon wrote:

It's actually required because PatternMatch.h hasn't marked match functions `const`, and ScalarEvolution.cpp uses PatternMatch with SCEVPatternMatch:

```cpp
 10590 |   if (match(Step, m_CombineOr(m_scev_One(), m_scev_AllOnes()))) {
```

I can remove this in a follow-up, by marking match functions `const` in PatternMatch?

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


More information about the llvm-commits mailing list