[Mlir-commits] [flang] [mlir] [Flang] Add new ConvertComplexPow pass for Flang (PR #158642)

Leandro Lupori llvmlistbot at llvm.org
Mon Sep 22 10:15:47 PDT 2025


luporl wrote:

```
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: ../build_flang/bin/fir-opt --convert-complex-pow /Users/leandro.lupori/home/git/flang/llvm-project/flang/test/Transforms/convert-complex-pow.fir
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  fir-opt                  0x000000010348bc78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  fir-opt                  0x0000000103489a04 llvm::sys::RunSignalHandlers() + 172
2  fir-opt                  0x000000010348c770 SignalHandler(int, __siginfo*, void*) + 360
3  libsystem_platform.dylib 0x000000018db5d6a4 _sigtramp + 56
4  fir-opt                  0x00000001006d0040 mlir::TypeID::operator!=(mlir::TypeID const&) const + 32
5  fir-opt                  0x00000001006d0014 mlir::OperationName::Impl::isRegistered() const + 48
6  fir-opt                  0x00000001006cff2c mlir::OperationName::isRegistered() const + 28
7  fir-opt                  0x00000001006cfec4 mlir::OperationName::getRegisteredInfo() const + 28
8  fir-opt                  0x00000001006cfd38 mlir::Operation::getRegisteredInfo() + 56
9  fir-opt                  0x0000000100ca6364 mlir::Op<mlir::complex::PowOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::ComplexType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::NOperands<2u>::Impl, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait, mlir::OpTrait::SameOperandsAndResultType, mlir::OpTrait::Elementwise, mlir::arith::ArithFastMathInterface::Trait, mlir::InferTypeOpInterface::Trait>::classof(mlir::Operation*) + 52
10 fir-opt                  0x0000000100ca62d0 llvm::CastInfo<mlir::complex::PowOp, mlir::Operation*, void>::isPossible(mlir::Operation*) + 24
11 fir-opt                  0x0000000100ca6284 llvm::DefaultDoCastIfPossible<mlir::complex::PowOp, mlir::Operation*, llvm::CastInfo<mlir::complex::PowOp, mlir::Operation*, void>>::doCastIfPossible(mlir::Operation*) + 24
12 fir-opt                  0x0000000100ca5668 decltype(auto) llvm::dyn_cast<mlir::complex::PowOp, mlir::Operation>(mlir::Operation*) + 112
13 fir-opt                  0x0000000100ca4dac (anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0::operator()(mlir::Operation*) const + 1424
14 fir-opt                  0x0000000100ca4810 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0>(long, mlir::Operation*) + 32
15 fir-opt                  0x0000000100b201b8 llvm::function_ref<void (mlir::Operation*)>::operator()(mlir::Operation*) const + 40
16 fir-opt                  0x0000000100b20118 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) + 464
17 fir-opt                  0x0000000100b200c8 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) + 384
18 fir-opt                  0x0000000100b200c8 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) + 384
19 fir-opt                  0x0000000100ca476c std::__1::enable_if<llvm::is_one_of<mlir::Operation*, mlir::Operation*, mlir::Region*, mlir::Block*>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0, mlir::Operation*, void>(mlir::Operation*, (anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0&&) + 68
20 fir-opt                  0x0000000100ca471c std::__1::enable_if<llvm::function_traits<__decay((anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0)>::num_args == 1, void>::type mlir::Operation::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0, void>((anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0&&) + 32
21 fir-opt                  0x0000000100ca46f0 std::__1::enable_if<llvm::function_traits<__decay((anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0)>::num_args == 1, void>::type mlir::OpState::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0, void>((anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0&&) + 36
22 fir-opt                  0x0000000100ca448c (anonymous namespace)::ConvertComplexPowPass::runOnOperation() + 128
23 fir-opt                  0x00000001026fc67c mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 1336
24 fir-opt                  0x00000001026fcff8 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 608
25 fir-opt                  0x00000001027033c4 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) + 460
26 fir-opt                  0x0000000102702b40 mlir::PassManager::run(mlir::Operation*) + 5724
27 fir-opt                  0x00000001027989c0 performActions(llvm::raw_ostream&, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) + 1524
28 fir-opt                  0x0000000102798338 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) + 804
29 fir-opt                  0x0000000102777a24 mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) + 596
30 fir-opt                  0x000000010278eb9c mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) + 432
31 fir-opt                  0x000000010278ef10 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) + 384
32 fir-opt                  0x000000010278f13c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) + 144
33 fir-opt                  0x00000001005fddbc main + 148
34 dyld                     0x000000018d782b98 start + 6076
Segmentation fault: 11     ../build_flang/bin/fir-opt --convert-complex-pow /Users/leandro.lupori/home/git/flang/llvm-project/flang/test/Transforms/convert-complex-pow.fir
```

The `op` argument In `ConvertComplexPowPass::runOnOperation()` doesn't look right and ends up causing a null pointer dereference:

```
(lldb) f
frame #10: 0x00000001006a8dac fir-opt`(anonymous namespace)::ConvertComplexPowPass::runOnOperation()::$_0::operator()(this=0x000000016fdfd6b0, op=0x0000600003e2c010) const at ConvertComplexPow.cpp:88:22
   85  	      powIop.erase();
   86  	    }
   87
-> 88  	    if (auto powOp = dyn_cast<complex::PowOp>(op)) {
   89  	      builder.setInsertionPoint(powOp);
   90  	      Location loc = powOp.getLoc();
   91  	      auto complexTy = cast<ComplexType>(powOp.getType());
(lldb) p *op
(mlir::Operation) {
  llvm::ilist_node_with_parent<mlir::Operation, mlir::Block> = {
    llvm::ilist_node<mlir::Operation> = {
      llvm::ilist_node_impl<llvm::ilist_detail::node_options<mlir::Operation, true, false, void, false, void> > = {
        llvm::ilist_detail::node_options<mlir::Operation, true, false, void, false, void>::node_base_type = {
          llvm::ilist_detail::node_base_prevnext<llvm::ilist_node_base<true, void>, true> = {
            PrevAndSentinel ={...}
            Next = nullptr{...}
          }
        }
      }
    }
  }
  block = nullptr
  location = {
    impl = {
      mlir::Attribute = {
        impl = nullptr
      }
    }
  }
  orderIndex = 0
  numResults = 0
  numSuccs = 0
  numRegions = 0
  hasOperandStorage = false
  propertiesStorageSize = '\0'
  name = {
    impl = nullptr
  }
  attrs = {
    mlir::Attribute::AttrBase<DictionaryAttr, ::mlir::Attribute, detail::DictionaryAttrStorage> = {
      mlir::Attribute = {
        impl = nullptr
      }
    }
  }
}
```

https://github.com/llvm/llvm-project/pull/158642


More information about the Mlir-commits mailing list