[clang] fd8d915 - Fix parser bug that permitted 'private' as a (no-op) decl-specifier even outside OpenCL.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 12:00:16 PST 2019


Author: Richard Smith
Date: 2019-11-20T11:59:58-08:00
New Revision: fd8d9155a997ab0f3ef3d7dff1c56efc9b692bfe

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

LOG: Fix parser bug that permitted 'private' as a (no-op) decl-specifier even outside OpenCL.

Added: 
    

Modified: 
    clang/lib/Parse/ParseDecl.cpp
    clang/test/Parser/cxx-decl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index e5c17a3131ab..a90147ca4692 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3949,9 +3949,14 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
         PrevSpec = Tok.getIdentifierInfo()->getNameStart();
         isInvalid = true;
         break;
-      };
+      }
       LLVM_FALLTHROUGH;
     case tok::kw_private:
+      // It's fine (but redundant) to check this for __generic on the
+      // fallthrough path; we only form the __generic token in OpenCL mode.
+      if (!getLangOpts().OpenCL)
+        goto DoneWithDeclSpec;
+      LLVM_FALLTHROUGH;
     case tok::kw___private:
     case tok::kw___global:
     case tok::kw___local:

diff  --git a/clang/test/Parser/cxx-decl.cpp b/clang/test/Parser/cxx-decl.cpp
index c60e42f28eef..a868904bb36d 100644
--- a/clang/test/Parser/cxx-decl.cpp
+++ b/clang/test/Parser/cxx-decl.cpp
@@ -6,6 +6,8 @@ const char const *x10; // expected-error {{duplicate 'const' declaration specifi
 
 int x(*g); // expected-error {{use of undeclared identifier 'g'}}
 
+private int cplusplus_is_not_opencl; // expected-error {{expected unqualified-id}}
+
 struct Type {
   int Type;
 };


        


More information about the cfe-commits mailing list