[PATCH] D59874: [PR41247] Fixed parsing of private keyword in C++
Anastasia Stulova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 06:01:05 PDT 2019
Anastasia created this revision.
Anastasia added reviewers: rjmccall, jsji.
Herald added a subscriber: ebevhan.
In C++ `private` shouldn't be parsed as a valid address space keyword.
This only fixes C++ part, in OpenCL we should still prevent ICE on the reported code example, but I will fix it separately.
@jsji thanks for filing the bug!
https://reviews.llvm.org/D59874
Files:
lib/Parse/ParseDecl.cpp
lib/Parse/ParseTentative.cpp
test/SemaOpenCLCXX/private-access-specifier.cpp
Index: test/SemaOpenCLCXX/private-access-specifier.cpp
===================================================================
--- /dev/null
+++ test/SemaOpenCLCXX/private-access-specifier.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -pedantic -verify -fsyntax-only
+
+struct B {
+ virtual ~B() // expected-error{{expected ';' at end of declaration list}}
+private:
+ void foo();
+};
Index: lib/Parse/ParseTentative.cpp
===================================================================
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1410,8 +1410,13 @@
// 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:
Index: lib/Parse/ParseDecl.cpp
===================================================================
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -4791,7 +4791,6 @@
case tok::kw___kindof:
- case tok::kw_private:
case tok::kw___private:
case tok::kw___local:
case tok::kw___global:
@@ -4800,9 +4799,11 @@
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 @@
case tok::kw___kindof:
- case tok::kw_private:
case tok::kw___private:
case tok::kw___local:
case tok::kw___global:
@@ -4995,6 +4995,9 @@
#include "clang/Basic/OpenCLImageTypes.def"
return true;
+
+ case tok::kw_private:
+ return getLangOpts().OpenCL;
}
}
@@ -5196,6 +5199,9 @@
// 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:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59874.192429.patch
Type: text/x-patch
Size: 2047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190327/cb6d21bd/attachment.bin>
More information about the cfe-commits
mailing list