From 731361cd1540d0e729633833e6f3a670443c4b84 Mon Sep 17 00:00:00 2001 From: erichkeane Date: Fri, 8 Dec 2023 09:32:01 -0800 Subject: [OpenACC] Fix bug with directive name being a 'special token' If the 'directive name' is a special token instead of an identifier, we end up asserting. This fixes that. --- clang/lib/Parse/ParseOpenACC.cpp | 9 +++------ clang/test/ParserOpenACC/parse-constructs.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp index 83a91d44f..f7f0967 100644 --- a/clang/lib/Parse/ParseOpenACC.cpp +++ b/clang/lib/Parse/ParseOpenACC.cpp @@ -206,7 +206,7 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) { // Just #pragma acc can get us immediately to the end, make sure we don't // introspect on the spelling before then. - if (FirstTok.isAnnotation()) { + if (FirstTok.isNot(tok::identifier)) { P.Diag(FirstTok, diag::err_acc_missing_directive); return OpenACCDirectiveKind::Invalid; } @@ -224,11 +224,8 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) { if (ExDirKind >= OpenACCDirectiveKindEx::Invalid) { switch (ExDirKind) { case OpenACCDirectiveKindEx::Invalid: { - if (!FirstTok.is(tok::identifier)) - P.Diag(FirstTok, diag::err_expected) << tok::identifier; - else - P.Diag(FirstTok, diag::err_acc_invalid_directive) - << 0 << FirstTok.getIdentifierInfo(); + P.Diag(FirstTok, diag::err_acc_invalid_directive) + << 0 << FirstTok.getIdentifierInfo(); return OpenACCDirectiveKind::Invalid; } case OpenACCDirectiveKindEx::Enter: diff --git a/clang/test/ParserOpenACC/parse-constructs.c b/clang/test/ParserOpenACC/parse-constructs.c index b745f54..83d9bd6 100644 --- a/clang/test/ParserOpenACC/parse-constructs.c +++ b/clang/test/ParserOpenACC/parse-constructs.c @@ -7,6 +7,17 @@ void func() { #pragma acc for(;;){} + // expected-error@+4{{expected OpenACC directive}} + // expected-error@+3{{expected clause-list or newline in OpenACC directive}} + // expected-warning@+2{{OpenACC clause parsing not yet implemented}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc(whatever) routine + + // expected-error@+3{{expected OpenACC directive}} + // expected-warning@+2{{OpenACC clause parsing not yet implemented}} + // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} +#pragma acc) routine + // expected-error@+2{{invalid OpenACC directive 'invalid'}} // expected-warning@+1{{OpenACC directives not yet implemented, pragma ignored}} #pragma acc invalid -- cgit v1.1