r361382 - [OpenCL] Support pipe keyword in C++ mode
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Wed May 22 06:12:20 PDT 2019
Author: svenvh
Date: Wed May 22 06:12:20 2019
New Revision: 361382
URL: http://llvm.org/viewvc/llvm-project?rev=361382&view=rev
Log:
[OpenCL] Support pipe keyword in C++ mode
Support the OpenCL C pipe feature in C++ for OpenCL mode, to preserve
backwards compatibility with OpenCL C.
Various changes had to be made in Parse and Sema to enable
pipe-specific diagnostics, so enable a SemaOpenCL test for C++.
Differential Revision: https://reviews.llvm.org/D62181
Modified:
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/lib/Basic/Builtins.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Wed May 22 06:12:20 2019
@@ -568,7 +568,7 @@ KEYWORD(vec_step , KE
// OpenMP Type Traits
KEYWORD(__builtin_omp_required_simd_align, KEYALL)
-KEYWORD(pipe , KEYOPENCLC)
+KEYWORD(pipe , KEYOPENCLC | KEYOPENCLCXX)
// Borland Extensions.
KEYWORD(__pascal , KEYALL)
Modified: cfe/trunk/lib/Basic/Builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Builtins.cpp (original)
+++ cfe/trunk/lib/Basic/Builtins.cpp Wed May 22 06:12:20 2019
@@ -70,8 +70,9 @@ bool Builtin::Context::builtinIsSupporte
bool ObjCUnsupported = !LangOpts.ObjC && BuiltinInfo.Langs == OBJC_LANG;
bool OclC1Unsupported = (LangOpts.OpenCLVersion / 100) != 1 &&
(BuiltinInfo.Langs & ALL_OCLC_LANGUAGES ) == OCLC1X_LANG;
- bool OclC2Unsupported = LangOpts.OpenCLVersion != 200 &&
- (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG;
+ bool OclC2Unsupported =
+ (LangOpts.OpenCLVersion != 200 && !LangOpts.OpenCLCPlusPlus) &&
+ (BuiltinInfo.Langs & ALL_OCLC_LANGUAGES) == OCLC20_LANG;
bool OclCUnsupported = !LangOpts.OpenCL &&
(BuiltinInfo.Langs & ALL_OCLC_LANGUAGES);
bool OpenMPUnsupported = !LangOpts.OpenMP && BuiltinInfo.Langs == OMP_LANG;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed May 22 06:12:20 2019
@@ -2560,6 +2560,11 @@ bool Parser::ParseImplicitInt(DeclSpec &
return false;
}
+ // Early exit as Sema has a dedicated missing_actual_pipe_type diagnostic
+ // for incomplete declarations such as `pipe p`.
+ if (getLangOpts().OpenCLCPlusPlus && DS.isTypeSpecPipe())
+ return false;
+
if (getLangOpts().CPlusPlus &&
DS.getStorageClassSpec() == DeclSpec::SCS_auto) {
// Don't require a type specifier if we have the 'auto' storage class
@@ -3769,7 +3774,8 @@ void Parser::ParseDeclarationSpecifiers(
isInvalid = DS.SetTypeAltiVecBool(true, Loc, PrevSpec, DiagID, Policy);
break;
case tok::kw_pipe:
- if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200)) {
+ if (!getLangOpts().OpenCL || (getLangOpts().OpenCLVersion < 200 &&
+ !getLangOpts().OpenCLCPlusPlus)) {
// OpenCL 2.0 defined this keyword. OpenCL 1.2 and earlier should
// support the "pipe" word as identifier.
Tok.getIdentifierInfo()->revertTokenIDToIdentifier();
@@ -4896,7 +4902,8 @@ bool Parser::isDeclarationSpecifier(bool
default: return false;
case tok::kw_pipe:
- return getLangOpts().OpenCL && (getLangOpts().OpenCLVersion >= 200);
+ return (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) ||
+ getLangOpts().OpenCLCPlusPlus;
case tok::identifier: // foo::bar
// Unfortunate hack to support "Class.factoryMethod" notation.
@@ -5384,7 +5391,8 @@ static bool isPtrOperatorToken(tok::Toke
if (Kind == tok::star || Kind == tok::caret)
return true;
- if ((Kind == tok::kw_pipe) && Lang.OpenCL && (Lang.OpenCLVersion >= 200))
+ if (Kind == tok::kw_pipe &&
+ ((Lang.OpenCL && Lang.OpenCLVersion >= 200) || Lang.OpenCLCPlusPlus))
return true;
if (!Lang.CPlusPlus)
Modified: cfe/trunk/lib/Parse/ParseTentative.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseTentative.cpp?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseTentative.cpp (original)
+++ cfe/trunk/lib/Parse/ParseTentative.cpp Wed May 22 06:12:20 2019
@@ -1461,6 +1461,8 @@ Parser::isCXXDeclarationSpecifier(Parser
case tok::kw___read_only:
case tok::kw___write_only:
case tok::kw___read_write:
+ // OpenCL pipe
+ case tok::kw_pipe:
// GNU
case tok::kw_restrict:
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed May 22 06:12:20 2019
@@ -9288,7 +9288,7 @@ Sema::ActOnFunctionDeclarator(Scope *S,
// OpenCL 2.0 pipe restrictions forbids pipe packet types to be non-value
// types.
- if (getLangOpts().OpenCLVersion >= 200) {
+ if (getLangOpts().OpenCLVersion >= 200 || getLangOpts().OpenCLCPlusPlus) {
if(const PipeType *PipeTy = PT->getAs<PipeType>()) {
QualType ElemTy = PipeTy->getElementType();
if (ElemTy->isReferenceType() || ElemTy->isPointerType()) {
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed May 22 06:12:20 2019
@@ -1356,7 +1356,7 @@ static QualType ConvertDeclSpecToType(Ty
// "At least one type specifier shall be given in the declaration
// specifiers in each declaration, and in the specifier-qualifier list in
// each struct declaration and type name."
- if (S.getLangOpts().CPlusPlus) {
+ if (S.getLangOpts().CPlusPlus && !DS.isTypeSpecPipe()) {
S.Diag(DeclLoc, diag::err_missing_type_specifier)
<< DS.getSourceRange();
@@ -1364,7 +1364,9 @@ static QualType ConvertDeclSpecToType(Ty
// value being declared, poison it as invalid so we don't get chains of
// errors.
declarator.setInvalidType(true);
- } else if (S.getLangOpts().OpenCLVersion >= 200 && DS.isTypeSpecPipe()){
+ } else if ((S.getLangOpts().OpenCLVersion >= 200 ||
+ S.getLangOpts().OpenCLCPlusPlus) &&
+ DS.isTypeSpecPipe()) {
S.Diag(DeclLoc, diag::err_missing_actual_pipe_type)
<< DS.getSourceRange();
declarator.setInvalidType(true);
Modified: cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl?rev=361382&r1=361381&r2=361382&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl Wed May 22 06:12:20 2019
@@ -1,9 +1,10 @@
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=c++
global pipe int gp; // expected-error {{type '__global read_only pipe int' can only be used as a function parameter in OpenCL}}
global reserve_id_t rid; // expected-error {{the '__global reserve_id_t' type cannot be used to declare a program scope variable}}
-extern pipe write_only int get_pipe(); // expected-error {{type '__global write_only pipe int (void)' can only be used as a function parameter in OpenCL}}
+extern pipe write_only int get_pipe(); // expected-error-re{{type '__global write_only pipe int ({{(void)?}})' can only be used as a function parameter in OpenCL}}
kernel void test_invalid_reserved_id(reserve_id_t ID) { // expected-error {{'reserve_id_t' cannot be used as the type of a kernel parameter}}
}
@@ -35,6 +36,7 @@ bool test_id_comprision(void) {
}
// Tests ASTContext::mergeTypes rejects this.
+#ifndef __OPENCL_CPP_VERSION__
int f(pipe int x, int y); // expected-note {{previous declaration is here}}
int f(x, y) // expected-error {{conflicting types for 'f}}
pipe short x;
@@ -42,3 +44,4 @@ int y;
{
return y;
}
+#endif
More information about the cfe-commits
mailing list