[Mlir-commits] [mlir] [MLIR][Linalg] Fix crash when parsing linalg.elementwise with vector inputs (#178363) (PR #179170)

Matthias Springer llvmlistbot at llvm.org
Mon Feb 2 00:34:20 PST 2026


================
@@ -4847,12 +4847,57 @@ ParseResult ElementwiseOp::parse(OpAsmParser &parser, OperationState &result) {
   auto arityGroupAndKind = getArityGroupAndKind(elemwiseKindVal);
   int numRegionArgs =
       getArityGroupAsUInt(arityGroupAndKind.arityGroup) + 1 /*output*/;
-  if (parseNamedStructuredOp(parser, result, numRegionArgs,
-                             ElementwiseOp::getRegionBuilder())) {
----------------
matthias-springer wrote:

This does not seem to be the right fix to me. This is not a random crash, but an `llvm_unreachable`. And there is already error handling code in place:
```c++
  // Build the binary functions defined by OpDSL.
  // If emitError is provided, an error will be emitted if the operation is not
  // supported and a nullptr will be returned, otherwise an assertion will be
  // raised.
  Value buildBinaryFn(BinaryFn binaryFn, Value arg0, Value arg1,
                      function_ref<InFlightDiagnostic()> emitError = {}) {
    bool allComplex = isComplex(arg0) && isComplex(arg1);
    bool allFloatingPoint = isFloatingPoint(arg0) && isFloatingPoint(arg1);
    bool allInteger = isInteger(arg0) && isInteger(arg1);
    bool allBool = allInteger && arg0.getType().getIntOrFloatBitWidth() == 1 &&
                   arg1.getType().getIntOrFloatBitWidth() == 1;
    if (!allComplex && !allFloatingPoint && !allInteger) {
      if (emitError) {
        emitError()
            << "Cannot build binary Linalg operation: expects allComplex, "
               "allFloatingPoint, or allInteger, got "
            << arg0.getType() << " and " << arg1.getType();
        return nullptr;
      }
      llvm_unreachable("unsupported non numeric type");
    }
```

`emitError` is not set. I found at least one place where `emitError` is not propagated: `ElementwiseOp::regionBuilder`.


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


More information about the Mlir-commits mailing list