llvm / llvm/llvm-project

[Flang][OpenMP] Incorrect execution result for multiple common blocks in a copyin clause

Open
#207,126 1 comment 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

When multiple common blocks are specified in a `copyin` clause and their variables are referenced, incorrect execution results are observed. I could not find any documented restrictions regarding this.

### Reproducer

* test.f90

```fortran
use omp_lib, only: omp_get_thread_num
implicit none
integer :: a, b
common /aa/ a
common /cc/ b
!$omp threadprivate(/aa/, /cc/)
a = 1
b = 2
!$omp parallel copyin(/aa/, /cc/)
a = a + omp_get_thread_num()
b = b + omp_get_thread_num()
print *, "thread=", omp_get_thread_num(), "a=", a, "b=", b
!$omp end parallel
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 2301475676b208c555273e7c1ac5d4470d5ee70e)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 -fopenmp && ./a.out
thread= 0 a= 1 b= 2
thread= 2 a= 3 b= 2
thread= 3 a= 4 b= 3
thread= 1 a= 2 b= 1
```

NOTE: The value of `b` is expected to be `a+1`.

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Specifying a single common block in the `copyin` clause.
* Remove the addition to the variables:
```fortran
use omp_lib, only: omp_get_thread_num
implicit none
integer :: a, b
common /aa/ a
common /cc/ b
!$omp threadprivate(/aa/, /cc/)
a = 1
b = 2
!$omp parallel copyin(/aa/, /cc/)
a = omp_get_thread_num()
b = omp_get_thread_num()
print *, "thread=", omp_get_thread_num(), "a=", a, "b=", b
!$omp end parallel
end
```

## 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
thread= 0 a= 1 b= 2
thread= 3 a= 4 b= 5
thread= 1 a= 2 b= 3
thread= 2 a= 3 b= 4
```

* 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
thread= 0 a= 1 b= 2
thread= 2 a= 3 b= 4
thread= 1 a= 2 b= 3
thread= 3 a= 4 b= 5
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided test.f90 with flang -fopenmp and compare its output with the expected copyin behavior and the other compiler results. The payload names no Flang source file or existing test, so trace the handling of multiple common blocks in an OpenMP copyin clause from this reproducer. Done means both common blocks retain their copied-in values and each thread reports the expected a and b values.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.