llvm / llvm/llvm-project

[Flang][OpenMP] Runtime error for a firstprivate structure with an array component of another derived type containing allocatable components

Open
#204,300 0 comments 0 reactions 0 assignees View on GitHub
flang:openmp
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## 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
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling and running the test.f90 reproducer with flang -fopenmp, then inspect flang-rt/lib/runtime/allocator-registry.cpp at line 48. The fix is complete when the firstprivate derived-type case runs without the allocator-registry error, invalid free, or abort and prints both parallel-region messages followed by pass.

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
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.