Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MLIR][linalg] Parser crashes on transpose #97857

Closed
IanWood1 opened this issue Jul 5, 2024 · 5 comments · Fixed by #97944
Closed

[MLIR][linalg] Parser crashes on transpose #97857

IanWood1 opened this issue Jul 5, 2024 · 5 comments · Fixed by #97944

Comments

@IanWood1
Copy link

IanWood1 commented Jul 5, 2024

My mlir lsp crashed when working with linalg.transpose. The issue I was can be reproduced with mlir-opt, which crashes when parsing this mlir:

module {
  func.func private @transpose(%arg0 : tensor<10x10xi32>){
    %0 = linalg.transpose permutation = [0, 1]
  }
}

This crash occurs for both linalg.transpose and linalg.broadcast ops. It looks like the reason is that this occurs is that the call to buildIdentityRegion implicitly requires that the op has at least 1 bb arg.

buildIdentityRegion(builder, result.location, *result.addRegion(),
Defined here
static void buildIdentityRegion(OpBuilder &builder, Location loc,
Region &region, ValueRange inputs,
ValueRange outputs) {
buildGenericRegion(builder, loc, region, inputs, outputs,
[](OpBuilder &b, Location loc, ValueRange args) {
b.create<linalg::YieldOp>(loc, args[0]);
});
}

Trace:

STLExtras.h:1272: ReferenceT llvm::detail::indexed_accessor_range_base<mlir::ValueRange, llvm::PointerUnion<const 
mlir::Value *, mlir::OpOperand *, mlir::detail::OpResultImpl *>, mlir::Value, mlir::Value, mlir::Value>::operator[](size_t) const [DerivedT = mlir::ValueRange, BaseT = llvm::PointerUnion<const mlir::Value *, mlir::OpOperand *, mlir::detail::OpResultImpl *>, T = mlir::Value, PointerT = mlir::Value, ReferenceT = mlir::Value]: Assertion `Index < size() && "invalid index for value 
range"' failed.                                                           

 #0 0x00005ef82a40f887 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13                               
 #1 0x00005ef82a40dad0 llvm::sys::RunSignalHandlers() /iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:106:18                                                         
 #2 0x00005ef82a41020a SignalHandler(int) /iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1                                                                 
 #3 0x0000709d4f442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)                                                                                                                              
 #4 0x0000709d4f4969fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76                                                                                                       
 #5 0x0000709d4f4969fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #6 0x0000709d4f4969fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #7 0x0000709d4f442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x0000709d4f4287f3 abort ./stdlib/./stdlib/abort.c:81:7
 #9 0x0000709d4f42871b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#10 0x0000709d4f439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#11 0x00005ef82abe42c1 (./build/RelWithDebInfo/llvm-project/bin/mlir-opt+0x443d2c1)
#12 0x00005ef82aafc726 mlir::OpBuilder::InsertPoint::isSet() const /iree/third_party/llvm-project/mlir/include/mlir/IR/Builders.h:339:40
#13 0x00005ef82aafc726 mlir::OpBuilder::restoreInsertionPoint(mlir::OpBuilder::InsertPoint) /iree/third_party/llvm-project/mlir/include/mlir/IR/Builders.h:393:12
#14 0x00005ef82aafc726 mlir::OpBuilder::InsertionGuard::~InsertionGuard() /iree/third_party/llvm-project/mlir/include/mlir/IR/Builders.h:357:18
#15 0x00005ef82aafc726 buildGenericRegion(mlir::OpBuilder&, mlir::Location, mlir::Region&, mlir::ValueRange, mlir::ValueRange, llvm::function_ref<void (mlir::OpBuilder&, mlir::Location, mlir
::ValueRange)>) /iree/third_party/llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:916:1
#16 0x00005ef82ab04619 buildIdentityRegion(mlir::OpBuilder&, mlir::Location, mlir::Region&, mlir::ValueRange, mlir::ValueRange) /iree/third_party/llvm-project/mlir/lib/Dialect/L
inalg/IR/LinalgOps.cpp:0:3
#17 0x00005ef82ab04619 mlir::linalg::TransposeOp::parse(mlir::OpAsmParser&, mlir::OperationState&) /iree/third_party/llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:1780:3
#18 0x00005ef82e35e2cb llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#19 0x00005ef82e35e2cb llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#20 0x00005ef82e35e2cb (anonymous namespace)::CustomOpAsmParser::parseOperation(mlir::OperationState&) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1521:9
#21 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseCustomOperation(llvm::ArrayRef<std::tuple<llvm::StringRef, unsigned int, llvm::SMLoc> >) /iree/third_party/ll
vm-project/mlir/lib/AsmParser/Parser.cpp:2017:19
#22 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseOperation() /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1174:10
#23 0x00005ef82e367f80 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#24 0x00005ef82e367f80 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#25 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlockBody(mlir::Block*) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2296:9
#26 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlock(mlir::Block*&) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2226:12
#27 0x00005ef82e365f22 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#28 0x00005ef82e365f22 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#29 0x00005ef82e365f22 (anonymous namespace)::OperationParser::parseRegionBody(mlir::Region&, llvm::SMLoc, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/l
lvm-project/mlir/lib/AsmParser/Parser.cpp:2184:7
#30 0x00005ef82e365f22 (anonymous namespace)::OperationParser::parseRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/llvm-project/mlir/
lib/AsmParser/Parser.cpp:2121:7
#31 0x00005ef82e3644a9 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#32 0x00005ef82e3644a9 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#33 0x00005ef82e3644a9 (anonymous namespace)::CustomOpAsmParser::parseRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/llvm-project/mli
r/lib/AsmParser/Parser.cpp:1785:9                                                                                                                                                             
#34 0x00005ef82e3644ec (anonymous namespace)::CustomOpAsmParser::parseOptionalRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/llvm-pro
ject/mlir/lib/AsmParser/Parser.cpp:1796:5                                                                                                                                                     
#35 0x00005ef82e3227ef std::_Optional_base_impl<llvm::ParseResult, std::_Optional_base<llvm::ParseResult, true, true> >::_M_is_engaged() const /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../.
./../include/c++/11/optional:433:58                                                                                                                                                           
#36 0x00005ef82e3227ef std::optional<llvm::ParseResult>::has_value() const /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/optional:945:22                                 
#37 0x00005ef82e3227ef mlir::OptionalParseResult::has_value() const /iree/third_party/llvm-project/mlir/include/mlir/IR/OpDefinition.h:49:40                                     
#38 0x00005ef82e3227ef mlir::function_interface_impl::parseFunctionOp(mlir::OpAsmParser&, mlir::OperationState&, bool, mlir::StringAttr, llvm::function_ref<mlir::Type (mlir::Builder&, llvm::
ArrayRef<mlir::Type>, llvm::ArrayRef<mlir::Type>, mlir::function_interface_impl::VariadicFlag, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)>, mlir::Strin
gAttr, mlir::StringAttr) /iree/third_party/llvm-project/mlir/lib/Interfaces/FunctionImplementation.cpp:234:19
#39 0x00005ef82a939348 mlir::func::FuncOp::parse(mlir::OpAsmParser&, mlir::OperationState&) /iree/third_party/llvm-project/mlir/lib/Dialect/Func/IR/FuncOps.cpp:203:10
#40 0x00005ef82e35e2cb llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#41 0x00005ef82e35e2cb llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#42 0x00005ef82e35e2cb (anonymous namespace)::CustomOpAsmParser::parseOperation(mlir::OperationState&) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1521:9
#43 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseCustomOperation(llvm::ArrayRef<std::tuple<llvm::StringRef, unsigned int, llvm::SMLoc> >) /iree/third_party/ll
vm-project/mlir/lib/AsmParser/Parser.cpp:2017:19
#44 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseOperation() /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1174:10
#45 0x00005ef82e367f80 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#46 0x00005ef82e367f80 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#47 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlockBody(mlir::Block*) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2296:9
#48 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlock(mlir::Block*&) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2226:12
#49 0x00005ef82e365d79 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#50 0x00005ef82e365d79 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#51 0x00005ef82e365d79 (anonymous namespace)::OperationParser::parseRegionBody(mlir::Region&, llvm::SMLoc, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/l
lvm-project/mlir/lib/AsmParser/Parser.cpp:2184:7
#52 0x00005ef82e365d79 (anonymous namespace)::OperationParser::parseRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/llvm-project/mlir/
lib/AsmParser/Parser.cpp:2121:7
#53 0x00005ef82e3644a9 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#54 0x00005ef82e3644a9 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#55 0x00005ef82e3644a9 (anonymous namespace)::CustomOpAsmParser::parseRegion(mlir::Region&, llvm::ArrayRef<mlir::OpAsmParser::Argument>, bool) /iree/third_party/llvm-project/mli
r/lib/AsmParser/Parser.cpp:1785:9
#56 0x00005ef82cb8f249 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#57 0x00005ef82cb8f249 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#58 0x00005ef82cb8f249 mlir::ModuleOp::parse(mlir::OpAsmParser&, mlir::OperationState&) /iree/build/RelWithDebInfo/llvm-project/tools/mlir/include/mlir/IR/BuiltinOps.cpp.inc:293
:7
#59 0x00005ef82e35e2cb llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 5, 2024

@llvm/issue-subscribers-mlir-linalg

Author: Ian Wood (IanWood1)

My mlir lsp crashed when working with linalg.transpose. The issue I was can be reproduced with `mlir-opt`, which crashes when parsing this mlir:
module {
  func.func private @<!-- -->transpose(%arg0 : tensor&lt;10x10xi32&gt;){
    %0 = linalg.transpose permutation = [0, 1]
  }
}

This crash occurs for both linalg.transpose and linalg.broadcast ops. It looks like the reason is that this occurs is that the call to buildIdentityRegion implicitly requires that the op has at least 1 bb arg.

buildIdentityRegion(builder, result.location, *result.addRegion(),
Defined here
static void buildIdentityRegion(OpBuilder &builder, Location loc,
Region &region, ValueRange inputs,
ValueRange outputs) {
buildGenericRegion(builder, loc, region, inputs, outputs,
[](OpBuilder &b, Location loc, ValueRange args) {
b.create<linalg::YieldOp>(loc, args[0]);
});
}

Trace:

STLExtras.h:1272: ReferenceT llvm::detail::indexed_accessor_range_base&lt;mlir::ValueRange, llvm::PointerUnion&lt;const 
mlir::Value *, mlir::OpOperand *, mlir::detail::OpResultImpl *&gt;, mlir::Value, mlir::Value, mlir::Value&gt;::operator[](size_t) const [DerivedT = mlir::ValueRange, BaseT = llvm::PointerUnion&lt;const mlir::Value *, mlir::OpOperand *, mlir::detail::OpResultImpl *&gt;, T = mlir::Value, PointerT = mlir::Value, ReferenceT = mlir::Value]: Assertion `Index &lt; size() &amp;&amp; "invalid index for value 
range"' failed.                                                           

 #<!-- -->0 0x00005ef82a40f887 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13                               
 #<!-- -->1 0x00005ef82a40dad0 llvm::sys::RunSignalHandlers() /iree/third_party/llvm-project/llvm/lib/Support/Signals.cpp:106:18                                                         
 #<!-- -->2 0x00005ef82a41020a SignalHandler(int) /iree/third_party/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1                                                                 
 #<!-- -->3 0x0000709d4f442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)                                                                                                                              
 #<!-- -->4 0x0000709d4f4969fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76                                                                                                       
 #<!-- -->5 0x0000709d4f4969fc __pthread_kill_internal ./nptl/./nptl/pthread_kill.c:78:10
 #<!-- -->6 0x0000709d4f4969fc pthread_kill ./nptl/./nptl/pthread_kill.c:89:10
 #<!-- -->7 0x0000709d4f442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->8 0x0000709d4f4287f3 abort ./stdlib/./stdlib/abort.c:81:7
 #<!-- -->9 0x0000709d4f42871b _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#<!-- -->10 0x0000709d4f439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->11 0x00005ef82abe42c1 (./build/RelWithDebInfo/llvm-project/bin/mlir-opt+0x443d2c1)
#<!-- -->12 0x00005ef82aafc726 mlir::OpBuilder::InsertPoint::isSet() const /iree/third_party/llvm-project/mlir/include/mlir/IR/Builders.h:339:40
#<!-- -->13 0x00005ef82aafc726 mlir::OpBuilder::restoreInsertionPoint(mlir::OpBuilder::InsertPoint) /iree/third_party/llvm-project/mlir/include/mlir/IR/Builders.h:393:12
#<!-- -->14 0x00005ef82aafc726 mlir::OpBuilder::InsertionGuard::~InsertionGuard() /iree/third_party/llvm-project/mlir/include/mlir/IR/Builders.h:357:18
#<!-- -->15 0x00005ef82aafc726 buildGenericRegion(mlir::OpBuilder&amp;, mlir::Location, mlir::Region&amp;, mlir::ValueRange, mlir::ValueRange, llvm::function_ref&lt;void (mlir::OpBuilder&amp;, mlir::Location, mlir
::ValueRange)&gt;) /iree/third_party/llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:916:1
#<!-- -->16 0x00005ef82ab04619 buildIdentityRegion(mlir::OpBuilder&amp;, mlir::Location, mlir::Region&amp;, mlir::ValueRange, mlir::ValueRange) /iree/third_party/llvm-project/mlir/lib/Dialect/L
inalg/IR/LinalgOps.cpp:0:3
#<!-- -->17 0x00005ef82ab04619 mlir::linalg::TransposeOp::parse(mlir::OpAsmParser&amp;, mlir::OperationState&amp;) /iree/third_party/llvm-project/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp:1780:3
#<!-- -->18 0x00005ef82e35e2cb llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->19 0x00005ef82e35e2cb llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->20 0x00005ef82e35e2cb (anonymous namespace)::CustomOpAsmParser::parseOperation(mlir::OperationState&amp;) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1521:9
#<!-- -->21 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseCustomOperation(llvm::ArrayRef&lt;std::tuple&lt;llvm::StringRef, unsigned int, llvm::SMLoc&gt; &gt;) /iree/third_party/ll
vm-project/mlir/lib/AsmParser/Parser.cpp:2017:19
#<!-- -->22 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseOperation() /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1174:10
#<!-- -->23 0x00005ef82e367f80 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->24 0x00005ef82e367f80 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->25 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlockBody(mlir::Block*) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2296:9
#<!-- -->26 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlock(mlir::Block*&amp;) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2226:12
#<!-- -->27 0x00005ef82e365f22 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->28 0x00005ef82e365f22 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->29 0x00005ef82e365f22 (anonymous namespace)::OperationParser::parseRegionBody(mlir::Region&amp;, llvm::SMLoc, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/l
lvm-project/mlir/lib/AsmParser/Parser.cpp:2184:7
#<!-- -->30 0x00005ef82e365f22 (anonymous namespace)::OperationParser::parseRegion(mlir::Region&amp;, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/llvm-project/mlir/
lib/AsmParser/Parser.cpp:2121:7
#<!-- -->31 0x00005ef82e3644a9 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->32 0x00005ef82e3644a9 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->33 0x00005ef82e3644a9 (anonymous namespace)::CustomOpAsmParser::parseRegion(mlir::Region&amp;, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/llvm-project/mli
r/lib/AsmParser/Parser.cpp:1785:9                                                                                                                                                             
#<!-- -->34 0x00005ef82e3644ec (anonymous namespace)::CustomOpAsmParser::parseOptionalRegion(mlir::Region&amp;, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/llvm-pro
ject/mlir/lib/AsmParser/Parser.cpp:1796:5                                                                                                                                                     
#<!-- -->35 0x00005ef82e3227ef std::_Optional_base_impl&lt;llvm::ParseResult, std::_Optional_base&lt;llvm::ParseResult, true, true&gt; &gt;::_M_is_engaged() const /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../.
./../include/c++/11/optional:433:58                                                                                                                                                           
#<!-- -->36 0x00005ef82e3227ef std::optional&lt;llvm::ParseResult&gt;::has_value() const /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/optional:945:22                                 
#<!-- -->37 0x00005ef82e3227ef mlir::OptionalParseResult::has_value() const /iree/third_party/llvm-project/mlir/include/mlir/IR/OpDefinition.h:49:40                                     
#<!-- -->38 0x00005ef82e3227ef mlir::function_interface_impl::parseFunctionOp(mlir::OpAsmParser&amp;, mlir::OperationState&amp;, bool, mlir::StringAttr, llvm::function_ref&lt;mlir::Type (mlir::Builder&amp;, llvm::
ArrayRef&lt;mlir::Type&gt;, llvm::ArrayRef&lt;mlir::Type&gt;, mlir::function_interface_impl::VariadicFlag, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;)&gt;, mlir::Strin
gAttr, mlir::StringAttr) /iree/third_party/llvm-project/mlir/lib/Interfaces/FunctionImplementation.cpp:234:19
#<!-- -->39 0x00005ef82a939348 mlir::func::FuncOp::parse(mlir::OpAsmParser&amp;, mlir::OperationState&amp;) /iree/third_party/llvm-project/mlir/lib/Dialect/Func/IR/FuncOps.cpp:203:10
#<!-- -->40 0x00005ef82e35e2cb llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->41 0x00005ef82e35e2cb llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->42 0x00005ef82e35e2cb (anonymous namespace)::CustomOpAsmParser::parseOperation(mlir::OperationState&amp;) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1521:9
#<!-- -->43 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseCustomOperation(llvm::ArrayRef&lt;std::tuple&lt;llvm::StringRef, unsigned int, llvm::SMLoc&gt; &gt;) /iree/third_party/ll
vm-project/mlir/lib/AsmParser/Parser.cpp:2017:19
#<!-- -->44 0x00005ef82e35e2cb (anonymous namespace)::OperationParser::parseOperation() /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:1174:10
#<!-- -->45 0x00005ef82e367f80 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->46 0x00005ef82e367f80 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->47 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlockBody(mlir::Block*) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2296:9
#<!-- -->48 0x00005ef82e367f80 (anonymous namespace)::OperationParser::parseBlock(mlir::Block*&amp;) /iree/third_party/llvm-project/mlir/lib/AsmParser/Parser.cpp:2226:12
#<!-- -->49 0x00005ef82e365d79 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->50 0x00005ef82e365d79 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->51 0x00005ef82e365d79 (anonymous namespace)::OperationParser::parseRegionBody(mlir::Region&amp;, llvm::SMLoc, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/l
lvm-project/mlir/lib/AsmParser/Parser.cpp:2184:7
#<!-- -->52 0x00005ef82e365d79 (anonymous namespace)::OperationParser::parseRegion(mlir::Region&amp;, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/llvm-project/mlir/
lib/AsmParser/Parser.cpp:2121:7
#<!-- -->53 0x00005ef82e3644a9 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->54 0x00005ef82e3644a9 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->55 0x00005ef82e3644a9 (anonymous namespace)::CustomOpAsmParser::parseRegion(mlir::Region&amp;, llvm::ArrayRef&lt;mlir::OpAsmParser::Argument&gt;, bool) /iree/third_party/llvm-project/mli
r/lib/AsmParser/Parser.cpp:1785:9
#<!-- -->56 0x00005ef82cb8f249 llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43
#<!-- -->57 0x00005ef82cb8f249 llvm::ParseResult::operator bool() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:124:53
#<!-- -->58 0x00005ef82cb8f249 mlir::ModuleOp::parse(mlir::OpAsmParser&amp;, mlir::OperationState&amp;) /iree/build/RelWithDebInfo/llvm-project/tools/mlir/include/mlir/IR/BuiltinOps.cpp.inc:293
:7
#<!-- -->59 0x00005ef82e35e2cb llvm::LogicalResult::failed() const /iree/third_party/llvm-project/llvm/include/llvm/Support/LogicalResult.h:43:43

