Issue 126966
Summary [flang] [OpenMP] compilation failure for a computed GOTO with OpenMP SIMD loop (Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed)
Labels flang
Assignees
Reporter nsdhaman
    Fortran code having a computed `GOTO` statement with `!$OMP SIMD` loop(s) in one or more of the paths fails to compile. 

Reproducer code `test.F`:

```
 PROGRAM MAIN

      INTEGER N,S,E,I
      N=1
      S=1
 E=128

#ifdef ADDGOTOS
      GOTO(100,200,300) N
      GOTO 400
#endif

 100  CONTINUE
!$OMP SIMD
      DO I=S,E
      ENDDO
 GOTO 500

 200  CONTINUE
      GOTO 500
 300  CONTINUE
      GOTO 500
 400  CONTINUE
      GOTO 500
 500  CONTINUE
      RETURN

 END
```

The following compilation fails
`flang -O2 -fopenmp -cpp -DADDGOTOS test.F -o ./a.out  # fails`
with the following error

```
flang: Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::BranchInst; From = llvm::Instruction]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Stack dump:
0. Program arguments: /llvm/Linux_x86_64/llvm-4386/bin/flang -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -cpp -D ADDGOTOS -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -fopenmp -resource-dir /llvm/Linux_x86_64/llvm-4386/lib/clang/21 -mframe-pointer=none -O2 -o /tmp/test-078f2a.o -x f95-cpp-input test.F
 #0 0x000064e912ca030b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x457130b)
 #1 0x000064e912c9db24 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007de285e45320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
 #3 0x00007de285e9eb1c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #4 0x00007de285e9eb1c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #5 0x00007de285e9eb1c pthread_kill ./nptl/pthread_kill.c:89:10
 #6 0x00007de285e4526e raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007de285e288ff abort ./stdlib/abort.c:81:7
 #8 0x00007de285e2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007de285e3b507 (/lib/x86_64-linux-gnu/libc.so.6+0x3b507)
#10 0x000064e914d0cfca allocatePrivateVars(llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, llvm::MutableArrayRef<mlir::BlockArgument>, llvm::MutableArrayRef<mlir::omp::PrivateClauseOp>, llvm::MutableArrayRef<mlir::Value>, llvm::SmallVectorImpl<llvm::Value*>&, llvm::IRBuilderBase::InsertPoint const&, llvm::DenseMap<mlir::Value, mlir::Value, llvm::DenseMapInfo<mlir::Value, void>, llvm::detail::DenseMapPair<mlir::Value, mlir::Value>>*) (.isra.0) OpenMPToLLVMIRTranslation.cpp:0:0
#11 0x000064e914d2c20c convertOmpSimd(mlir::Operation&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#12 0x000064e914d3379a convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#13 0x000064e914d351f6 (anonymous namespace)::OpenMPDialectLLVMIRTranslationInterface::convertOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) const OpenMPToLLVMIRTranslation.cpp:0:0
#14 0x000064e916b1b60e mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x83ec60e)
#15 0x000064e916b2fb2d mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x8400b2d)
#16 0x000064e916b30f1d mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x8401f1d)
#17 0x000064e916b31964 mlir::LLVM::ModuleTranslation::convertFunctions() (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x8402964)
#18 0x000064e916b33579 mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef, bool) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x8404579)
#19 0x000064e912e1c6e5 Fortran::frontend::CodeGenAction::generateLLVMIR() (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x46ed6e5)
#20 0x000064e912e1ff00 Fortran::frontend::CodeGenAction::executeAction() (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x46f0f00)
#21 0x000064e912ce794d Fortran::frontend::FrontendAction::execute() (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x45b894d)
#22 0x000064e912cc68db Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x45978db)
#23 0x000064e912cf055e Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x45c155e)
#24 0x000064e9125bee1d fc1_main(llvm::ArrayRef<char const*>, char const*) (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x3e8fe1d)
#25 0x000064e9125be7c9 main (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x3e8f7c9)
#26 0x00007de285e2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#27 0x00007de285e2a28b call_init ./csu/../csu/libc-start.c:128:20
#28 0x00007de285e2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#29 0x000064e9125bcc2e _start (/llvm/Linux_x86_64/llvm-4386/bin/flang+0x3e8dc2e)
flang-21: error: unable to execute command: Aborted
flang-21: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 21.0.0git (https://github.com/llvm/llvm-project b0d782080529cf5d422847e1f91f29bd7c62f691)
```


Eliminating the `!$OMP SIMD` directive or the computed `GOTO` statements allows for a successful compilation. For example, compiling without `-DADDGOTOS` removes the computed `GOTO` and the reproducer compiles.
 
`flang -O2 -fopenmp -cpp test.F -o ./a.out  # builds successfully`

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to