The stop statement is allowed in OpenMP/OpenACC block region.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Comment Actions
@kiranchandramohan left one comment here (https://reviews.llvm.org/D88655#2470610) more than one year ago, but there is no further update. Take up this.
I checked OpenACC 3.0, and there is no explicit description for the stop statement in a region. Then I checked gfortran, and this is OK for gfortran.
$ cat test.f90 program m integer :: i, N=10, a(10) !$acc serial do i = 1, N a(i) = 3.14 if(i == N-1) THEN stop 999 ! no error end if end do !$acc end serial end $ gfortran test.f90 -fopenacc ! no error
Comment Actions
For semantic analysis, this patch is OK. Branching out of a OpenMP region has wrong semantics such as the slave thread GOTO the non-parallel region. For STOP statement, it aborts the program, which is expected.
For lowering, it hasn't handle this case. I will fix it later.
program m use omp_lib !$omp parallel num_threads(4) stop omp_get_thread_num() !$omp end parallel end
$ bbc -emit-fir -fopenmp test.f90 && cat test.mlir func.func @_QQmain() { %c4_i32 = arith.constant 4 : i32 omp.parallel num_threads(%c4_i32 : i32) { %0 = fir.call @omp_get_thread_num() : () -> i32 %false = arith.constant false %false_0 = arith.constant false %1 = fir.call @_FortranAStopStatement(%0, %false, %false_0) : (i32, i1, i1) -> none fir.unreachable } return }
Change it by-hand:
func.func @_QQmain() { %c4_i32 = arith.constant 4 : i32 omp.parallel num_threads(%c4_i32 : i32) { %0 = fir.call @omp_get_thread_num() : () -> i32 %false = arith.constant false %false_0 = arith.constant false %1 = fir.call @_FortranAStopStatement(%0, %false, %false_0) : (i32, i1, i1) -> none omp.terminator } return }
tco test.mlir -o test.ll $ clang++ -L/path-to-lib -lFortran_main -lFortranRuntime -lFortranDecimal -lomp test.ll $ ./a.out Fortran STOP: code 1 Fortran STOP: code 3 IEEE arithmetic exceptions signaled: INEXACT IEEE arithmetic exceptions signaled: INEXACT Fortran STOP: code 2 IEEE arithmetic exceptions signaled: INEXACT Fortran STOP IEEE arithmetic exceptions signaled:
$ gfortran test.f90 -fopenmp && ./a.out STOP 0 STOP 3 STOP 2
I will fix the lowering later.