llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.12k stars 11.61k forks source link

[mlir] -ensure-debug-info-scope-on-llvm-func crashes #108390

Open axeabc opened 1 week ago

axeabc commented 1 week ago

git version: 8168088f0a9015b

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt -ensure-debug-info-scope-on-llvm-func a.mlir

a.mlir:

module {
  func.func @test(%arg0: memref<3x2xi8>) -> memref<2x3xi8> {
    %0 = bufferization.to_tensor %arg0 : memref<3x2xi8>
    %1 = tosa.reshape %0 {new_shape = array<i64: 2, 3>} : (tensor<3x2xi8>) -> tensor<2x3xi8>
    %2 = bufferization.to_memref %1 : memref<2x3xi8>
    return %2 : memref<2x3xi8>
  }
}

stack trace:

LLVM ERROR: can't create Attribute 'mlir::LLVM::DIFileAttr' because storage uniquer isn't initialized: the dialect was likely not loaded, or the attribute wasn't added with addAttributes<...>() in the Dialect::initialize() method.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt -ensure-debug-info-scope-on-llvm-func a.mlir
 #0 0x00005595184772c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10dc2c8)
 #1 0x0000559518474dde llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d9dde)
 #2 0x0000559518477c5d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007effd1388420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007effd09c500b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007effd09a4859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x0000559518496f67 llvm::report_fatal_error(llvm::Twine const&, bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10fbf67)
 #7 0x00005595196254fa (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x228a4fa)
 #8 0x00005595195fb041 mlir::LLVM::DIFileAttr::get(mlir::MLIRContext*, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2260041)
 #9 0x00005595195d138e (anonymous namespace)::DIScopeForLLVMFuncOp::runOnOperation() DIScopeForLLVMFuncOp.cpp:0:0
#10 0x000055951b59e156 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203156)
#11 0x000055951b59eac0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203ac0)
#12 0x000055951b5a1102 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4206102)
#13 0x000055951b599931 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#14 0x000055951b59958b llvm::LogicalResult llvm::function_ref<llvm::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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#15 0x000055951b645f25 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x42aaf25)
#16 0x000055951b5949b5 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f99b5)
#17 0x000055951b594c5f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9c5f)
#18 0x000055951b594f8e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9f8e)
#19 0x0000559518457f07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bcf07)
#20 0x00007effd09a6083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#21 0x0000559518457a8e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bca8e)
Megan0704-1 commented 1 week ago

Adding the --convert-func-to-llvm flag before using --ensure-debug-info-scope-on-llvm-funcseems to solve the problem. This ensures that function operations are first lowered to LLVM, which then allows the debug info subprogram attributes to be correctly materialized.

axeabc commented 1 week ago

Adding the --convert-func-to-llvm flag before using --ensure-debug-info-scope-on-llvm-funcseems to solve the problem. This ensures that function operations are first lowered to LLVM, which then allows the debug info subprogram attributes to be correctly materialized.

So, --ensure-debug-info-scope-on-llvm-func option can't be used alone? Should it be accompanied by some error handling instead of just throwing crash?