Index: include/clang/Basic/TokenKinds.def =================================================================== --- include/clang/Basic/TokenKinds.def +++ include/clang/Basic/TokenKinds.def @@ -568,7 +568,7 @@ // OpenMP Type Traits KEYWORD(__builtin_omp_required_simd_align, KEYALL) -KEYWORD(pipe , KEYOPENCLC) +KEYWORD(pipe , KEYOPENCLC | KEYOPENCLCXX) // Borland Extensions. KEYWORD(__pascal , KEYALL) Index: lib/Basic/Builtins.cpp =================================================================== --- lib/Basic/Builtins.cpp +++ lib/Basic/Builtins.cpp @@ -70,8 +70,9 @@ 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; Index: lib/Parse/ParseDecl.cpp =================================================================== --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -2560,6 +2560,11 @@ 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 @@ 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 @@ 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 @@ 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) Index: lib/Parse/ParseTentative.cpp =================================================================== --- lib/Parse/ParseTentative.cpp +++ lib/Parse/ParseTentative.cpp @@ -1437,6 +1437,8 @@ 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: Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -9288,7 +9288,7 @@ // 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()) { QualType ElemTy = PipeTy->getElementType(); if (ElemTy->isReferenceType() || ElemTy->isPointerType()) { Index: lib/Sema/SemaType.cpp =================================================================== --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -1356,7 +1356,7 @@ // "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 @@ // 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); Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl =================================================================== --- test/SemaOpenCL/invalid-pipes-cl2.0.cl +++ test/SemaOpenCL/invalid-pipes-cl2.0.cl @@ -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 @@ } // 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 @@ { return y; } +#endif