r357162 - [PR41247] Fixed parsing of private keyword in C++.

Anastasia Stulova via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 28 04:47:14 PDT 2019


Author: stulova
Date: Thu Mar 28 04:47:14 2019
New Revision: 357162

URL: http://llvm.org/viewvc/llvm-project?rev=357162&view=rev
Log:
[PR41247] Fixed parsing of private keyword in C++.

Fixed bug in C++ to prevent parsing 'private' as a
valid address space qualifier.

Differential Revision: https://reviews.llvm.org/D59874


Added:
    cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseTentative.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=357162&r1=357161&r2=357162&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Mar 28 04:47:14 2019
@@ -4791,7 +4791,6 @@ bool Parser::isTypeSpecifierQualifier()
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4800,9 +4799,11 @@ bool Parser::isTypeSpecifierQualifier()
   case tok::kw___read_only:
   case tok::kw___read_write:
   case tok::kw___write_only:
-
     return true;
 
+  case tok::kw_private:
+    return getLangOpts().OpenCL;
+
   // C11 _Atomic
   case tok::kw__Atomic:
     return true;
@@ -4982,7 +4983,6 @@ bool Parser::isDeclarationSpecifier(bool
 
   case tok::kw___kindof:
 
-  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4995,6 +4995,9 @@ bool Parser::isDeclarationSpecifier(bool
 #include "clang/Basic/OpenCLImageTypes.def"
 
     return true;
+
+  case tok::kw_private:
+    return getLangOpts().OpenCL;
   }
 }
 
@@ -5196,6 +5199,9 @@ void Parser::ParseTypeQualifierListOpt(
 
     // OpenCL qualifiers:
     case tok::kw_private:
+      if (!getLangOpts().OpenCL)
+        goto DoneWithTypeQuals;
+      LLVM_FALLTHROUGH;
     case tok::kw___private:
     case tok::kw___global:
     case tok::kw___local:

Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=357162&r1=357161&r2=357162&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Thu Mar 28 04:47:14 2019
@@ -1414,8 +1414,13 @@ Parser::isCXXDeclarationSpecifier(Parser
     // cv-qualifier
   case tok::kw_const:
   case tok::kw_volatile:
+    return TPResult::True;
+
     // OpenCL address space qualifiers
   case tok::kw_private:
+    if (!getLangOpts().OpenCL)
+      return TPResult::False;
+    LLVM_FALLTHROUGH;
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:

Added: cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp?rev=357162&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp (added)
+++ cfe/trunk/test/SemaOpenCLCXX/private-access-specifier.cpp Thu Mar 28 04:47:14 2019
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
+
+// Test that 'private' is not parsed as an address space qualifier
+// in regular C++ mode.
+
+struct B {
+  virtual ~B() // expected-error{{expected ';' at end of declaration list}}
+private:
+   void foo();
+   private int* i; // expected-error{{expected ':'}}
+};
+
+void bar(private int*); //expected-error{{variable has incomplete type 'void'}} expected-error{{expected expression}}




More information about the cfe-commits mailing list