@@ -39,11 +39,27 @@ bool diagnoseConstructAppertainment(SemaOpenACC &S, OpenACCDirectiveKind K,
3939
4040bool doesClauseApplyToDirective (OpenACCDirectiveKind DirectiveKind,
4141 OpenACCClauseKind ClauseKind) {
42- // FIXME: For each clause as we implement them, we can add the
43- // 'legalization' list here.
44-
45- // Do nothing so we can go to the 'unimplemented' diagnostic instead.
46- return true ;
42+ switch (ClauseKind) {
43+ // FIXME: For each clause as we implement them, we can add the
44+ // 'legalization' list here.
45+ case OpenACCClauseKind::Default:
46+ switch (DirectiveKind) {
47+ case OpenACCDirectiveKind::Parallel:
48+ case OpenACCDirectiveKind::Serial:
49+ case OpenACCDirectiveKind::Kernels:
50+ case OpenACCDirectiveKind::ParallelLoop:
51+ case OpenACCDirectiveKind::SerialLoop:
52+ case OpenACCDirectiveKind::KernelsLoop:
53+ case OpenACCDirectiveKind::Data:
54+ return true ;
55+ default :
56+ return false ;
57+ }
58+ default :
59+ // Do nothing so we can go to the 'unimplemented' diagnostic instead.
60+ return true ;
61+ }
62+ llvm_unreachable (" Invalid clause kind" );
4763}
4864} // namespace
4965
@@ -63,8 +79,43 @@ SemaOpenACC::ActOnClause(ArrayRef<const OpenACCClause *> ExistingClauses,
6379 return nullptr ;
6480 }
6581
66- // TODO OpenACC: Switch over the clauses we implement here and 'create'
67- // them.
82+ switch (Clause.getClauseKind ()) {
83+ case OpenACCClauseKind::Default: {
84+ // Restrictions only properly implemented on 'compute' constructs, and
85+ // 'compute' constructs are the only construct that can do anything with
86+ // this yet, so skip/treat as unimplemented in this case.
87+ if (Clause.getDirectiveKind () != OpenACCDirectiveKind::Parallel &&
88+ Clause.getDirectiveKind () != OpenACCDirectiveKind::Serial &&
89+ Clause.getDirectiveKind () != OpenACCDirectiveKind::Kernels)
90+ break ;
91+
92+ // Don't add an invalid clause to the AST.
93+ if (Clause.getDefaultClauseKind () == OpenACCDefaultClauseKind::Invalid)
94+ return nullptr ;
95+
96+ // OpenACC 3.3, Section 2.5.4:
97+ // At most one 'default' clause may appear, and it must have a value of
98+ // either 'none' or 'present'.
99+ // Second half of the sentence is diagnosed during parsing.
100+ auto Itr = llvm::find_if (ExistingClauses, [](const OpenACCClause *C) {
101+ return C->getClauseKind () == OpenACCClauseKind::Default;
102+ });
103+
104+ if (Itr != ExistingClauses.end ()) {
105+ SemaRef.Diag (Clause.getBeginLoc (),
106+ diag::err_acc_duplicate_clause_disallowed)
107+ << Clause.getDirectiveKind () << Clause.getClauseKind ();
108+ SemaRef.Diag ((*Itr)->getBeginLoc (), diag::note_acc_previous_clause_here);
109+ return nullptr ;
110+ }
111+
112+ return OpenACCDefaultClause::Create (
113+ getASTContext (), Clause.getDefaultClauseKind (), Clause.getBeginLoc (),
114+ Clause.getLParenLoc (), Clause.getEndLoc ());
115+ }
116+ default :
117+ break ;
118+ }
68119
69120 Diag (Clause.getBeginLoc (), diag::warn_acc_clause_unimplemented)
70121 << Clause.getClauseKind ();
0 commit comments