Skip to content

Commit e8824e0

Browse files
committed
[flang][openacc] Relax required clauses on acc data as portability warning
Some compilers accept `!$acc data` without any clauses. For portability reason, this patch relaxes the strict error to a simple portability warning. Reviewed By: razvanlupusoru, vzakhari Differential Revision: https://reviews.llvm.org/D159019
1 parent 031b4e5 commit e8824e0

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

flang/docs/OpenACC.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
* An `!$acc routine` with no parallelism clause is treated as if the `seq`
1919
clause was present.
2020
* `!$acc end loop` does not trigger a parsing error and is just ignored.
21+
* The restriction on `!$acc data` required clauses is emitted as a portability
22+
warning instead of an error as other compiler accepts it.

flang/lib/Lower/OpenACC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,9 @@ static void genACCDataOp(Fortran::lower::AbstractConverter &converter,
19371937
addOperands(operands, operandSegments, waitOperands);
19381938
addOperands(operands, operandSegments, dataClauseOperands);
19391939

1940+
if (dataClauseOperands.empty() && !hasDefaultNone && !hasDefaultPresent)
1941+
return;
1942+
19401943
auto dataOp = createRegionOp<mlir::acc::DataOp, mlir::acc::TerminatorOp>(
19411944
builder, currentLocation, operands, operandSegments);
19421945

flang/lib/Semantics/check-acc-structure.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ void AccStructureChecker::Leave(const parser::OpenACCBlockConstruct &x) {
147147
CheckNoBranching(block, GetContext().directive, blockDir.source);
148148
break;
149149
case llvm::acc::Directive::ACCD_data:
150-
// Restriction - line 1249-1250
151-
CheckRequireAtLeastOneOf();
150+
// Restriction - 2.6.5 pt 1
151+
// Only a warning is emitted here for portability reason.
152+
CheckRequireAtLeastOneOf(/*warnInsteadOfError=*/true);
152153
// Restriction is not formally in the specification but all compilers emit
153154
// an error and it is likely to be omitted from the spec.
154155
CheckNoBranching(block, GetContext().directive, blockDir.source);

flang/lib/Semantics/check-directive-structure.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class DirectiveStructureChecker : public virtual BaseChecker {
331331
// Check that only clauses in set are after the specific clauses.
332332
void CheckOnlyAllowedAfter(C clause, common::EnumSet<C, ClauseEnumSize> set);
333333

334-
void CheckRequireAtLeastOneOf();
334+
void CheckRequireAtLeastOneOf(bool warnInsteadOfError = false);
335335

336336
void CheckAllowed(C clause);
337337

@@ -422,18 +422,24 @@ DirectiveStructureChecker<D, C, PC, ClauseEnumSize>::ClauseSetToString(
422422
// directive.
423423
template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>
424424
void DirectiveStructureChecker<D, C, PC,
425-
ClauseEnumSize>::CheckRequireAtLeastOneOf() {
425+
ClauseEnumSize>::CheckRequireAtLeastOneOf(bool warnInsteadOfError) {
426426
if (GetContext().requiredClauses.empty())
427427
return;
428428
for (auto cl : GetContext().actualClauses) {
429429
if (GetContext().requiredClauses.test(cl))
430430
return;
431431
}
432432
// No clause matched in the actual clauses list
433-
context_.Say(GetContext().directiveSource,
434-
"At least one of %s clause must appear on the %s directive"_err_en_US,
435-
ClauseSetToString(GetContext().requiredClauses),
436-
ContextDirectiveAsFortran());
433+
if (warnInsteadOfError)
434+
context_.Say(GetContext().directiveSource,
435+
"At least one of %s clause should appear on the %s directive"_port_en_US,
436+
ClauseSetToString(GetContext().requiredClauses),
437+
ContextDirectiveAsFortran());
438+
else
439+
context_.Say(GetContext().directiveSource,
440+
"At least one of %s clause must appear on the %s directive"_err_en_US,
441+
ClauseSetToString(GetContext().requiredClauses),
442+
ContextDirectiveAsFortran());
437443
}
438444

439445
template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>

flang/test/Lower/OpenACC/acc-data.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,9 @@ subroutine acc_data
188188
! CHECK: acc.terminator
189189
! CHECK: } attributes {defaultAttr = #acc<defaultvalue present>}
190190

191+
!$acc data
192+
!$acc end data
193+
! CHECK-NOT: acc.data
194+
191195
end subroutine acc_data
192196

flang/test/Semantics/OpenACC/acc-data.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ program openacc_data_validity
132132
!ERROR: At least one of COPYOUT, DELETE, DETACH clause must appear on the EXIT DATA directive
133133
!$acc exit data
134134

135-
!ERROR: At least one of ATTACH, COPY, COPYIN, COPYOUT, CREATE, DEFAULT, DEVICEPTR, NO_CREATE, PRESENT clause must appear on the DATA directive
135+
!PORTABILITY: At least one of ATTACH, COPY, COPYIN, COPYOUT, CREATE, DEFAULT, DEVICEPTR, NO_CREATE, PRESENT clause should appear on the DATA directive
136136
!$acc data
137137
!$acc end data
138138

0 commit comments

Comments
 (0)