llvm / llvm/llvm-project

[MLIR] Crash in FuncToLLVM when running a SPIR-V lowering pipeline with llvm-request-c-wrappers

Open
#205,266 1 comment 0 reactions 0 assignees View on GitHub
crash mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I encountered a crash when running a minimized MLIR input through a SPIR-V lowering pipeline. The crash happens during the `convert-func-to-llvm` pass, after `llvm-request-c-wrappers` has been applied.

**Code Example**
```llvm
func.func @test() -> i32 attributes {linkage = "external"} {
%retval = arith.constant 0 : i32
func.return %retval : i32
}
```

**Stack Trace**
```bash
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: mlir-opt input.mlir "-pass-pipeline=builtin.module(spirv-attach-target{ver=v1.0 caps=Addresses,Int64,Kernel},convert-gpu-to-spirv{use-64bit-index=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)),func.func(llvm-request-c-wrappers),convert-scf-to-cf,convert-cf-to-llvm,convert-arith-to-llvm,convert-math-to-llvm,convert-func-to-llvm,gpu-to-llvm{use-bare-pointers-for-kernels=true},gpu-module-to-binary,expand-strided-metadata,lower-affine,finalize-memref-to-llvm,reconcile-unrealized-casts)"
#0 0x00005d8d411e6d32 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /llvm-project/llvm/lib/Support/Unix/Signals.inc:881:22
#1 0x00005d8d411e71f6 PrintStackTraceSignalHandler(void*) /llvm-project/llvm/lib/Support/Unix/Signals.inc:963:1
#2 0x00005d8d411e4568 llvm::sys::RunSignalHandlers() /llvm-project/llvm/lib/Support/Signals.cpp:108:20
#3 0x00005d8d411e65e6 SignalHandler(int, siginfo_t*, void*) /llvm-project/llvm/lib/Support/Unix/Signals.inc:448:14
#4 0x000072ba7d245cb0 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x45cb0)
#5 0x000072ba7d2a648c pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0xa648c)
#6 0x000072ba7d245b7e raise (/usr/lib/x86_64-linux-gnu/libc.so.6+0x45b7e)
#7 0x000072ba7d2288ec abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x288ec)
#8 0x00005d8d411be88d llvm::report_fatal_error(llvm::Twine const&, bool) /llvm-project/llvm/lib/Support/ErrorHandling.cpp:137:9
#9 0x00005d8d4e9532ce mlir::LLVM::LLVMFuncOp::build(mlir::OpBuilder&, mlir::OperationState&, llvm::StringRef, mlir::Type, mlir::LLVM::linkage::Linkage, bool, mlir::LLVM::cconv::CConv, mlir::SymbolRefAttr, llvm::ArrayRef, llvm::ArrayRef, std::optional) /llvm-project/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp:3057:21
#10 0x00005d8d4ea47d1f mlir::LLVM::LLVMFuncOp::create(mlir::OpBuilder&, mlir::Location, llvm::StringRef, mlir::Type, mlir::LLVM::linkage::Linkage, bool, mlir::LLVM::cconv::CConv, mlir::SymbolRefAttr, llvm::ArrayRef, llvm::ArrayRef, std::optional) /llvm-project/build_de045d/tools/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.cpp.inc:35541:8
#11 0x00005d8d4a64e205 wrapForExternalCallers(mlir::OpBuilder&, mlir::Location, mlir::LLVMTypeConverter const&, mlir::FunctionOpInterface, mlir::LLVM::LLVMFuncOp) /llvm-project/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp:124:48
#12 0x00005d8d4a650259 wrapWithCInterface(mlir::FunctionOpInterface, mlir::ConversionPatternRewriter&, mlir::LLVMTypeConverter const&, mlir::LLVM::LLVMFuncOp) /llvm-project/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp:435:1
#13 0x00005d8d4a650789 mlir::convertFuncOpToLLVMFuncOp(mlir::FunctionOpInterface, mlir::ConversionPatternRewriter&, mlir::LLVMTypeConverter const&, mlir::SymbolTableCollection*) /llvm-project/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp:510:10
#14 0x00005d8d4a6508b7 (anonymous namespace)::FuncOpConversion::matchAndRewrite(mlir::func::FuncOp, mlir::func::FuncOpAdaptor, mlir::ConversionPatternRewriter&) const /llvm-project/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp:529:76
#15 0x00005d8d41395066 llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1, mlir::func::FuncOp>(mlir::ConvertOpToLLVMPattern const&, mlir::func::FuncOp, mlir::func::FuncOp::GenericAdaptor>, mlir::ConversionPatternRewriter&) /llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:1069:30
#16 0x00005d8d41394a1c mlir::ConvertOpToLLVMPattern::matchAndRewrite(mlir::func::FuncOp, mlir::func::FuncOpGenericAdaptor>, mlir::ConversionPatternRewriter&) const /llvm-project/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h:276:26
#17 0x00005d8d41394975 mlir::ConvertOpToLLVMPattern::matchAndRewrite(mlir::Operation*, llvm::ArrayRef, mlir::ConversionPatternRewriter&) const /llvm-project/mlir/include/mlir/Conversion/LLVMCommon/Pattern.h:262:27
#18 0x00005d8d4fc2d0cf mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2414:25
#19 0x00005d8d4fcc3c02 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref)::'lambda'()::operator()() const /llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:223:46
#20 0x00005d8d4fcc4588 void llvm::function_ref::callback_fn, llvm::function_ref, llvm::function_ref)::'lambda'()>(long) /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:47:40
#21 0x00005d8d41208732 llvm::function_ref::operator()() const /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:62
#22 0x00005d8d4fcc7643 void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef, mlir::Pattern const&) /llvm-project/mlir/include/mlir/IR/MLIRContext.h:297:3
#23 0x00005d8d4fcc43da mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) /llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:242:5
#24 0x00005d8d4fc2edaf (anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2835:36
#25 0x00005d8d4fc2d894 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2613:16
#26 0x00005d8d4fc307d9 mlir::OperationConverter::convert(mlir::Operation*, bool) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3321:13
#27 0x00005d8d4fc38fc4 llvm::LogicalResult mlir::OperationConverter::legalizeOperations)::'lambda'()>(llvm::ArrayRef, mlir::OperationConverter::applyConversion(llvm::ArrayRef)::'lambda'(), bool) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3420:15
#28 0x00005d8d4fc31376 mlir::OperationConverter::applyConversion(llvm::ArrayRef) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:3467:44
#29 0x00005d8d4fc34b71 applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::'lambda'()::operator()() const /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4211:45
#30 0x00005d8d4fc3d510 void llvm::function_ref::callback_fn, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::'lambda'()>(long) /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:47:40
#31 0x00005d8d41208732 llvm::function_ref::operator()() const /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:62
#32 0x00005d8d4fc53402 void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef) /llvm-project/mlir/include/mlir/IR/MLIRContext.h:297:3
#33 0x00005d8d4fc34cec applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4214:10
#34 0x00005d8d4fc34d91 mlir::applyPartialConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4224:25
#35 0x00005d8d4fc34e1d mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) /llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:4231:32
#36 0x00005d8d4a651bc1 (anonymous namespace)::ConvertFuncToLLVMPass::runOnOperation() /llvm-project/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp:879:15
#37 0x00005d8d4fd73ff3 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda'()::operator()() const /llvm-project/mlir/lib/Pass/Pass.cpp:613:24
#38 0x00005d8d4fd7be96 void llvm::function_ref::callback_fn(long) /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:47:40
#39 0x00005d8d41208732 llvm::function_ref::operator()() const /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:62
#40 0x00005d8d4fd81a2d void mlir::MLIRContext::executeAction(llvm::function_ref, llvm::ArrayRef, mlir::Pass&) /llvm-project/mlir/include/mlir/IR/MLIRContext.h:297:3
#41 0x00005d8d4fd7467b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /llvm-project/mlir/lib/Pass/Pass.cpp:619:23
#42 0x00005d8d4fd74ce8 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /llvm-project/mlir/lib/Pass/Pass.cpp:688:15
#43 0x00005d8d4fd7a869 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /llvm-project/mlir/lib/Pass/Pass.cpp:1128:40
#44 0x00005d8d4fd7a36f mlir::PassManager::run(mlir::Operation*) /llvm-project/mlir/lib/Pass/Pass.cpp:1102:69
#45 0x00005d8d412f0e8c performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:596:13
#46 0x00005d8d412f16d2 processBuffer(llvm::raw_ostream&, std::unique_ptr>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) /llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:686:26
#47 0x00005d8d412f1ce1 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr>, llvm::MemoryBufferRef, llvm::raw_ostream&)::operator()(std::unique_ptr>, llvm::MemoryBufferRef, llvm::raw_ostream&) const /llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:784:25
#48 0x00005d8d412f2ea5 llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:52
#49 0x00005d8d502d9d15 llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::operator()(std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) const /llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
#50 0x00005d8d502d93de mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /llvm-project/mlir/lib/Support/ToolUtilities.cpp:30:30
#51 0x00005d8d412f1fab mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:789:47
#52 0x00005d8d412f22db mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:835:13
#53 0x00005d8d412f2499 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:851:21
#54 0x00005d8d411ba901 main /llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:347:32
#55 0x000072ba7d22a601 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a601)
#56 0x000072ba7d22a718 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2a718)
#57 0x00005d8d411ba435 _start (/mnt/raid/llvm-project/build_de045d/bin/mlir-opt+0x464c435)
Aborted mlir-opt input.mlir "-pass-pipeline=builtin.module(spirv-attach-target{ver=v1.0 caps=Addresses,Int64,Kernel},convert-gpu-to-spirv{use-64bit-index=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)),func.func(llvm-request-c-wrappers),convert-scf-to-cf,convert-cf-to-llvm,convert-arith-to-llvm,convert-math-to-llvm,convert-func-to-llvm,gpu-to-llvm{use-bare-pointers-for-kernels=true},gpu-module-to-binary,expand-strided-metadata,lower-affine,finalize-memref-to-llvm,reconcile-unrealized-casts)"
```

**Used Command**
```bash
mlir-opt input.mlir "-pass-pipeline=builtin.module(spirv-attach-target{ver=v1.0 caps=Addresses,Int64,Kernel},convert-gpu-to-spirv{use-64bit-index=true},gpu.module(spirv.module(spirv-lower-abi-attrs,spirv-update-vce)),func.func(llvm-request-c-wrappers),convert-scf-to-cf,convert-cf-to-llvm,convert-arith-to-llvm,convert-math-to-llvm,convert-func-to-llvm,gpu-to-llvm{use-bare-pointers-for-kernels=true},gpu-module-to-binary,expand-strided-metadata,lower-affine,finalize-memref-to-llvm,reconcile-unrealized-casts)"
```

Version: de045d579791d978cce109f9348d20560e112d74

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the crash with input.mlir and the supplied mlir-opt pass pipeline, then trace wrapForExternalCallers and convertFuncOpToLLVMFuncOp in mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp. Check the LLVMFuncOp construction in mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp; done means the minimized pipeline no longer aborts and the regression is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.