Skip to content

[flang] Improve OpenACC SELF clause parser #135883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flang/lib/Parser/openacc-parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ TYPE_PARSER(construct<AccDefaultClause>(
// SELF clause is either a simple optional condition for compute construct
// or a synonym of the HOST clause for the update directive 2.14.4 holding
// an object list.
TYPE_PARSER(construct<AccSelfClause>(Parser<AccObjectList>{}) ||
construct<AccSelfClause>(scalarLogicalExpr))
TYPE_PARSER(
construct<AccSelfClause>(Parser<AccObjectList>{}) / lookAhead(")"_tok) ||
construct<AccSelfClause>(scalarLogicalExpr / lookAhead(")"_tok)) ||
construct<AccSelfClause>(
recovery(fail<std::optional<ScalarLogicalExpr>>(
"logical expression or object list expected"_err_en_US),
SkipTo<')'>{} >> pure<std::optional<ScalarLogicalExpr>>())))

// Modifier for copyin, copyout, cache and create
TYPE_PARSER(construct<AccDataModifier>(
Expand Down
14 changes: 14 additions & 0 deletions flang/test/Semantics/OpenACC/bug135810-1.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenacc
integer function square(x, y)
implicit none
integer, intent(in) :: x, y
!$acc parallel self(x * 2 > x) ! ok
!$acc end parallel
!ERROR: Must have LOGICAL type, but is INTEGER(4)
!$acc parallel self(x * 2)
!$acc end parallel
!ERROR: SELF clause on the PARALLEL directive only accepts optional scalar logical expression
!$acc parallel self(x, y)
!$acc end parallel
square = x * x
end function square
12 changes: 12 additions & 0 deletions flang/test/Semantics/OpenACC/bug135810-2.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
! RUN: %python %S/../test_errors.py %s %flang -fopenacc
integer function square(x)
implicit none
integer, intent(in) :: x
!ERROR: logical expression or object list expected
!$acc parallel self(,)
!$acc end parallel
!ERROR: logical expression or object list expected
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a test that !$acc parallel self(object-list) would cause a diagnostic? (as self only takes an object list when used on an update construct).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's done by semantics, not the parser; but I'll add a test here since there isn't one elsewhere.

!$acc parallel self(.true., )
!$acc end parallel
square = x * x
end function square
Loading