[clang] 731361c - [OpenACC] Fix bug with directive name being a 'special token'

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 8 09:32:54 PST 2023


Author: erichkeane
Date: 2023-12-08T09:32:49-08:00
New Revision: 731361cd1540d0e729633833e6f3a670443c4b84

URL: https://github.com/llvm/llvm-project/commit/731361cd1540d0e729633833e6f3a670443c4b84
DIFF: https://github.com/llvm/llvm-project/commit/731361cd1540d0e729633833e6f3a670443c4b84.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Parse/ParseOpenACC.cpp
    clang/test/ParserOpenACC/parse-constructs.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index 83a91d44f73fa..f7f096762e91a 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 b745f54bd715c..83d9bd6070d41 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 at +4{{expected OpenACC directive}}
+  // expected-error at +3{{expected clause-list or newline in OpenACC directive}}
+  // expected-warning at +2{{OpenACC clause parsing not yet implemented}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc(whatever) routine
+
+  // expected-error at +3{{expected OpenACC directive}}
+  // expected-warning at +2{{OpenACC clause parsing not yet implemented}}
+  // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
+#pragma acc) routine
+
   // expected-error at +2{{invalid OpenACC directive 'invalid'}}
   // expected-warning at +1{{OpenACC directives not yet implemented, pragma ignored}}
 #pragma acc invalid


        


More information about the cfe-commits mailing list