llvm / llvm/llvm-project

[Flang][OpenMP] Compilation error when a type with deferred length type parameter is specified in declare_reduction directive

Open
#177,500 1 comment 0 reactions 0 assignees View on GitHub
flang:frontend flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```
Version of flang : 23.0.0(eb773961aac45593ce126ed258d82c3c3abbaa93)/AArch64
```

In the attached program (`masa_udr_id_com_init_007_21.f90`), when a type with `deferred length type parameter (character(len=:))` is specified in `declare_reduction directive`, a compilation-time error occurs.
After checking `OpenMP 6.0 : 7.6.14 declare_reduction Directive`, the program appears to contain no particular errors.

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

masa_udr_id_com_init_007_21.f90:
```fortran
program main
character(len=:),allocatable::k1
!$omp declare reduction (a:character(len=:):omp_out=max(omp_in, omp_out)) &
!$omp initializer(omp_priv='0')
!$omp parallel sections reduction(a:k1)
k1=max(k1,'2')
!$omp end parallel sections
print *,'pass'
end
```

```
$ flang -fopenmp masa_udr_id_com_init_007_21.f90
error: Semantic errors in masa_udr_id_com_init_007_21.f90
error: 'omp_in' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
error: 'omp_out' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
error: 'omp_orig' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
error: 'omp_priv' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
$
```

```
$ gfortran -fopenmp masa_udr_id_com_init_007_21.f90
masa_udr_id_com_init_007_21.f90:5:39:

5 | !$omp parallel sections reduction(a:k1)
| 1
internal compiler error: in fold_binary_loc, at fold-const.cc:11259
0xafb5b7 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
../.././gcc/fold-const.cc:11259
0xafb62b fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*)
../.././gcc/fold-const.cc:14211
0x92021b alloc_scalar_allocatable_for_assignment
../.././gcc/fortran/trans-expr.cc:11752
0x92021b gfc_trans_assignment_1
../.././gcc/fortran/trans-expr.cc:12594
0x942eaf gfc_trans_omp_array_reduction_or_udr
../.././gcc/fortran/trans-openmp.cc:2266
0x943763 gfc_trans_omp_reduction_list
../.././gcc/fortran/trans-openmp.cc:2388
0x94ab27 gfc_trans_omp_clauses
../.././gcc/fortran/trans-openmp.cc:2726
0x9510bb gfc_trans_omp_parallel_sections
../.././gcc/fortran/trans-openmp.cc:7333
0x8d4447 trans_code
../.././gcc/fortran/trans.cc:2660
0x903ef7 gfc_generate_function_code(gfc_namespace*)
../.././gcc/fortran/trans-decl.cc:7880
0x879cef translate_all_program_units
../.././gcc/fortran/parse.cc:7099
0x879cef gfc_parse_file()
../.././gcc/fortran/parse.cc:7413
0x8d172b gfc_be_parse_file
../.././gcc/fortran/f95-lang.cc:241
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See for instructions.
$
```

```
$ ifx -qopenmp masa_udr_id_com_init_007_21.f90
#0 0x000000000312d792
#1 0x0000000003191e57
#2 0x0000000003191f80
#3 0x000014f386c426f0
#4 0x000000000240baa0
#5 0x000000000240a703
#6 0x000000000240a51b
#7 0x00000000022a54f7
#8 0x00000000022a774f
#9 0x00000000021c12e4
#10 0x00000000021c101c
#11 0x00000000022a919a
#12 0x00000000022a9d54
#13 0x00000000022a93ad
#14 0x00000000021bbf71
#15 0x00000000021bbe4d
#16 0x00000000021b7163
#17 0x00000000021b6eed
#18 0x00000000021bd791
#19 0x00000000021bcd8d
#20 0x00000000027ee7fa
#21 0x00000000027ed32a
#22 0x00000000027ecfad
#23 0x00000000027ee7fa
#24 0x00000000030ce29b
#25 0x00000000030cc544
#26 0x000000000307863e
#27 0x000000000324df17
#28 0x000014f386c2d590
#29 0x000014f386c2d640 __libc_start_main + 128
#30 0x0000000002eb06ea

masa_udr_id_com_init_007_21.f90: error #5633: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report. Note: File and line
given may not be explicit cause of this error.
compilation aborted for masa_udr_id_com_init_007_21.f90 (code 3)
$
```

Contributor guide

Open the contributing guide

Research direction

Start with the attached reproducer masa_udr_id_com_init_007_21.f90 and run flang -fopenmp to reproduce the semantic errors for deferred-length character variables in declare_reduction. Trace Flang's handling of the OpenMP declare_reduction directive and add or update a regression test so this valid OpenMP 6.0 case compiles without those errors.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.