Issue 204300
Summary [Flang][OpenMP] Runtime error for a firstprivate structure with an array component of another derived type containing allocatable components
Labels flang:openmp
Assignees
Reporter yus3710-fj
    ## Summary

Execution terminates abnormally when a firstprivate structure has a component that is an array of another derived type with allocatable components.

* 7.5.4 `firstprivate` Clause (OpenMP 6.0)
> If an original list item does not have the POINTER attribute, initialization of the new list items occurs as if by intrinsic assignment unless the original list item has a compatible type-bound defined assignment, in which case initialization of the new list items occurs as if by the defined assignment.

### Reproducer

* test.f90

```fortran
subroutine s1
  IMPLICIT NONE
 TYPE :: x
    integer, ALLOCATABLE :: alloc
  END TYPE
  TYPE y
 TYPE(x) :: v(2)
  END TYPE
  TYPE(y)::g

 !allocate(g%v(1)%alloc,source=1)
  !allocate(g%v(2)%alloc,source=2)

 print *,'Start'
!$omp parallel firstprivate(g)
  print *,'In region'
!$omp end parallel
end

!$ use omp_lib, only: omp_set_num_threads
!$ call omp_set_num_threads(2)
call s1
print *,'pass'
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git e84e480bb5a53c794f303683df6460ddb44bb7ac)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out 
 Start

fatal Fortran runtime error(/path/to/llvm-project/flang-rt/lib/runtime/allocator-registry.cpp:48): Internal error: RUNTIME_CHECK(f != nullptr) failed at /path/to/llvm-project/flang-rt/lib/runtime/allocator-registry.cpp(48)
free(): invalid size
Aborted (core dumped)
```

Note that this issue occurs whether or not the allocatable component is allocated.

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Changing the component from an array to a scalar (i.e., `v(2)` to `v`).
* Changing the explicit-shape array to a deferred-shape array (i.e., `v(2)` to `v(:)` with ALLOCATABLE).

## Other Compilers

* GFortran
  ```console
 $ gfortran --version
  GNU Fortran (GCC) 15.2.0
  Copyright (C) 2025 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
  $ gfortran test.f90 -fopenmp && ./a.out
   Start
   In region
   In region
   pass
  ```

* Intel Fortran
  ```console
  $ ifx --version
  ifx (IFX) 2025.3.2 20260112
 Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
  
  $ ifx -O0 test.f90 -qopenmp && ./a.out
   Start
   In region
   In region
 pass
  ```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to