From 609361ab39226a866211286a2ae4f19ab8bb444c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Fri, 11 Apr 2025 13:54:48 -0700 Subject: [PATCH] [flang][openacc] Allow finalize clause on exit data more than once (#135415) The spec has not strict restriction to allow a single `finalize` clause on the `exit data` directive. Allowing this clause multiple times does not change the semantic of it. This patch relax the rules in `ACC.td` since there is no restriction in the standard. The OpenACC dialect represent the finalize clause with a UnitAttr so the attribute will be set if the is one or more `finalize` clause. --- flang/test/Lower/OpenACC/acc-exit-data.f90 | 5 +++++ flang/test/Semantics/OpenACC/acc-data.f90 | 2 +- llvm/include/llvm/Frontend/OpenACC/ACC.td | 12 ++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/flang/test/Lower/OpenACC/acc-exit-data.f90 b/flang/test/Lower/OpenACC/acc-exit-data.f90 index fbd1edfb6afe..bf5f7094913a 100644 --- a/flang/test/Lower/OpenACC/acc-exit-data.f90 +++ b/flang/test/Lower/OpenACC/acc-exit-data.f90 @@ -102,4 +102,9 @@ subroutine acc_exit_data !CHECK: acc.exit_data wait_devnum(%[[WAIT6]] : i32) wait(%[[WAIT4]], %[[WAIT5]] : i32, i32) dataOperands(%[[DEVPTR]] : !fir.ref>) !CHECK: acc.delete accPtr(%[[DEVPTR]] : !fir.ref>) {name = "a", structured = false} + !$acc exit data delete(a) finalize +!CHECK: acc.exit_data dataOperands(%{{.*}} : !fir.ref>) attributes {finalize} + + !$acc exit data delete(a) finalize finalize +!CHECK: acc.exit_data dataOperands(%{{.*}} : !fir.ref>) attributes {finalize} end subroutine acc_exit_data diff --git a/flang/test/Semantics/OpenACC/acc-data.f90 b/flang/test/Semantics/OpenACC/acc-data.f90 index 84eb72825b34..ac49532c495d 100644 --- a/flang/test/Semantics/OpenACC/acc-data.f90 +++ b/flang/test/Semantics/OpenACC/acc-data.f90 @@ -86,7 +86,7 @@ program openacc_data_validity !$acc exit data delete(aa) finalize - !ERROR: At most one FINALIZE clause can appear on the EXIT DATA directive + ! OK !$acc exit data delete(aa) finalize finalize !ERROR: Argument `cc` on the DETACH clause must be a variable or array with the POINTER or ALLOCATABLE attribute diff --git a/llvm/include/llvm/Frontend/OpenACC/ACC.td b/llvm/include/llvm/Frontend/OpenACC/ACC.td index 8729d4505205..cee0d53458a0 100644 --- a/llvm/include/llvm/Frontend/OpenACC/ACC.td +++ b/llvm/include/llvm/Frontend/OpenACC/ACC.td @@ -535,14 +535,10 @@ def ACC_EnterData : Directive<"enter data"> { // 2.14.7 def ACC_ExitData : Directive<"exit data"> { - let allowedClauses = [ - VersionedClause - ]; - let allowedOnceClauses = [ - VersionedClause, - VersionedClause, - VersionedClause - ]; + let allowedClauses = [VersionedClause, + VersionedClause]; + let allowedOnceClauses = [VersionedClause, + VersionedClause]; let requiredClauses = [ VersionedClause, VersionedClause,