Skip to content

Commit

Permalink
[OpenACC] Handle lack of construct/directive
Browse files Browse the repository at this point in the history
Discovered while working on another patch, this patch fixes the case
where are construct/directive name isn't provided.
  • Loading branch information
erichkeane committed Nov 17, 2023
1 parent 52df67b commit 6168337
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ def warn_pragma_acc_unimplemented_clause_parsing
InGroup<SourceUsesOpenACC>;
def err_acc_invalid_directive
: Error<"invalid OpenACC directive '%0'">;
def err_acc_missing_directive : Error<"expected OpenACC directive">;

// OpenMP support.
def warn_pragma_omp_ignored : Warning<
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Parse/ParseOpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ OpenACCDirectiveKind GetOpenACCDirectiveKind(StringRef Name) {
// Parse and consume the tokens for OpenACC Directive/Construct kinds.
OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
Token FirstTok = P.getCurToken();

// Just #pragma acc can get us immediately to the end, make sure we don't
// introspect on the spelling before then.
if (FirstTok.isAnnotation()) {
P.Diag(FirstTok, diag::err_acc_missing_directive);
return OpenACCDirectiveKind::Invalid;
}

P.ConsumeToken();
std::string FirstTokSpelling = P.getPreprocessor().getSpelling(FirstTok);

Expand Down
6 changes: 6 additions & 0 deletions clang/test/ParserOpenACC/parse-constructs.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// RUN: %clang_cc1 %s -verify -fopenacc

void func() {

// expected-error@+2{{expected OpenACC directive}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc
for(;;){}

// expected-error@+2{{invalid OpenACC directive 'invalid'}}
// expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}}
#pragma acc invalid
Expand Down

0 comments on commit 6168337

Please sign in to comment.