Skip to content

Commit

Permalink
[OpenACC] Implement 'wait' clause parsing.
Browse files Browse the repository at this point in the history
The 'wait' clause is parsed the same way as the 'wait' construct, so
this jsut differs to that function.
  • Loading branch information
erichkeane committed Jan 30, 2024
1 parent 58e8c07 commit 0dd0cbd
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 12 deletions.
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/OpenACCKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ enum class OpenACCClauseKind {
Tile,
/// 'gang' clause, allowed on 'loop' and Combined constructs.
Gang,
/// 'wait' clause, allowed on Compute, Data, 'update', and Combined
/// constructs.
Wait,

/// Represents an invalid clause, for the purposes of parsing.
Invalid,
Expand Down Expand Up @@ -376,6 +379,9 @@ inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &Out,
case OpenACCClauseKind::Gang:
return Out << "gang";

case OpenACCClauseKind::Wait:
return Out << "wait";

case OpenACCClauseKind::Invalid:
return Out << "<invalid>";
}
Expand Down
22 changes: 10 additions & 12 deletions clang/lib/Parse/ParseOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
.Case("use_device", OpenACCClauseKind::UseDevice)
.Case("vector", OpenACCClauseKind::Vector)
.Case("vector_length", OpenACCClauseKind::VectorLength)
.Case("wait", OpenACCClauseKind::Wait)
.Case("worker", OpenACCClauseKind::Worker)
.Default(OpenACCClauseKind::Invalid);
}
Expand Down Expand Up @@ -475,6 +476,7 @@ ClauseParensKind getClauseParensKind(OpenACCDirectiveKind DirKind,
case OpenACCClauseKind::Worker:
case OpenACCClauseKind::Vector:
case OpenACCClauseKind::Gang:
case OpenACCClauseKind::Wait:
return ClauseParensKind::Optional;

case OpenACCClauseKind::Default:
Expand Down Expand Up @@ -907,6 +909,12 @@ bool Parser::ParseOpenACCClauseParams(OpenACCDirectiveKind DirKind,
if (ParseOpenACCGangArgList())
return true;
break;
case OpenACCClauseKind::Wait:
if (ParseOpenACCWaitArgument()) {
Parens.skipToEnd();
return false;
}
break;
default:
llvm_unreachable("Not an optional parens type?");
}
Expand Down Expand Up @@ -940,8 +948,7 @@ bool Parser::ParseOpenACCWaitArgument() {
// Consume colon.
ConsumeToken();

ExprResult IntExpr =
getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression());
ExprResult IntExpr = ParseOpenACCIntExpr();
if (IntExpr.isInvalid())
return true;

Expand All @@ -962,14 +969,6 @@ bool Parser::ParseOpenACCWaitArgument() {
// the term 'async-argument' means a nonnegative scalar integer expression, or
// one of the special values 'acc_async_noval' or 'acc_async_sync', as defined
// in the C header file and the Fortran opacc module.
//
// We are parsing this simply as list of assignment expressions (to avoid
// comma being troublesome), and will ensure it is an integral type. The
// 'special' types are defined as macros, so we can't really check those
// (other than perhaps as values at one point?), but the standard does say it
// is implementation-defined to use any other negative value.
//
//
bool FirstArg = true;
while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) {
if (!FirstArg) {
Expand All @@ -978,8 +977,7 @@ bool Parser::ParseOpenACCWaitArgument() {
}
FirstArg = false;

ExprResult CurArg =
getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression());
ExprResult CurArg = ParseOpenACCAsyncArgument();

if (CurArg.isInvalid())
return true;
Expand Down
157 changes: 157 additions & 0 deletions clang/test/ParserOpenACC/parse-wait-clause.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// RUN: %clang_cc1 %s -verify -fopenacc

void func() {
int i, j;

// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait

// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (

// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait ()

// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait () clause-list

// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum:

// expected-error@+2{{expected expression}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum:)

// expected-error@+3{{expected expression}}
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum:) clause-list

// expected-error@+4{{expected ':'}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum: i + j

// expected-error@+2{{expected ':'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum: i + j)

// expected-error@+3{{expected ':'}}
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum: i + j) clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (queues:

// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (queues:)

// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (queues:) clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum: i + j:queues:

// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum: i + j:queues:)

// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (devnum: i + j:queues:) clause-list

// expected-error@+4{{use of undeclared identifier 'devnum'}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (queues:devnum: i + j

// expected-error@+2{{use of undeclared identifier 'devnum'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (queues:devnum: i + j)

// expected-error@+3{{use of undeclared identifier 'devnum'}}
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait (queues:devnum: i + j) clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(i, j, 1+1, 3.3

// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(i, j, 1+1, 3.3)
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(i, j, 1+1, 3.3) clause-list

// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(,

// expected-error@+2{{expected expression}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(,)

// expected-error@+3{{expected expression}}
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(,) clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(queues:i, j, 1+1, 3.3

// expected-error@+4{{expected expression}}
// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(queues:i, j, 1+1, 3.3,

// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(queues:i, j, 1+1, 3.3)

// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(queues:i, j, 1+1, 3.3) clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(devnum:3:i, j, 1+1, 3.3
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(devnum:3:i, j, 1+1, 3.3)
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(devnum:3:i, j, 1+1, 3.3) clause-list

// expected-error@+3{{expected ')'}}
// expected-note@+2{{to match this '('}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(devnum:3:queues:i, j, 1+1, 3.3
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(devnum:3:queues:i, j, 1+1, 3.3)
// expected-error@+2{{invalid OpenACC clause 'clause'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc parallel wait(devnum:3:queues:i, j, 1+1, 3.3) clause-list
}

0 comments on commit 0dd0cbd

Please sign in to comment.