llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir] `scf-parallel-loop-tiling` pass with `parallel-loop-tile-sizes=0` triggered Floating point exception and crashed.

Open Colloportus0 opened this issue 3 years ago • 4 comments

MLIR built at commit ed83797f Reproduced with:
mlir-opt "--scf-parallel-loop-tiling=parallel-loop-tile-sizes=0" temp.mlir

temp.mlir

trace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: mlir-opt --scf-parallel-loop-tiling=parallel-loop-tile-sizes=0 mlir/temp1627897143751579929344_9.mlir
 #0 0x0000557882cc21d2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/mlir-fuzz/llvm/lib/Support/Unix/Signals.inc:602:0
 #1 0x0000557882cc29d3 PrintStackTraceSignalHandler(void*) /data/mlir-fuzz/llvm/lib/Support/Unix/Signals.inc:674:0
 #2 0x0000557882cbded8 llvm::sys::RunSignalHandlers() /data/mlir-fuzz/llvm/lib/Support/Signals.cpp:104:0
 #3 0x0000557882cbe227 SignalHandler(int) /data/mlir-fuzz/llvm/lib/Support/Unix/Signals.inc:403:0
 #4 0x00007fbede4cb980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #5 0x0000557884849cbc mlir::scf::tileParallelLoop(mlir::scf::ParallelOp, llvm::ArrayRef<long>, bool) /data/mlir-fuzz/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp:117:0
 #6 0x000055788484bcca (anonymous namespace)::ParallelLoopTiling::runOnOperation() /data/mlir-fuzz/mlir/lib/Dialect/SCF/Transforms/ParallelLoopTiling.cpp:204:0
 #7 0x00005578862135b6 operator() /data/mlir-fuzz/mlir/lib/Pass/Pass.cpp:485:0
 #8 0x00005578862135b6 callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::<lambda()> > /data/mlir-fuzz/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:0
 #9 0x00005578862135b6 llvm::function_ref<void ()>::operator()() const /data/mlir-fuzz/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:0
#10 0x00005578862135b6 void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /data/mlir-fuzz/mlir/include/mlir/IR/MLIRContext.h:275:0
#11 0x00005578862135b6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /data/mlir-fuzz/mlir/lib/Pass/Pass.cpp:479:0
#12 0x0000557886214a07 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (.constprop.491) /data/mlir-fuzz/mlir/lib/Pass/Pass.cpp:551:0
#13 0x00005578862154a0 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /data/mlir-fuzz/mlir/lib/Pass/Pass.cpp:861:0
#14 0x00005578862154a0 mlir::PassManager::run(mlir::Operation*) /data/mlir-fuzz/mlir/lib/Pass/Pass.cpp:840:0
#15 0x00005578861ffdf4 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /data/mlir-fuzz/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:376:0
#16 0x00005578862004c2 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) /data/mlir-fuzz/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:430:0
#17 0x00005578862006f1 std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>::~unique_ptr() /usr/include/c++/7/bits/unique_ptr.h:262:0
#18 0x00005578862006f1 operator() /data/mlir-fuzz/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:473:0
#19 0x00005578862006f1 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&) /data/mlir-fuzz/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:0
#20 0x000055788633690c std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>::~unique_ptr() /usr/include/c++/7/bits/unique_ptr.h:262:0
#21 0x000055788633690c llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /data/mlir-fuzz/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:0
#22 0x000055788633690c 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) /data/mlir-fuzz/mlir/lib/Support/ToolUtilities.cpp:28:0
#23 0x00005578861fb271 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /data/mlir-fuzz/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:477:0
#24 0x0000557886200bbd std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>::~unique_ptr() /usr/include/c++/7/bits/unique_ptr.h:262:0
#25 0x0000557886200bbd mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /data/mlir-fuzz/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:531:0
#26 0x0000557882bf7f3d main /data/mlir-fuzz/mlir/tools/mlir-opt/mlir-opt.cpp:284:0
#27 0x00007fbedd389c87 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c87)
#28 0x0000557882c8a4ba _start (/data/mlir-fuzz/build/bin/mlir-opt+0x42134ba)
Floating point exception (core dumped)

Colloportus0 avatar Aug 02 '23 07:08 Colloportus0

@Colloportus0 Could you us the example input to reproduce the case?

Lewuathe avatar Aug 14 '23 06:08 Lewuathe

@Colloportus0 I've reproduced the bug at ToT.

It looks like the bug is being caused by the command line argument --scf-parallel-loop-tiling=parallel-loop-tile-sizes=0. More specifically, --scf-parallel-loop-tiling=parallel-loop-tile-sizes sets the tileSize variable to 0 on this line. tileSize is then used on this line causing a divide by zero exception.

It seems like a good next step could be to add an assert to ensure that --scf-parallel-loop-tiling=parallel-loop-tile-sizes isn't set to zero. Does that sound good on your end? If not, what kind of behavior were you expected from --scf-parallel-loop-tiling=parallel-loop-tile-sizes=0?

justinfargnoli avatar Oct 09 '23 01:10 justinfargnoli

In my humble opinion, the invalid option parameter should be rejected correctly instead of crashing.

You may refer to this commit https://github.com/SNSystems/llvm-debuginfo-analyzer/commit/730a827eeae5c1527b1f52fbfcd3250aa8e0672a which fixed a similar issue.

Colloportus0 avatar Oct 09 '23 02:10 Colloportus0

Can we close this issue if it's fixed. Thank you.

kavin-sai-krishna avatar Nov 09 '25 13:11 kavin-sai-krishna