Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -7703,6 +7703,10 @@ "array of block type is invalid in OpenCL">; def err_opencl_ternary_with_block : Error< "block type cannot be used as expression in ternary expression in OpenCL">; +def err_opencl_pointer_to_type : Error< + "pointer to type %0 is invalid in OpenCL">; +def err_opencl_type_can_only_be_used_as_function_parameter : Error < + "type %0 can only be used as a function parameter in OpenCL">; // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions def err_opencl_builtin_pipe_first_arg : Error< Index: lib/Sema/SemaDecl.cpp =================================================================== --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5710,6 +5710,17 @@ QualType R = TInfo->getType(); DeclarationName Name = GetNameForDeclarator(D).getName(); + // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument. + // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function + // argument. + if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) { + Diag(D.getIdentifierLoc(), + diag::err_opencl_type_can_only_be_used_as_function_parameter) + << R; + D.setInvalidType(); + return nullptr; + } + DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec(); StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec()); @@ -10737,7 +10748,17 @@ Diag(NameLoc, diag::err_arg_with_address_space); New->setInvalidDecl(); } - } + } + + // OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used. + // OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used. + if (getLangOpts().OpenCL && T->isPointerType()) { + const QualType PTy = T->getPointeeType(); + if (PTy->isImageType() || PTy->isSamplerT() || PTy->isPipeType()) { + Diag(NameLoc, diag::err_opencl_pointer_to_type) << PTy; + New->setInvalidDecl(); + } + } return New; } Index: test/CodeGenOpenCL/opencl_types.cl =================================================================== --- test/CodeGenOpenCL/opencl_types.cl +++ test/CodeGenOpenCL/opencl_types.cl @@ -36,5 +36,5 @@ // CHECK: call {{.*}}void @fnc4smp(i32 } -void __attribute__((overloadable)) bad1(image1d_t *b, image2d_t *c, image2d_t *d) {} -// CHECK-LABEL: @{{_Z4bad1P11ocl_image1dP11ocl_image2dS2_|"\\01\?bad1@@\$\$J0YAXPE?APAUocl_image1d@@PE?APAUocl_image2d@@1@Z"}} +void __attribute__((overloadable)) bad1(image1d_t b, image2d_t c, image2d_t d) {} +// CHECK-LABEL: @{{_Z4bad111ocl_image1d11ocl_image2dS0_|"\\01\?bad1@@\$\$J0YAXPAUocl_image1d@@PAUocl_image2d@@1@Z"}} Index: test/SemaOpenCL/invalid-image.cl =================================================================== --- /dev/null +++ test/SemaOpenCL/invalid-image.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -verify %s + +void test1(image1d_t *i){} // expected-error {{pointer to type 'image1d_t' is invalid in OpenCL}} + +void test2() { + image1d_t i; // expected-error {{type 'image1d_t' can only be used as a function parameter}} +} Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl =================================================================== --- test/SemaOpenCL/invalid-pipes-cl2.0.cl +++ test/SemaOpenCL/invalid-pipes-cl2.0.cl @@ -6,3 +6,6 @@ } void test3(int pipe p){// expected-error {{cannot combine with previous 'int' declaration specifier}} } +void test4() { + pipe int p; // expected-error {{type 'pipe' can only be used as a function parameter}} +}