@ubfx
Copy link
Member

ubfx commented Jul 7, 2024

The Destination Style Op parsing treating both ins() and outs() as optional - so we can end up with a state without any operands. This also leads to a crash in the MapOp parser for example:

module {
  func.func private @transpose(%arg0 : tensor<10x10xi32>){
    //%0 = linalg.transpose permutation = [0, 1]
    %add = linalg.map { arith.addf }
  }
}

@matthias-springer
Copy link
Member

All Linalg dialect ops that I am aware of require at least one output operand. We should check that in the verifier. I wouldn't add it to the DestinationStyleOpInterface because there could be destination-style ops without any inputs and outputs.

@ubfx
Copy link
Member

ubfx commented Jul 7, 2024

We should check that in the verifier

In this specific case, we won't even get to that point in the verifier, because (after fixing the invalid array access during region creation) it will error out like this:

test.mlir:4:5: error: cannot name an operation with no results
    %1 = linalg.broadcast dimensions = [0, 1]

And when we take away the result, it will still error out because the number of operands is incorrect:

test.mlir:4:5: error: 'linalg.broadcast' op expected 2 operands, but found 0
    linalg.broadcast dimensions = [0, 1]
    ^

But we could add an additional check guaranteeing that at least one operand has to be an outs

@matthias-springer
Copy link
Member

Oh, this is crashing already in the builder...

ubfx added a commit to ubfx/llvm-project that referenced this issue Jul 7, 2024
`parseDstStyleOp` parses both `ins()` and `outs()` optionally. The parsers
for `linalg.transpose`, `linalg.broadcast` and `linalg.map` however
assume that at least one operand is present in the state, leading to crashes
otherwise.

This patch adds checks to the parsers which stop them from crashing if
no operands were parsed. After the Ops are parsed successfuly, the verifier
takes it from there.

Fix llvm#97857
@ubfx ubfx closed this as completed in c65f8d8 Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants