diff --git a/clang/include/clang/Basic/OpenACCKinds.h b/clang/include/clang/Basic/OpenACCKinds.h index 04bc2a674af19..afdd0e8983c9e 100644 --- a/clang/include/clang/Basic/OpenACCKinds.h +++ b/clang/include/clang/Basic/OpenACCKinds.h @@ -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, @@ -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 << ""; } diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index b9f2d3c9e1e5e..bfe5061481ad9 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -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); } @@ -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: @@ -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?"); } @@ -940,8 +948,7 @@ bool Parser::ParseOpenACCWaitArgument() { // Consume colon. ConsumeToken(); - ExprResult IntExpr = - getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression()); + ExprResult IntExpr = ParseOpenACCIntExpr(); if (IntExpr.isInvalid()) return true; @@ -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) { @@ -978,8 +977,7 @@ bool Parser::ParseOpenACCWaitArgument() { } FirstArg = false; - ExprResult CurArg = - getActions().CorrectDelayedTyposInExpr(ParseAssignmentExpression()); + ExprResult CurArg = ParseOpenACCAsyncArgument(); if (CurArg.isInvalid()) return true; diff --git a/clang/test/ParserOpenACC/parse-wait-clause.c b/clang/test/ParserOpenACC/parse-wait-clause.c new file mode 100644 index 0000000000000..7639e6242ea67 --- /dev/null +++ b/clang/test/ParserOpenACC/parse-wait-clause.c @@ -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 +}