[flang][OpenMP] Only privaize pre-determined symbols when defined the evaluation. (#154070)

Fixes a regression uncovered by Fujitsu test 0686_0024.f90. In
particular, verifies that a pre-determined symbol is only privatized by
its defining evaluation (e.g. the loop for which the symbol was marked
as pre-determined).
This commit is contained in:
Kareem Ergawy 2025-08-18 13:36:08 +02:00 committed by GitHub
parent cfe5975eaf
commit c1e2a9c66d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 1 deletions

View File

@ -571,7 +571,8 @@ void DataSharingProcessor::collectSymbols(
if (collectPreDetermined) {
// Similar to implicit symbols, collect pre-determined symbols only if
// they are not defined by a nested `DeclarationConstruct`
return !visitor.isSymbolDefineByNestedDeclaration(sym) &&
return visitor.isSymbolDefineBy(sym, eval) &&
!visitor.isSymbolDefineByNestedDeclaration(sym) &&
sym->test(semantics::Symbol::Flag::OmpPreDetermined);
}

View File

@ -0,0 +1,35 @@
! Fixes a regression uncovered by Fujitsu test 0686_0024.f90. In particular,
! verifies that a pre-determined symbol is only privatized by its defining
! evaluation (e.g. the loop for which the symbol was marked as pre-determined).
! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
subroutine privatize_predetermined_when_defined_by_eval
integer::i,ii
integer::j
!$omp parallel
!$omp do lastprivate(ii)
do i=1,10
do ii=1,10
enddo
enddo
!$omp do
do j=1,ii
enddo
!$omp end parallel
end subroutine
! Verify that nothing is privatized by the `omp.parallel` op.
! CHECK: omp.parallel {
! Verify that `i` and `ii` are privatized by the first loop.
! CHECK: omp.wsloop private(@{{.*}}ii_private_i32 %{{.*}}#0 -> %{{.*}}, @{{.*}}i_private_i32 %2#0 -> %{{.*}} : {{.*}}) {
! CHECK: }
! Verify that `j` is privatized by the second loop.
! CHECK: omp.wsloop private(@{{.*}}j_private_i32 %{{.*}}#0 -> %{{.*}} : {{.*}}) {
! CHECK: }
! CHECK: }