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

[mlir][bug] Printing acc.routine segfaults when bindStrName is missing

Open Kiritobl opened this issue 2 months ago • 1 comments

Version

git commit hash: 2a96d5737524012839e786699a0b327f22d1cfee

Bug Description

An acc.routine has bindStrNameDeviceType but no matching bindStrName array. Running mlir-opt without any pass segfaults while printing the operation. Adding bindStrName = ["name"] makes the same no-pass invocation finish.

Crash Chain & Root Cause

Location: mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp (RoutineOp::getBindNameValue).

Crash flow:

`acc.routine` has `bindStrNameDeviceType`
  → `acc::RoutineOp::print()`
  → `RoutineOp::getBindNameValue()`
  → access absent `getBindStrName()` array
  → `ArrayAttr::getValue()`
  → SIGSEGV

The printer sees a device-type entry and indexes the corresponding name array without first confirming that the name array exists. This malformed attribute pair should be rejected or printed without a null-attribute dereference.

Steps to Reproduce

Run the following command with the provided reproducer MLIR:

mlir-opt reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module { "acc.routine"() <{sym_name="r", func_name=@f, bindStrNameDeviceType=[#acc.device_type<none>]}> : () -> () }

Stack Dump

Stack dump:
0.  Program arguments: mlir-opt reproducer.mlir -o <output>
 #0 0x0000556ae6ae6a1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x202aa1a)
 #1 0x0000556ae6ae37ff llvm::sys::RunSignalHandlers() (mlir-opt+0x20277ff)
 #2 0x0000556ae6ae780b SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007fcace569520 (libc.so.6+0x42520)
 #4 0x0000556aeeaf0273 mlir::ArrayAttr::getValue() const (mlir-opt+0xa034273)
 #5 0x0000556ae8363e6e mlir::acc::RoutineOp::print(mlir::OpAsmPrinter&) (mlir-opt+0x38a7e6e)
 #6 0x0000556ae8407e3e mlir::Op<mlir::acc::RoutineOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::ZeroResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::IsIsolatedFromAbove, mlir::OpTrait::SymbolName, mlir::OpTrait::SymbolVisibility, mlir::SymbolOpInterface::Trait>::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef)::operator()(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) const (mlir-opt+0x394be3e)
 #7 0x0000556aeead50dd (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
 #8 0x0000556aeead2f30 (anonymous namespace)::DummyAliasOperationPrinter::printRegion(mlir::Region&, bool, bool, bool) AsmPrinter.cpp:0:0
 #9 0x0000556aeeb22590 mlir::ModuleOp::print(mlir::OpAsmPrinter&) (mlir-opt+0xa066590)
#10 0x0000556aeeb25f4e mlir::Op<mlir::ModuleOp, mlir::OpTrait::OneRegion, mlir::OpTrait::ZeroResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::NoRegionArguments, mlir::OpTrait::NoTerminator, mlir::OpTrait::SingleBlock, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::AffineScope, mlir::OpTrait::IsIsolatedFromAbove, mlir::OpTrait::SymbolTable, mlir::OpTrait::SymbolName, mlir::OpTrait::SymbolVisibility, mlir::SymbolOpInterface::Trait, mlir::OpAsmOpInterface::Trait, mlir::RegionKindInterface::Trait, mlir::OpTrait::HasOnlyGraphRegion>::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef)::operator()(mlir::Operation*, mlir::OpAsmPrinter&, llvm::StringRef) const (mlir-opt+0xa069f4e)
#11 0x0000556aeeacd3d2 mlir::detail::AsmStateImpl::initializeAliases(mlir::Operation*) (mlir-opt+0xa0113d2)
#12 0x0000556aeeacc04d mlir::Operation::print(llvm::raw_ostream&, mlir::AsmState&) (mlir-opt+0xa01004d)
#13 0x0000556ae6b97028 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#14 0x0000556ae6b95d2c llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, 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&)::$_3>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#15 0x0000556aeebe7df7 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::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa12bdf7)
#16 0x0000556ae6b8cd72 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (mlir-opt+0x20d0d72)
#17 0x0000556ae6b8d171 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x20d1171)
#18 0x0000556ae6b8d3ad mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x20d13ad)
#19 0x0000556ae6accaa2 main (mlir-opt+0x2010aa2)
#20 0x00007fcace550d90 __libc_start_call_main libc_start_call_main.h:58:16
#21 0x00007fcace550e40 call_init libc-start.c:128:20
#22 0x00007fcace550e40 __libc_start_main libc-start.c:379:5
#23 0x0000556ae6acc5d5 _start (mlir-opt+0x20105d5)

Kiritobl avatar Oct 04 '26 07:10 Kiritobl

@llvm/issue-subscribers-mlir

Author: Peixiang Qin (Kiritobl)

#### Version

git commit hash: 2a96d5737524012839e786699a0b327f22d1cfee

Bug Description

An acc.routine has bindStrNameDeviceType but no matching bindStrName array. Running mlir-opt without any pass segfaults while printing the operation. Adding bindStrName = ["name"] makes the same no-pass invocation finish.

Crash Chain & Root Cause

Location: mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp (RoutineOp::getBindNameValue).

Crash flow:

`acc.routine` has `bindStrNameDeviceType`
  → `acc::RoutineOp::print()`
  → `RoutineOp::getBindNameValue()`
  → access absent `getBindStrName()` array
  → `ArrayAttr::getValue()`
  → SIGSEGV

The printer sees a device-type entry and indexes the corresponding name array without first confirming that the name array exists. This malformed attribute pair should be rejected or printed without a null-attribute dereference.

Steps to Reproduce

Run the following command with the provided reproducer MLIR:

mlir-opt reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module { "acc.routine"() &lt;{sym_name="r", func_name=@<!-- -->f, bindStrNameDeviceType=[#acc.device_type&lt;none&gt;]}&gt; : () -&gt; () }

Stack Dump

Stack dump:
0.  Program arguments: mlir-opt reproducer.mlir -o &lt;output&gt;
 #<!-- -->0 0x0000556ae6ae6a1a llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (mlir-opt+0x202aa1a)
 #<!-- -->1 0x0000556ae6ae37ff llvm::sys::RunSignalHandlers() (mlir-opt+0x20277ff)
 #<!-- -->2 0x0000556ae6ae780b SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #<!-- -->3 0x00007fcace569520 (libc.so.6+0x42520)
 #<!-- -->4 0x0000556aeeaf0273 mlir::ArrayAttr::getValue() const (mlir-opt+0xa034273)
 #<!-- -->5 0x0000556ae8363e6e mlir::acc::RoutineOp::print(mlir::OpAsmPrinter&amp;) (mlir-opt+0x38a7e6e)
 #<!-- -->6 0x0000556ae8407e3e mlir::Op&lt;mlir::acc::RoutineOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::ZeroResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::IsIsolatedFromAbove, mlir::OpTrait::SymbolName, mlir::OpTrait::SymbolVisibility, mlir::SymbolOpInterface::Trait&gt;::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&amp;, llvm::StringRef)::operator()(mlir::Operation*, mlir::OpAsmPrinter&amp;, llvm::StringRef) const (mlir-opt+0x394be3e)
 #<!-- -->7 0x0000556aeead50dd (anonymous namespace)::DummyAliasOperationPrinter::print(mlir::Block*, bool, bool) AsmPrinter.cpp:0:0
 #<!-- -->8 0x0000556aeead2f30 (anonymous namespace)::DummyAliasOperationPrinter::printRegion(mlir::Region&amp;, bool, bool, bool) AsmPrinter.cpp:0:0
 #<!-- -->9 0x0000556aeeb22590 mlir::ModuleOp::print(mlir::OpAsmPrinter&amp;) (mlir-opt+0xa066590)
#<!-- -->10 0x0000556aeeb25f4e mlir::Op&lt;mlir::ModuleOp, mlir::OpTrait::OneRegion, mlir::OpTrait::ZeroResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::ZeroOperands, mlir::OpTrait::NoRegionArguments, mlir::OpTrait::NoTerminator, mlir::OpTrait::SingleBlock, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::AffineScope, mlir::OpTrait::IsIsolatedFromAbove, mlir::OpTrait::SymbolTable, mlir::OpTrait::SymbolName, mlir::OpTrait::SymbolVisibility, mlir::SymbolOpInterface::Trait, mlir::OpAsmOpInterface::Trait, mlir::RegionKindInterface::Trait, mlir::OpTrait::HasOnlyGraphRegion&gt;::getPrintAssemblyFn()::'lambda'(mlir::Operation*, mlir::OpAsmPrinter&amp;, llvm::StringRef)::operator()(mlir::Operation*, mlir::OpAsmPrinter&amp;, llvm::StringRef) const (mlir-opt+0xa069f4e)
#<!-- -->11 0x0000556aeeacd3d2 mlir::detail::AsmStateImpl::initializeAliases(mlir::Operation*) (mlir-opt+0xa0113d2)
#<!-- -->12 0x0000556aeeacc04d mlir::Operation::print(llvm::raw_ostream&amp;, mlir::AsmState&amp;) (mlir-opt+0xa01004d)
#<!-- -->13 0x0000556ae6b97028 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->14 0x0000556ae6b95d2c llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::$_3&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->15 0x0000556aeebe7df7 mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa12bdf7)
#<!-- -->16 0x0000556ae6b8cd72 mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (mlir-opt+0x20d0d72)
#<!-- -->17 0x0000556ae6b8d171 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x20d1171)
#<!-- -->18 0x0000556ae6b8d3ad mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x20d13ad)
#<!-- -->19 0x0000556ae6accaa2 main (mlir-opt+0x2010aa2)
#<!-- -->20 0x00007fcace550d90 __libc_start_call_main libc_start_call_main.h:58:16
#<!-- -->21 0x00007fcace550e40 call_init libc-start.c:128:20
#<!-- -->22 0x00007fcace550e40 __libc_start_main libc-start.c:379:5
#<!-- -->23 0x0000556ae6acc5d5 _start (mlir-opt+0x20105d5)