[Mlir-commits] [mlir] [mlir] Fix UB in comparator lambdas in getRegisteredOperationsByDialect (PR #186428)

Mehdi Amini llvmlistbot at llvm.org
Fri Mar 13 09:10:35 PDT 2026


================
@@ -711,18 +711,18 @@ ArrayRef<RegisteredOperationName>
 MLIRContext::getRegisteredOperationsByDialect(StringRef dialectName) {
   auto *lowerBound = llvm::lower_bound(
       impl->sortedRegisteredOperations, dialectName, [](auto &lhs, auto &rhs) {
-        return lhs.getDialect().getNamespace().compare(rhs);
+        return lhs.getDialect().getNamespace().compare(rhs) < 0;
       });
 
   if (lowerBound == impl->sortedRegisteredOperations.end() ||
       lowerBound->getDialect().getNamespace() != dialectName)
     return ArrayRef<RegisteredOperationName>();
 
-  auto *upperBound =
-      std::upper_bound(lowerBound, impl->sortedRegisteredOperations.end(),
-                       dialectName, [](auto &lhs, auto &rhs) {
-                         return lhs.compare(rhs.getDialect().getNamespace());
-                       });
+  auto *upperBound = std::upper_bound(
+      lowerBound, impl->sortedRegisteredOperations.end(), dialectName,
+      [](auto &lhs, auto &rhs) {
+        return lhs.compare(rhs.getDialect().getNamespace()) < 0;
+      });
----------------
joker-eph wrote:

Only one is a stringref, made explicit now

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


More information about the Mlir-commits mailing list