@@ -341,31 +341,64 @@ bool checkAlreadyHasClauseOfKind(
341
341
return false ;
342
342
}
343
343
344
- // / Implement check from OpenACC3.3: section 2.5.4:
345
- // / Only the async, wait, num_gangs, num_workers, and vector_length clauses may
346
- // / follow a device_type clause.
347
344
bool checkValidAfterDeviceType (
348
345
SemaOpenACC &S, const OpenACCDeviceTypeClause &DeviceTypeClause,
349
346
const SemaOpenACC::OpenACCParsedClause &NewClause) {
350
- // This is only a requirement on compute constructs so far, so this is fine
351
- // otherwise.
352
- if (!isOpenACCComputeDirectiveKind (NewClause.getDirectiveKind ()))
347
+ // This is only a requirement on compute and loop constructs so far, so this
348
+ // is fine otherwise.
349
+ if (!isOpenACCComputeDirectiveKind (NewClause.getDirectiveKind ()) &&
350
+ NewClause.getDirectiveKind () != OpenACCDirectiveKind::Loop)
353
351
return false ;
354
- switch (NewClause.getClauseKind ()) {
355
- case OpenACCClauseKind::Async:
356
- case OpenACCClauseKind::Wait:
357
- case OpenACCClauseKind::NumGangs:
358
- case OpenACCClauseKind::NumWorkers:
359
- case OpenACCClauseKind::VectorLength:
360
- case OpenACCClauseKind::DType:
361
- case OpenACCClauseKind::DeviceType:
352
+
353
+ // OpenACC3.3: Section 2.4: Clauses that precede any device_type clause are
354
+ // default clauses. Clauses that follow a device_type clause up to the end of
355
+ // the directive or up to the next device_type clause are device-specific
356
+ // clauses for the device types specified in the device_type argument.
357
+ //
358
+ // The above implies that despite what the individual text says, these are
359
+ // valid.
360
+ if (NewClause.getClauseKind () == OpenACCClauseKind::DType ||
361
+ NewClause.getClauseKind () == OpenACCClauseKind::DeviceType)
362
362
return false ;
363
- default :
364
- S.Diag (NewClause.getBeginLoc (), diag::err_acc_clause_after_device_type)
365
- << NewClause.getClauseKind () << DeviceTypeClause.getClauseKind ();
366
- S.Diag (DeviceTypeClause.getBeginLoc (), diag::note_acc_previous_clause_here);
367
- return true ;
363
+
364
+ // Implement check from OpenACC3.3: section 2.5.4:
365
+ // Only the async, wait, num_gangs, num_workers, and vector_length clauses may
366
+ // follow a device_type clause.
367
+ if (isOpenACCComputeDirectiveKind (NewClause.getDirectiveKind ())) {
368
+ switch (NewClause.getClauseKind ()) {
369
+ case OpenACCClauseKind::Async:
370
+ case OpenACCClauseKind::Wait:
371
+ case OpenACCClauseKind::NumGangs:
372
+ case OpenACCClauseKind::NumWorkers:
373
+ case OpenACCClauseKind::VectorLength:
374
+ return false ;
375
+ default :
376
+ break ;
377
+ }
378
+ } else if (NewClause.getDirectiveKind () == OpenACCDirectiveKind::Loop) {
379
+ // Implement check from OpenACC3.3: section 2.9:
380
+ // Only the collapse, gang, worker, vector, seq, independent, auto, and tile
381
+ // clauses may follow a device_type clause.
382
+ switch (NewClause.getClauseKind ()) {
383
+ case OpenACCClauseKind::Collapse:
384
+ case OpenACCClauseKind::Gang:
385
+ case OpenACCClauseKind::Worker:
386
+ case OpenACCClauseKind::Vector:
387
+ case OpenACCClauseKind::Seq:
388
+ case OpenACCClauseKind::Independent:
389
+ case OpenACCClauseKind::Auto:
390
+ case OpenACCClauseKind::Tile:
391
+ return false ;
392
+ default :
393
+ break ;
394
+ }
368
395
}
396
+ S.Diag (NewClause.getBeginLoc (), diag::err_acc_clause_after_device_type)
397
+ << NewClause.getClauseKind () << DeviceTypeClause.getClauseKind ()
398
+ << isOpenACCComputeDirectiveKind (NewClause.getDirectiveKind ())
399
+ << NewClause.getDirectiveKind ();
400
+ S.Diag (DeviceTypeClause.getBeginLoc (), diag::note_acc_previous_clause_here);
401
+ return true ;
369
402
}
370
403
} // namespace
371
404
@@ -816,10 +849,12 @@ SemaOpenACC::ActOnClause(ArrayRef<const OpenACCClause *> ExistingClauses,
816
849
}
817
850
case OpenACCClauseKind::DType:
818
851
case OpenACCClauseKind::DeviceType: {
819
- // Restrictions only properly implemented on 'compute' constructs, and
820
- // 'compute' constructs are the only construct that can do anything with
821
- // this yet, so skip/treat as unimplemented in this case.
822
- if (!isOpenACCComputeDirectiveKind (Clause.getDirectiveKind ()))
852
+ // Restrictions only properly implemented on 'compute' and 'loop'
853
+ // constructs, and 'compute'/'loop' constructs are the only construct that
854
+ // can do anything with this yet, so skip/treat as unimplemented in this
855
+ // case.
856
+ if (!isOpenACCComputeDirectiveKind (Clause.getDirectiveKind ()) &&
857
+ Clause.getDirectiveKind () != OpenACCDirectiveKind::Loop)
823
858
break ;
824
859
825
860
// TODO OpenACC: Once we get enough of the CodeGen implemented that we have
0 commit comments