[Flang][OpenMP] Compilation abnormally terminates of incomplete DECLARE REDUCTION directive
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```
Version of flang : 23.0.0(36041192cf6c9042615c8d2364cacc698ef89865)/AArch64
```
The attached program (`err_sngg002e_3.f90`) is incorrect.
`gen` is specified as `reduction-identifier` and `combiner` in `DECLARE REDUCTION directive`. However, it does not define how it behaves within the program. In this case, the compilation error (Internal error) occurs.
Error checking should be performed for this program.
The following are the test program, Flang, Gfortran and ifx compilation/execution results.
err_sngg002e_3.f90:
```fortran
program main
implicit none
type x
integer::xxx
end type x
!$omp declare reduction(gen:x:omp_out=gen(omp_in,omp_out))
type(x) ::t1
!$omp parallel reduction(gen:t1)
!$omp endparallel
end program main
```
```
$ flang -fopenmp err_sngg002e_3.f90
./err_sngg002e_3.f90:7:39: error: Internal error: Expression analysis failed on: Expr -> FunctionReference -> Call
| ProcedureDesignator -> Name = 'gen'
| ActualArgSpec
| | ActualArg -> Expr -> Designator -> DataRef -> Name = 'omp_in'
| ActualArgSpec
| | ActualArg -> Expr -> Designator -> DataRef -> Name = 'omp_out'
!$omp declare reduction(gen:x:omp_out=gen(omp_in,omp_out))
^^^^^^^^^^^^^^^^^^^
$
```
```
$ gfortran -fopenmp err_sngg002e_3.f90
err_sngg002e_3.f90:7:23:
7 | !$omp declare reduction(gen:x:omp_out=gen(omp_in,omp_out))
| 1
Error: Missing INITIALIZER clause for !$OMP DECLARE REDUCTION of derived type without default initializer at (1)
err_sngg002e_3.f90:7:38:
7 | !$omp declare reduction(gen:x:omp_out=gen(omp_in,omp_out))
| 1
Error: Function ‘gen’ at (1) has no IMPLICIT type
err_sngg002e_3.f90:7:38:
7 | !$omp declare reduction(gen:x:omp_out=gen(omp_in,omp_out))
| 1
Error: Implicitly declared function gen used in !$OMP DECLARE REDUCTION at (1)
$
```
```
$ ifx -qopenmp err_sngg002e_3.f90
err_sngg002e_3.f90(7): error #6404: This name does not have a type, and must have an explicit type. [GEN]
!$omp declare reduction(gen:x:omp_out=gen(omp_in,omp_out))
--------------------------------------^
compilation aborted for err_sngg002e_3.f90 (code 1)
$
```
Contributor guide
Research direction
Start by reproducing the failure with err_sngg002e_3.f90 using Flang and -fopenmp, then compare the diagnostic with the gfortran and ifx results included in the issue. Trace Flang's handling of the DECLARE REDUCTION directive and its expression analysis; done means the invalid, incomplete declaration produces a normal semantic error instead of an internal error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100