r261818 - [OpenCL] Add Sema checks for types
Xiuli Pan via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 24 19:34:20 PST 2016
Author: pxl
Date: Wed Feb 24 21:34:20 2016
New Revision: 261818
URL: http://llvm.org/viewvc/llvm-project?rev=261818&view=rev
Log:
[OpenCL] Add Sema checks for types
Summary:
Add Sema checks for opencl type: image, pipe....
This patch is partitioned from http://reviews.llvm.org/D16047
Reviewers: Anastasia, yaxunl
Subscribers: pekka.jaaskelainen, cfe-commits
Differential Revision: http://reviews.llvm.org/D17437
Added:
cfe/trunk/test/SemaOpenCL/invalid-image.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
cfe/trunk/test/SemaOpenCL/sampler_t.cl
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=261818&r1=261817&r2=261818&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Feb 24 21:34:20 2016
@@ -7720,6 +7720,10 @@ def err_opencl_invalid_type_array : Erro
"array of %0 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<
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=261818&r1=261817&r2=261818&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Feb 24 21:34:20 2016
@@ -5710,6 +5710,17 @@ Sema::ActOnVariableDeclarator(Scope *S,
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 @@ ParmVarDecl *Sema::CheckParameter(DeclCo
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;
}
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=261818&r1=261817&r2=261818&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Feb 24 21:34:20 2016
@@ -2176,9 +2176,12 @@ QualType Sema::BuildArrayType(QualType T
}
// OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
+ // OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
+ // OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
if (getLangOpts().OpenCL) {
const QualType ArrType = Context.getBaseElementType(T);
- if (ArrType->isBlockPointerType()) {
+ if (ArrType->isBlockPointerType() || ArrType->isPipeType() ||
+ ArrType->isSamplerT() || ArrType->isImageType()) {
Diag(Loc, diag::err_opencl_invalid_type_array) << ArrType;
return QualType();
}
Modified: cfe/trunk/test/CodeGenOpenCL/opencl_types.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/opencl_types.cl?rev=261818&r1=261817&r2=261818&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/opencl_types.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/opencl_types.cl Wed Feb 24 21:34:20 2016
@@ -36,5 +36,5 @@ kernel void foo(image1d_t img) {
// 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 at 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 at Z"}}
Added: cfe/trunk/test/SemaOpenCL/invalid-image.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-image.cl?rev=261818&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-image.cl (added)
+++ cfe/trunk/test/SemaOpenCL/invalid-image.cl Wed Feb 24 21:34:20 2016
@@ -0,0 +1,8 @@
+// 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) {
+ image1d_t ti; // expected-error {{type 'image1d_t' can only be used as a function parameter}}
+ image1d_t ai[] = {i,i};// expected-error {{array of 'image1d_t' type is invalid in OpenCL}}
+}
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=261818&r1=261817&r2=261818&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl Wed Feb 24 21:34:20 2016
@@ -6,3 +6,6 @@ void test2(pipe p){// expected-error {{m
}
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}}
+}
Modified: cfe/trunk/test/SemaOpenCL/sampler_t.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/sampler_t.cl?rev=261818&r1=261817&r2=261818&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/sampler_t.cl (original)
+++ cfe/trunk/test/SemaOpenCL/sampler_t.cl Wed Feb 24 21:34:20 2016
@@ -10,4 +10,7 @@ void kernel ker(sampler_t argsmp) {
foo(glb_smp);
foo(const_smp);
foo(5); // expected-error {{sampler_t variable required - got 'int'}}
+ sampler_t sa[] = {argsmp, const_smp}; // expected-error {{array of 'sampler_t' type is invalid in OpenCL}}
}
+
+void bad(sampler_t*); // expected-error {{pointer to type 'sampler_t' is invalid in OpenCL}}
More information about the cfe-commits
mailing list