Skip to content

[MLIR] getRegisteredOperationsByDialect comparator lambdas return int instead of bool, causing incorrect operation filtering #146940

@rpavlovicTT

Description

@rpavlovicTT

The implementation of MLIRContext::getRegisteredOperationsByDialect uses std::lower_bound and std::upper_bound with comparator lambdas that return the result of StringRef::compare() directly (an int), instead of a boolean. Since these standard algorithms require comparators returning bool representing a strict weak ordering, returning an int causes undefined behavior and leads to incorrect or empty results when filtering operations by dialect.

Proposed fix:

// lower_bound comparator
[](const RegisteredOperationName &lhs, StringRef dialectName) {
  return lhs.getDialect().getNamespace() < dialectName;
}

// upper_bound comparator
[](StringRef dialectName, const RegisteredOperationName &rhs) {
  return dialectName < rhs.getDialect().getNamespace();
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions