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]-test-elements-attr-interface pass crashes in SparseElementsAttr::getZeroAPInt() with assertion failure `isa<To>(Val) && "cast<Ty>() argument of incompatible type!" #61871

Closed
BealZephyr opened this issue Mar 31, 2023 · 3 comments · Fixed by #69878
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir

Comments

@BealZephyr
Copy link

BealZephyr commented Mar 31, 2023

Test commit: e7281c6

Steps to reproduce:

mlir-opt test.mlir -test-elements-attr-interface

Test case:

"test.sparse_attr"() {foo.sparse_attr = sparse<[[0, 0, 5]],  -2.0> : vector<1x1x10xf16>} : () -> ()

Crash trace:

mlir-opt: /home/ty/llvm-project/llvm/include/llvm/Support/Casting.h:567: decltype(auto) llvm::cast(const From&) [with To = mlir::IntegerType; From = mlir::Type]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/ty/llvm-project/build/bin/mlir-opt test.mlir -test-elements-attr-interface
 #0 0x000055f0b4a5d60a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ty/llvm-project/build/bin/mlir-opt+0x22b60a)
 #1 0x000055f0b4a5a89c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f7315be3980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #3 0x00007f7314894e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #4 0x00007f73148967f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #5 0x00007f73148863fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #6 0x00007f7314886472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #7 0x000055f0b649e6f6 mlir::SparseElementsAttr::getZeroAPInt() const (/home/ty/llvm-project/build/bin/mlir-opt+0x1c6c6f6)
 #8 0x000055f0b64a76bc mlir::FailureOr<llvm::mapped_iterator<llvm::detail::SafeIntIterator<long, false>, std::function<llvm::APInt (long)>, decltype(declval<std::function<llvm::APInt (long)>>()(declval<llvm::detail::SafeIntIterator<long, false>>().llvm::detail::SafeIntIterator<long, false>::operator*() const()))>> mlir::SparseElementsAttr::try_value_begin_impl<llvm::APInt>(mlir::detail::ElementsAttrTrait<mlir::SparseElementsAttr>::OverloadToken<llvm::APInt>) const (/home/ty/llvm-project/build/bin/mlir-opt+0x1c756bc)
 #9 0x000055f0b64adfb1 mlir::detail::ElementsAttrInterfaceTraits::Model<mlir::SparseElementsAttr>::getValuesImpl(mlir::detail::ElementsAttrInterfaceTraits::Concept const*, mlir::Attribute, mlir::TypeID) (/home/ty/llvm-project/build/bin/mlir-opt+0x1c7bfb1)
#10 0x000055f0b6483247 mlir::ElementsAttr::getValuesImpl(mlir::TypeID) const (/home/ty/llvm-project/build/bin/mlir-opt+0x1c51247)
#11 0x000055f0b5a86b7e _ZNK4mlir12ElementsAttr15try_value_beginIN4llvm5APIntEEENSt9enable_ifIXoosrSt7is_sameINS_9AttributeET_E5valuentsrSt10is_base_ofIS6_S7_E5valueESt8optionalINS_6detail20ElementsAttrIteratorIS7_EEEE4typeEv (/home/ty/llvm-project/build/bin/mlir-opt+0x1254b7e)
#12 0x000055f0b623abfc void (anonymous namespace)::TestElementsAttrInterface::testElementsAttrIteration<llvm::APInt>(mlir::Operation*, mlir::ElementsAttr, llvm::StringRef) (.isra.175.constprop.186) TestBuiltinAttributeInterfaces.cpp:0:0
#13 0x000055f0b623dde1 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::TestElementsAttrInterface::runOnOperation()::'lambda'(mlir::Operation*)>(long, mlir::Operation*) TestBuiltinAttributeInterfaces.cpp:0:0
#14 0x000055f0b623d4b5 (anonymous namespace)::TestElementsAttrInterface::runOnOperation() TestBuiltinAttributeInterfaces.cpp:0:0
#15 0x000055f0b637d9be mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b4b9be)
#16 0x000055f0b637e813 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (.constprop.510) Pass.cpp:0:0
#17 0x000055f0b637ee9d mlir::PassManager::run(mlir::Operation*) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b4ce9d)
#18 0x000055f0b6372e13 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#19 0x000055f0b63734e1 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#20 0x000055f0b63736d1 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#21 0x000055f0b64455e0 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/home/ty/llvm-project/build/bin/mlir-opt+0x1c135e0)
#22 0x000055f0b636e7f3 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b3c7f3)
#23 0x000055f0b637101e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b3f01e)
#24 0x000055f0b4a29570 main (/home/ty/llvm-project/build/bin/mlir-opt+0x1f7570)
#25 0x00007f7314877c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#26 0x000055f0b4a3c3da _start (/home/ty/llvm-project/build/bin/mlir-opt+0x20a3da)
@EugeneZelenko EugeneZelenko added mlir crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Mar 31, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 31, 2023

@llvm/issue-subscribers-mlir

@sott0n
Copy link
Contributor

sott0n commented May 30, 2023

Patch submitted at https://reviews.llvm.org/D151675

@EugeneZelenko
Copy link
Contributor

Patch was not committed yet.

@EugeneZelenko EugeneZelenko reopened this Jul 15, 2023
rikhuijzer added a commit that referenced this issue Oct 23, 2023
Fixes #61871 and fixes #60581.

This PR fixes two small things. First and foremost, it throws a clear
error in the `-test-elements-attr-interface` when those tests are called
on elements which are not an integer. I've looked through the
introduction of the attribute interface
(https://reviews.llvm.org/D109190) and later commits and see no evidence
that the interface (`attr.tryGetValues<T>()`) is expected to handle
mismatching types.

For example, the case which is given in #61871 is:
```mlir
arith.constant sparse<[[0, 0, 5]],  -2.0> : vector<1x1x10xf16>
```
So, a sparse vector containing `f16` elements. This will crash at
various locations when called in the test because the test introduces
integer types (`int64_t`, `uint64_t`, `APInt`, `IntegerAttr`), but as I
said in the previous paragraph: I see no reason to believe that the
implementation of the interface is wrong here. The interface just
assumes that clients don't do things like `attr.tryGetValues<APInt>()`
on a floating point `attr`.

Also I've added a test for the implementation of this interface by the
`sparse` dialect. There were no problems there. Still, probably good to
increase code coverage on that one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants