@@ -393,10 +393,12 @@ enum ClauseParensKind {
393
393
Required
394
394
};
395
395
396
- ClauseParensKind getClauseParensKind (OpenACCClauseKind Kind) {
396
+ ClauseParensKind getClauseParensKind (OpenACCDirectiveKind DirKind,
397
+ OpenACCClauseKind Kind) {
397
398
switch (Kind) {
398
399
case OpenACCClauseKind::Self:
399
- return ClauseParensKind::Optional;
400
+ return DirKind == OpenACCDirectiveKind::Update ? ClauseParensKind::Required
401
+ : ClauseParensKind::Optional;
400
402
401
403
case OpenACCClauseKind::Default:
402
404
case OpenACCClauseKind::If:
@@ -433,12 +435,14 @@ ClauseParensKind getClauseParensKind(OpenACCClauseKind Kind) {
433
435
llvm_unreachable (" Unhandled clause kind" );
434
436
}
435
437
436
- bool ClauseHasOptionalParens (OpenACCClauseKind Kind) {
437
- return getClauseParensKind (Kind) == ClauseParensKind::Optional;
438
+ bool ClauseHasOptionalParens (OpenACCDirectiveKind DirKind,
439
+ OpenACCClauseKind Kind) {
440
+ return getClauseParensKind (DirKind, Kind) == ClauseParensKind::Optional;
438
441
}
439
442
440
- bool ClauseHasRequiredParens (OpenACCClauseKind Kind) {
441
- return getClauseParensKind (Kind) == ClauseParensKind::Required;
443
+ bool ClauseHasRequiredParens (OpenACCDirectiveKind DirKind,
444
+ OpenACCClauseKind Kind) {
445
+ return getClauseParensKind (DirKind, Kind) == ClauseParensKind::Required;
442
446
}
443
447
444
448
ExprResult ParseOpenACCConditionalExpr (Parser &P) {
@@ -465,7 +469,7 @@ void SkipUntilEndOfDirective(Parser &P) {
465
469
// a pqr-list is a comma-separated list of pdr items. The one exception is a
466
470
// clause-list, which is a list of one or more clauses optionally separated by
467
471
// commas.
468
- void Parser::ParseOpenACCClauseList () {
472
+ void Parser::ParseOpenACCClauseList (OpenACCDirectiveKind DirKind ) {
469
473
bool FirstClause = true ;
470
474
while (getCurToken ().isNot (tok::annot_pragma_openacc_end)) {
471
475
// Comma is optional in a clause-list.
@@ -475,7 +479,7 @@ void Parser::ParseOpenACCClauseList() {
475
479
476
480
// Recovering from a bad clause is really difficult, so we just give up on
477
481
// error.
478
- if (ParseOpenACCClause ()) {
482
+ if (ParseOpenACCClause (DirKind )) {
479
483
SkipUntilEndOfDirective (*this );
480
484
return ;
481
485
}
@@ -508,7 +512,7 @@ bool Parser::ParseOpenACCClauseVarList(OpenACCClauseKind Kind) {
508
512
// really have its owner grammar and each individual one has its own definition.
509
513
// However, they all are named with a single-identifier (or auto/default!)
510
514
// token, followed in some cases by either braces or parens.
511
- bool Parser::ParseOpenACCClause () {
515
+ bool Parser::ParseOpenACCClause (OpenACCDirectiveKind DirKind ) {
512
516
// A number of clause names are actually keywords, so accept a keyword that
513
517
// can be converted to a name.
514
518
if (expectIdentifierOrKeyword (*this ))
@@ -523,14 +527,15 @@ bool Parser::ParseOpenACCClause() {
523
527
// Consume the clause name.
524
528
ConsumeToken ();
525
529
526
- return ParseOpenACCClauseParams (Kind);
530
+ return ParseOpenACCClauseParams (DirKind, Kind);
527
531
}
528
532
529
- bool Parser::ParseOpenACCClauseParams (OpenACCClauseKind Kind) {
533
+ bool Parser::ParseOpenACCClauseParams (OpenACCDirectiveKind DirKind,
534
+ OpenACCClauseKind Kind) {
530
535
BalancedDelimiterTracker Parens (*this , tok::l_paren,
531
536
tok::annot_pragma_openacc_end);
532
537
533
- if (ClauseHasRequiredParens (Kind)) {
538
+ if (ClauseHasRequiredParens (DirKind, Kind)) {
534
539
if (Parens.expectAndConsume ()) {
535
540
// We are missing a paren, so assume that the person just forgot the
536
541
// parameter. Return 'false' so we try to continue on and parse the next
@@ -576,6 +581,12 @@ bool Parser::ParseOpenACCClauseParams(OpenACCClauseKind Kind) {
576
581
if (ParseOpenACCClauseVarList (Kind))
577
582
return true ;
578
583
break ;
584
+ case OpenACCClauseKind::Self:
585
+ // The 'self' clause is a var-list instead of a 'condition' in the case of
586
+ // the 'update' clause, so we have to handle it here. U se an assert to
587
+ // make sure we get the right differentiator.
588
+ assert (DirKind == OpenACCDirectiveKind::Update);
589
+ LLVM_FALLTHROUGH;
579
590
case OpenACCClauseKind::Attach:
580
591
case OpenACCClauseKind::Copy:
581
592
case OpenACCClauseKind::Delete:
@@ -598,10 +609,11 @@ bool Parser::ParseOpenACCClauseParams(OpenACCClauseKind Kind) {
598
609
}
599
610
600
611
return Parens.consumeClose ();
601
- } else if (ClauseHasOptionalParens (Kind)) {
612
+ } else if (ClauseHasOptionalParens (DirKind, Kind)) {
602
613
if (!Parens.consumeOpen ()) {
603
614
switch (Kind) {
604
615
case OpenACCClauseKind::Self: {
616
+ assert (DirKind != OpenACCDirectiveKind::Update);
605
617
ExprResult CondExpr = ParseOpenACCConditionalExpr (*this );
606
618
// An invalid expression can be just about anything, so just give up on
607
619
// this clause list.
@@ -817,7 +829,7 @@ void Parser::ParseOpenACCDirective() {
817
829
}
818
830
819
831
// Parses the list of clauses, if present.
820
- ParseOpenACCClauseList ();
832
+ ParseOpenACCClauseList (DirKind );
821
833
822
834
Diag (getCurToken (), diag::warn_pragma_acc_unimplemented);
823
835
assert (Tok.is (tok::annot_pragma_openacc_end) &&
0 commit comments