Issue 124489
Summary [Flang] Compilation abnormally terminates when a program uses equivalence, namelist, and read statement
Labels flang
Assignees
Reporter ohno-fj
    ```
Version of flang : 20.0.0(69d3ba3db922fca8cfc47b5f115b6bea6a737aab)/AArch64
```

When a program uses `equivalence`, `namelist`, and `read` statement, a compilation terminates abnormally.  
Compilation ends normally in the following cases:
- remove the `equivalue` statement, or
- remove the `read` statement, or
- Change `namelist-group-name (kono1)` specified in the `read` statement to a `array (r1k001)`, or
- Change the number of elements in `array (r1k001)` to 1

The following are the test program, Flang, Gfortran and ifx compilation/execution result.

ioct148_2.f:
```fortran
 program main
      real r9dim2,rdim
      equivalence (r9dim2,rdim)
 real*8 r1k001(5)
      namelist /kono1/r1k001
      read (5,kono1)
 print *,'end'
      end
```

```
$ flang ioct148_2.f
flang: /work/groups/ssoft/compiler/llvm/src/llvm-main/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = mlir::omp::OutlineableOpenMPOpInterface; From = mlir::Operation]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature
 +neon -resource-dir /work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/ioct148_2-0a2fdd.o -x f95-cpp-input ioct148_2.f
 #0 0x0000400036aa25a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x5a025a8)
 #1 0x0000400036aa0630 llvm::sys::RunSignalHandlers() (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x5a00630)
 #2 0x0000400036aa0788 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000400026bc07a0 (linux-vdso.so.1+0x7a0)
 #4 0x000040003b936274 raise (/lib64/libc.so.6+0x36274)
 #5 0x000040003b920a2c abort (/lib64/libc.so.6+0x20a2c)
 #6 0x000040003b92fba0 __assert_fail_base (/lib64/libc.so.6+0x2fba0)
 #7 0x000040003b92fc18 __assert_perror_fail (/lib64/libc.so.6+0x2fc18)
 #8 0x00000000057f4864 fir::ConvertFIRToLLVMPattern::getBlockForAllocaInsert(mlir::Operation*, mlir::Region*) const (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x57f4864)
 #9 0x00000000057f476c fir::ConvertFIRToLLVMPattern::getBlockForAllocaInsert(mlir::Operation*, mlir::Region*) const (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x57f476c)
#10 0x00000000057f476c fir::ConvertFIRToLLVMPattern::getBlockForAllocaInsert(mlir::Operation*, mlir::Region*) const (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x57f476c)
#11 0x00000000057e4290 (anonymous namespace)::AllocaOpConversion::matchAndRewrite(fir::AllocaOp, fir::AllocaOpAdaptor, mlir::ConversionPatternRewriter&) const CodeGen.cpp:0:0
#12 0x00000000057e2c04 fir::FIROpConversion<fir::AllocaOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::ValueRange>, mlir::ConversionPatternRewriter&) const CodeGen.cpp:0:0
#13 0x0000400030e2fce0 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x525fce0)
#14 0x0000400030b9a64c mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/work/groups/ssoft/compiler/llvm/aarch64/main-la
test/lib/libMLIR.so.20.0git+0x4fca64c)
#15 0x0000400030e32668 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#16 0x0000400030e32bb4 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x5262bb4)
#17 0x0000400030e34b4c mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x5264b4c)
#18 0x0000400030e3691c mlir::applyFullConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x526691c)
#19 0x00000000057ca31c (anonymous namespace)::FIRToLLVMLowering::runOnOperation() CodeGen.cpp:0:0
#20 0x0000400030b658b8 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x4f958b8)
#21 0x0000400030b65b58 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x4f95b58)
#22 0x0000400030b66460 mlir::PassManager::run(mlir::Operation*) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libMLIR.so.20.0git+0x4f96460)
#23 0x0000000004d27d5c Fortran::frontend::CodeGenAction::generateLLVMIR() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4d27d5c)
#24 0x0000000004d2a590 Fortran::frontend::CodeGenAction::executeAction() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4d2a590)
#25 0x0000000004c395ac Fortran::frontend::FrontendAction::execute() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4c395ac)
#26 0x0000000004c2bca4 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4c2bca4)
#27 0x0000000004c4085c Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4c4085c)
#28 0x0000000004c24518 fc1_main(llvm::ArrayRef<char const*>, char const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4c24518)
#29 0x0000000004c23f70 main (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4c23f70)
#30 0x000040003b924384 __libc_start_main (/lib64/libc.so.6+0x24384)
#31 0x0000000004c2243c _start (/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang+0x4c2243c)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (https://github.com/llvm/llvm-project.git 69d3ba3db922fca8cfc47b5f115b6bea6a737aab)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin
Build config: +assertions
flang-20: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /tmp/ioct148_2-2a4c15
flang-20: note: diagnostic msg: /tmp/ioct148_2-2a4c15.sh
flang-20: note: diagnostic msg:

********************
$
```

```
$ cat /tmp/ioct148_2-2a4c15
#line "./ioct148_2.f" 1
      program main
 real r9dim2,rdim
      equivalence (r9dim2,rdim)
      real*8 r1k001(5)
 namelist /kono1/r1k001
      read (5,kono1)
      print *,'end'
 end
$
```

```
$ cat /tmp/ioct148_2-2a4c15.sh
# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git 69d3ba3db922fca8cfc47b5f115b6bea6a737aab)
# Driver args: "ioct148_2.f"
# Original command: "/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-featur
e" "+fp-armv8" "-target-feature" "+neon" "-resource-dir" "/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/lib/clang/20" "-mframe-pointer=non-leaf" "-o" "/tmp/ioct148_2-0a2fdd.o" "-x" "f95-cpp-input" "ioct148_2.f"
 "/work/groups/ssoft/compiler/llvm/aarch64/main-20250120-69d3ba3db922/bin/flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-feature" "+fp-armv8" "-tar
get-feature" "+neon" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "ioct148_2-2a4c15"
$
```

```
$ gfortran ioct148_2.f
$
```

```
$ ifx ioct148_2.f
$
```


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to