diff --git a/flang/docs/OpenACC.md b/flang/docs/OpenACC.md index 79b7e3000b02a..2becfb1aeac1a 100644 --- a/flang/docs/OpenACC.md +++ b/flang/docs/OpenACC.md @@ -18,3 +18,5 @@ * An `!$acc routine` with no parallelism clause is treated as if the `seq` clause was present. * `!$acc end loop` does not trigger a parsing error and is just ignored. +* The restriction on `!$acc data` required clauses is emitted as a portability + warning instead of an error as other compiler accepts it. diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 5ec04722cd5e1..d6f6ae18a4011 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -1937,6 +1937,9 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter, addOperands(operands, operandSegments, waitOperands); addOperands(operands, operandSegments, dataClauseOperands); + if (dataClauseOperands.empty() && !hasDefaultNone && !hasDefaultPresent) + return; + auto dataOp = createRegionOp( builder, currentLocation, operands, operandSegments); diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp index 677a1d65b13ee..692a7a408947a 100644 --- a/flang/lib/Semantics/check-acc-structure.cpp +++ b/flang/lib/Semantics/check-acc-structure.cpp @@ -147,8 +147,9 @@ void AccStructureChecker::Leave(const parser::OpenACCBlockConstruct &x) { CheckNoBranching(block, GetContext().directive, blockDir.source); break; case llvm::acc::Directive::ACCD_data: - // Restriction - line 1249-1250 - CheckRequireAtLeastOneOf(); + // Restriction - 2.6.5 pt 1 + // Only a warning is emitted here for portability reason. + CheckRequireAtLeastOneOf(/*warnInsteadOfError=*/true); // Restriction is not formally in the specification but all compilers emit // an error and it is likely to be omitted from the spec. CheckNoBranching(block, GetContext().directive, blockDir.source); diff --git a/flang/lib/Semantics/check-directive-structure.h b/flang/lib/Semantics/check-directive-structure.h index 5dc1d7b488557..14a3151e67268 100644 --- a/flang/lib/Semantics/check-directive-structure.h +++ b/flang/lib/Semantics/check-directive-structure.h @@ -331,7 +331,7 @@ class DirectiveStructureChecker : public virtual BaseChecker { // Check that only clauses in set are after the specific clauses. void CheckOnlyAllowedAfter(C clause, common::EnumSet set); - void CheckRequireAtLeastOneOf(); + void CheckRequireAtLeastOneOf(bool warnInsteadOfError = false); void CheckAllowed(C clause); @@ -422,7 +422,7 @@ DirectiveStructureChecker::ClauseSetToString( // directive. template void DirectiveStructureChecker::CheckRequireAtLeastOneOf() { + ClauseEnumSize>::CheckRequireAtLeastOneOf(bool warnInsteadOfError) { if (GetContext().requiredClauses.empty()) return; for (auto cl : GetContext().actualClauses) { @@ -430,10 +430,16 @@ void DirectiveStructureChecker diff --git a/flang/test/Lower/OpenACC/acc-data.f90 b/flang/test/Lower/OpenACC/acc-data.f90 index 57336a761c73e..5226474d012c1 100644 --- a/flang/test/Lower/OpenACC/acc-data.f90 +++ b/flang/test/Lower/OpenACC/acc-data.f90 @@ -188,5 +188,9 @@ subroutine acc_data ! CHECK: acc.terminator ! CHECK: } attributes {defaultAttr = #acc} + !$acc data + !$acc end data +! CHECK-NOT: acc.data + end subroutine acc_data diff --git a/flang/test/Semantics/OpenACC/acc-data.f90 b/flang/test/Semantics/OpenACC/acc-data.f90 index de168ba70d19b..17e0624b8cf24 100644 --- a/flang/test/Semantics/OpenACC/acc-data.f90 +++ b/flang/test/Semantics/OpenACC/acc-data.f90 @@ -132,7 +132,7 @@ program openacc_data_validity !ERROR: At least one of COPYOUT, DELETE, DETACH clause must appear on the EXIT DATA directive !$acc exit data - !ERROR: At least one of ATTACH, COPY, COPYIN, COPYOUT, CREATE, DEFAULT, DEVICEPTR, NO_CREATE, PRESENT clause must appear on the DATA directive + !PORTABILITY: At least one of ATTACH, COPY, COPYIN, COPYOUT, CREATE, DEFAULT, DEVICEPTR, NO_CREATE, PRESENT clause should appear on the DATA directive !$acc data !$acc end data