[flang-commits] [flang] [flang][OpenMP] incorrect handling for local variable in OpenMP parallel workshare firstprivate(P) (PR #195616)

via flang-commits flang-commits at lists.llvm.org
Tue Jun 2 22:34:20 PDT 2026


SunilKuravinakop wrote:

>I'm worried fir.ptr might lead to more pessimistic handling by fir::AliasAnalysis.
I think the problem here is trying to make a pointer to a pointer. Off the top of my head I can't remember another case where this is done in Flang. This suggests to me a broader design problem that is going unaddressed.

Are you referring to examples like:
```
  real(8), pointer :: z(:), a(:)
  !$omp parallel workshare firstprivate(z)
  a = z + 1.0
  !$omp end parallel workshare
```
>If you want a private copy then you need to duplicate the type which is being pointed to not just make a copy of the !fir.ref. It is by design that you can't have two references pointing at the same memory. I'd be worried about having one pointer and one ref engineered to be the same memory - I imagine this will break an alias analysis assumption somewhere.

I have looked at the -emit-hlfir and -emit-mlir outputs. Here the private/duplicate copies of the z in the thread will be pointing to the same memory as the original z. It is preferable to avoid deep copy of the pointers. If I have to then please point me to currently existing precedence of this in the code. I will ensure a call is done to it.

https://github.com/llvm/llvm-project/pull/195616


More information about the flang-commits mailing list