[flang-commits] [flang] [flang] Fix NOTIFY= placement checking and folding (PR #231660)
via flang-commits
flang-commits at lists.llvm.org
Wed Oct 14 18:46:53 PDT 2026
================
@@ -0,0 +1,143 @@
+! NOTE: Do not autogenerate
+! RUN: %flang_fc1 -cpp -fopenmp -fopenmp-version=51 -fopenacc -fsyntax-only %s
+! RUN: %flang_fc1 -cpp -fopenmp -fopenmp-version=51 -fopenacc -fdebug-dump-parse-tree %s | FileCheck %s
+
+module notify_intrinsic_types
+ type t
+ integer :: value
+ integer :: values(4)
+ end type
+ interface assignment(=)
+ module procedure assign_integer
+ end interface
+contains
+ subroutine assign_integer(lhs, rhs)
+ type(t), intent(out) :: lhs
+ integer, intent(in) :: rhs
+ lhs%value = rhs
+ end subroutine
+end module
+
+module notify_intrinsic_bound_types
+ type t
+ integer :: value
+ contains
+ procedure :: assign_integer
+ generic :: assignment(=) => assign_integer
+ end type
+contains
+ subroutine assign_integer(lhs, rhs)
+ class(t), intent(out) :: lhs
+ integer, intent(in) :: rhs
+ lhs%value = rhs
+ end subroutine
+end module
+
+#define REMOTE b[1, notify=n]
+
+program intrinsic_notify_assignment
+ use iso_fortran_env, only: notify_type, team_type
+ use notify_intrinsic_types
+ use notify_intrinsic_bound_types, only: bound_t => t
+ implicit none
+ type container
+ integer, allocatable :: c[:]
+ end type
+ integer :: a(4)[*], b[*], local_array(4), status, i
+ logical :: mask(4)
+ type(t) :: d[*], rhs
+ type(bound_t) :: bound_d[*], bound_rhs
+ type(notify_type) :: n[*], na(4)[*]
+ type(team_type) :: team
+ type(container) :: x
+ character(8) :: text[*]
+ complex :: z[*]
+
+ !CHECK: AssignmentStmt = 'b[1_8,NOTIFY=n]=1_4'
+ b[1, notify=n] = 1
+ !CHECK: AssignmentStmt = 'a(1_8)[1_8,NOTIFY=na(2_8)]=2_4'
+ a(1)[1, notify=na(1+1)] = 2
+ a(:)[1, notify=n] = 3
+ d[1, notify=n]%value = 4
+ text[1, notify=n](2:4) = 'abc'
+ z[1, notify=n]%re = 5.
+ !CHECK: AssignmentStmt = 'b[1_8,STAT=status,NOTIFY=n]=6_4'
+ b[1, notify=n, stat=status] = 6
+ !CHECK: AssignmentStmt = 'b[1_8,STAT=status,NOTIFY=n,TEAM=team]=7_4'
+ b[1, stat=status, notify=n, team=team] = 7
+ !CHECK: AssignmentStmt = 'b[1_8,STAT=status,NOTIFY=n,TEAM_NUMBER=1_4]=8_4'
+ b[1, team_number=1, notify=n, stat=status] = 8
+ if (.true.) b[1, notify=n] = 9
+ where (mask) a(:)[1, notify=n] = 10
+ where (mask)
+ a(:)[1, notify=n] = 11
+ elsewhere
+ a(:)[1, notify=n] = 12
+ end where
+ forall (i=1:4) a(i)[1, notify=n] = 13
+ forall (i=1:4)
+ a(i)[1, notify=n] = 14
+ end forall
+
+ ! A visible but nonmatching generic leaves these assignments intrinsic.
+ d[1, notify=n] = rhs
+ bound_d[1, notify=n] = bound_rhs
+
+ ! Ordinary coindexed reads in target expressions remain permitted.
+ a(b[1])[2, notify=n] = 15
+ local_array(b[1]) = 16
+ a(1)[b[1], notify=na(1)] = 17
+ text[1, notify=n](b[1]:4) = 'abc'
+ b[1, &
+ notify=n] = 18
+ REMOTE = 19
+ a(1)[1, notify=na(b[1])] = 20
+ allocate(x%c[*])
+ x%c[1, notify=n] = 21
+ associate (remote => b)
+ remote[1, notify=n] = 22
+ end associate
+ d[1, notify=n]%values(2) = 23
+
+ !$omp atomic update
+ b[1, notify=n] = b[1] + 1
+ !$omp atomic capture
+ i = b[1]
+ b[1, notify=n] = b[1] + 1
+ !$omp end atomic
+ !$omp atomic capture
+ b[1, notify=n] = b[1] + 1
+ i = b[1]
+ !$omp end atomic
+ !$omp atomic compare
+ if (b[1] == i) b[1, notify=n] = 1
+ !$omp atomic compare capture
+ i = b[1]
+ if (b[1] == status) then
+ b[1, notify=n] = 1
+ end if
+ !$omp end atomic
+ !$acc atomic update
+ b[1, notify=n] = b[1] + 1
+ !$acc atomic capture
+ i = b[1]
+ b[1, notify=n] = b[1] + 1
+ !$acc end atomic
+ !$acc atomic capture
+ b[1, notify=n] = b[1] + 1
+ i = b[1]
+ !$acc end atomic
+
+ !$omp atomic update
+ d[1, notify=n]%value = d[1]%value + 1
+ !$omp atomic capture
+ i = d[1]%value
+ d[1, notify=n]%value = d[1]%value + 1
+ !$omp end atomic
+ !$acc atomic update
+ d[1, notify=n]%value = d[1]%value + 1
+ !$acc atomic capture
+ i = d[1]%value
+ d[1, notify=n]%value = d[1]%value + 1
+ !$acc end atomic
----------------
MattPD wrote:
Good point! I haven't found a permitted `NOTIFY=` use requiring this variable matching. During semantic analysis, only atomic checks call the matching helpers I traced: `IsSameOrConvertOf` and `IsVarSubexpressionOf`.
I've removed the atomic cases. The remaining tests cover the issue's requirements: F2023 C933 placement, notification folding and formatting.
The fix leaves `CoarrayRef` comparison unchanged, so I've also removed the comparison-only unit assertions.
https://github.com/llvm/llvm-project/pull/231660
More information about the flang-commits
mailing list