Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
pxli168 updated this revision to Diff 47074. pxli168 updated the summary for this revision. pxli168 added a comment. Rebase for partition http://reviews.llvm.org/D16047 Files: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/opencl_types.cl test/Parser/opencl-atomics-cl20.cl test/SemaOpenCL/invalid-block.cl test/SemaOpenCL/invalid-decl.cl test/SemaOpenCL/invalid-image.cl test/SemaOpenCL/invalid-pipes-cl2.0.cl 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 {{pipe can only be used as a function parameter}} +} 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 image is invalid in OpenCL}} + +void test2() { + image1d_t i; // expected-error {{image can only be used as a function parameter}} +} Index: test/SemaOpenCL/invalid-decl.cl === --- /dev/null +++ test/SemaOpenCL/invalid-decl.cl @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -verify -cl-std=CL2.0 %s +int; // expected-error {{declaration does not declare anything}} + +void test1(){ + myfun(); // expected-error {{implicit declaration of function 'myfun' is invalid in OpenCL}} +} Index: test/SemaOpenCL/invalid-block.cl === --- /dev/null +++ test/SemaOpenCL/invalid-block.cl @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s + +int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed}} + return 0; +}; + +typedef int (^BlkInt)(int); +void f1(int i) { + BlkInt B1 = ^int(int I) {return 1;}; + BlkInt B2 = ^int(int I) {return 2;}; + BlkInt Arr[] = {B1, B2}; // expected-error {{array of block is invalid in OpenCL}} + int tmp = i ? B1(i) // expected-error {{blocks cannot be used as expressions in ternary expressions}} + : B2(i); // expected-error {{blocks cannot be used as expressions in ternary expressions}} +} + +void f2(BlkInt *BlockPtr) { + BlkInt B = ^int(int I) {return 1;}; + BlkInt *P = // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}} + B = *BlockPtr; // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed}} +} + Index: test/Parser/opencl-atomics-cl20.cl === --- test/Parser/opencl-atomics-cl20.cl +++ test/Parser/opencl-atomics-cl20.cl @@ -56,6 +56,7 @@ #endif #ifdef CL20 +#define ATOMIC_VAR_INIT void foo(atomic_int * ptr) {} void atomic_ops_test() { atomic_int i; @@ -66,4 +67,7 @@ i += 1; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'int')}} i = i + i; // expected-error {{invalid operands to binary expression ('atomic_int' (aka '_Atomic(int)') and 'atomic_int')}} } +void atomic_init_test() { +atomic_int guide = ATOMIC_VAR_INIT(42); // expected-error {{initialization of atomic variables is restricted to variables in global address space in opencl}} +} #endif Index: test/CodeGenOpenCL/opencl_types.cl === --- test/CodeGenOpenCL/opencl_types.cl +++ test/CodeGenOpenCL/opencl_types.cl @@ -35,6 +35,3 @@ fnc4smp(glb_smp); // 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"}} Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -2175,6 +2175,14 @@ Diag(Loc, diag::warn_vla_used); } + // OpenCL v2.0 s6.12.5 - The following Blocks features are currently not + // supported in OpenCL C: Arrays of Blocks. + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200 && + Context.getBaseElementType(T)->isBlockPointerType()) { +Diag(Loc, diag::err_opencl_invalid_block_array); +return QualType(); + } + return T; } Index: lib/Sema/SemaInit.cpp === --- lib/Sema/SemaInit.cpp +++ lib/Sema/SemaInit.cpp @@ -6135,6 +6135,32 @@ << Init->getSourceRange(); } + // OpenCL v2.0
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
pxli168 marked 6 inline comments as done. pxli168 added a comment. I will separate this patch into small ones. Comment at: lib/Sema/SemaDecl.cpp:5724 @@ +5723,3 @@ + R->isPipeType()) { +Diag(D.getIdentifierLoc(), + diag::err_opencl_type_can_only_be_used_as_function_parameter) Anastasia wrote: > pxli168 wrote: > > Anastasia wrote: > > > Some of them have to be. For example for C types that we use differently > > > in CL. But for CL only types do we need to check additionally that it's > > > CL? Do we not know it already? > > Yes, but it seems all old code write in that way. I just follow the style. > Ok, I think an improvement to the old code is always welcome! OK, I think we can try here to see if it will bring some errors. Comment at: lib/Sema/SemaDecl.cpp:7279 @@ -7228,1 +7278,3 @@ + if (PT->isReserveIDT()) +return InvalidKernelParam; Anastasia wrote: > Is there a test for this? I will add one. http://reviews.llvm.org/D16047 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
Anastasia added a comment. Xiuli, do you still plan to continue here? I was just thinking if it would make sense to re-upload the review since the line numbers got broken due to full diff. Also it would be nice to partition to several independent commits/reviews. Let's say: - Blocks diagnostics - invalid types: images, pipes - Misc: atomics and implicit declaration Or you could split the last one into two as well. What do you think? Comment at: include/clang/Basic/DiagnosticSemaKinds.td:593 @@ -592,2 +592,3 @@ +def err_no_declarators : Error<"declaration does not declare anything">; def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">, InGroup; pxli168 wrote: > Anastasia wrote: > > I just can't understand the intention here. Could you give any code example > > or reference to spec? > I will try, Do you still plan to have it? We can discuss in a separate review if you wish to be able to proceed here. http://reviews.llvm.org/D16047 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
Anastasia added inline comments. Comment at: lib/Sema/SemaDecl.cpp:7255 @@ -7209,3 +7254,3 @@ return PtrPtrKernelParam; -return PointeeType.getAddressSpace() == 0 ? PrivatePtrKernelParam - : PtrKernelParam; +// Now generice address space is added, we need to handle like this +unsigned addrSpace = PointeeType.getAddressSpace(); I think this should be removed? Comment at: lib/Sema/SemaDecl.cpp:7279 @@ -7228,1 +7278,3 @@ + if (PT->isReserveIDT()) +return InvalidKernelParam; Is there a test for this? http://reviews.llvm.org/D16047 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
Anastasia added inline comments. Comment at: include/clang/Basic/DiagnosticSemaKinds.td:593 @@ -592,2 +592,3 @@ +def err_no_declarators : Error<"declaration does not declare anything">; def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">, InGroup; I just can't understand the intention here. Could you give any code example or reference to spec? Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7666 @@ +7665,3 @@ + "dereferencing pointer of type %0 is not allowed in OpenCL">; +def err_opencl_pointer_to_image : Error< + "pointer to image is invalid in OpenCL">; I have a feeling that line numbers are broken now in this review due to patch reupload. Please, see the comment on the line 7670. Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7670 @@ +7669,3 @@ + "%0 can only be used as a function parameter">; +def err_opencl_atomic_init_addressspace : Error< + "initialization of atomic variables is restricted to variables in global address space in opencl">; Could you do something like: def err_atomic_init_constant : Error< "atomic variable can only be %select{assigned|initialised}0 to a compile time constant" " in the declaration statement in the program scope">; Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7673 @@ +7672,3 @@ +def err_opencl_block_proto_variadic : Error< + "invalid block prototype, variadic arguments are not allowed in opencl">; +def err_opencl_invalid_block_array : Error< in OpenCL Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7674 @@ +7673,3 @@ + "invalid block prototype, variadic arguments are not allowed in opencl">; +def err_opencl_invalid_block_array : Error< + "array of block is invalid in OpenCL">; Could we combine err_opencl_invalid_block_array and err_opencl_pointer_to_image saying something like: "Declaring a %select{pointer|array}0 of type %1 is not allowed in OpenCL" Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7675 @@ +7674,3 @@ +def err_opencl_invalid_block_array : Error< + "array of block is invalid in OpenCL">; +def err_opencl_ternary_with_block : Error< array of block type is ... Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7677 @@ +7676,3 @@ +def err_opencl_ternary_with_block : Error< + "blocks cannot be used as expressions in ternary expressions in opencl">; + in OpenCL Comment at: lib/Sema/SemaDecl.cpp:5724 @@ +5723,3 @@ + R->isPipeType()) { +Diag(D.getIdentifierLoc(), + diag::err_opencl_type_can_only_be_used_as_function_parameter) Some of them have to be. For example for C types that we use differently in CL. But for CL only types do we need to check additionally that it's CL? Do we not know it already? Comment at: lib/Sema/SemaExpr.cpp:6251 @@ -6250,1 +6250,3 @@ +/// \brief Return true if the Expr is block type +static bool checkBlockType(Sema , const Expr *E) { a block type Comment at: lib/Sema/SemaExpr.cpp:6299 @@ -6286,3 +6298,3 @@ // Now check the two expressions. if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) I am not sure what the question is? I think using block in a condition should be disallowed. Could you add this to testing as well? Comment at: lib/Sema/SemaExpr.cpp:6316 @@ +6315,3 @@ + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) { +// should output error for both LHS and RHS, use | instead || +if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get())) Could you remove this comment? Comment at: lib/Sema/SemaExpr.cpp:7550 @@ -7527,3 +7549,3 @@ LHSType, RHSVecType->getElementType(), - RHSType)) + RHSType, Loc)) return RHSType; I am not clear about the purpose of this change. Comment at: lib/Sema/SemaExpr.cpp:10061 @@ +10060,3 @@ + // OpenCL v2.0 s6.12.5 - The unary operators (* and &) cannot be used with a + // Block + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) { Block -> block Comment at: lib/Sema/SemaExpr.cpp:10115 @@ +10114,3 @@ +// Block. +if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200 && +Result->isBlockPointerType()) { The code above seems to do similar. Could we combine into one function/diagnostic? Comment at: lib/Sema/SemaInit.cpp:6139 @@ +6138,3 @@ + // OpenCL v2.0 s6.13.11.1 - The ATOMIC_VAR_INIT macro expands to a token + // sequence suitable for initializing an atomic
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
Anastasia added a comment. Also generally it's much nicer to have small logically isolated changes committed. I can see how you could partition this change into into pipe, blocks and images. Comment at: include/clang/Basic/DiagnosticSemaKinds.td:593 @@ -592,2 +592,3 @@ InGroup; +def err_no_declarators : Error<"declaration does not declare anything">; def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">, Can you explain why you are adding this and not relying on standard C behavior? Any reference to spec or complete example would be helpful! Comment at: include/clang/Basic/DiagnosticSemaKinds.td:7666 @@ +7665,3 @@ +def err_opencl_atomic_init_addressspace : Error< + "initialization of atomic variables is restricted to variables in global address space in opencl">; +def err_opencl_block_proto_variadic : Error< I think it's best to merge this with err_atomic_init_constant diagnostic. You can have {assigned|initialize} in the text and pass which value to select in the code handling the error. I would also rename it directly to: err_opencl_atomic_init_constant Comment at: lib/Sema/SemaDecl.cpp:5724 @@ +5723,3 @@ + // Pipes can only be passed as arguments to a function. + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200 && + R->isPipeType()) { is CL check really needed since we are accepting pipes only in CL2.0? Comment at: lib/Sema/SemaDecl.cpp:5735 @@ +5734,3 @@ + + // OpenCL v1.2 s6.5 p5 + // There is no generic address space name for program scope variables. Dead code here? Comment at: lib/Sema/SemaDecl.cpp:6745 @@ +6744,3 @@ +const BlockPointerType *BlkTy = T->getAs(); +assert(BlkTy && "Not a block pointer."); + this seems to be redundant considering the check above. Comment at: lib/Sema/SemaDecl.cpp:6760 @@ +6759,3 @@ +#if 0 + // OpenCL v2.0 s6.9.b + // An image type can only be used as a type of a function argument. Dead code! Comment at: lib/Sema/SemaDecl.cpp:7302 @@ -7209,2 +7302,2 @@ QualType PointeeType = PT->getPointeeType(); if (PointeeType->isPointerType()) I feel like exporting the full diff might be a good idea here. A lot of small framents hard to understand. "To get a full diff, use one of the following commands (or just use Arcanist to upload your patch): git diff -U99 other-branch svn diff --diff-cmd=diff -x -U99" Comment at: lib/Sema/SemaDecl.cpp:7308 @@ +7307,3 @@ +unsigned addrSpace = PointeeType.getAddressSpace(); +return (addrSpace != LangAS::opencl_global && +addrSpace != LangAS::opencl_constant && Why this change? Comment at: lib/Sema/SemaDecl.cpp:11466 @@ +11465,3 @@ + else if (getLangOpts().OpenCL) +// OpenCL spir-function need to be called with prototype, so we don't allow +// implicit function declarations in OpenCL Can you remove "spir-" from here? Comment at: lib/Sema/SemaExpr.cpp:6299 @@ +6298,3 @@ +if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get())) + return QualType(); + } Can we produce the diagnostic here and let checkBlockType only return true or false? Comment at: lib/Sema/SemaExpr.cpp:10094 @@ -10060,1 +10093,3 @@ Result = PT->getPointeeType(); +// OpenCL v2.0 s6.12.5 --The unary operators (* and &) cannot be used with a +// Block. Remove one -, add space after Comment at: lib/Sema/SemaInit.cpp:6138 @@ -6137,1 +6137,3 @@ + // OpenCL v2.0 s6.13.1.1 -- This macro can only be used to initialize atomic + // objects that are declared in program scope in the global address space. I guess you mean s6.13.11.1? Comment at: lib/Sema/SemaInit.cpp:6139 @@ +6138,3 @@ + // OpenCL v2.0 s6.13.1.1 -- This macro can only be used to initialize atomic + // objects that are declared in program scope in the global address space. + if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200 && Not clear about the macro. Could you be more generic here i.e. write about initialization is generally disallowed. Comment at: lib/Sema/SemaInit.cpp:6143 @@ +6142,3 @@ +Qualifiers TyQualifiers = Entity.getType().getQualifiers(); +bool HasGlobalAS = TyQualifiers.hasAddressSpace() && + TyQualifiers.getAddressSpace() == LangAS::opencl_global; It would be sufficient to check: TyQualifiers.getAddressSpace() == LangAS::opencl_global Comment at: lib/Sema/SemaInit.cpp:6145 @@ +6144,3 @@ + TyQualifiers.getAddressSpace() == LangAS::opencl_global; +if (!HasGlobalAS &&
[PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
pxli168 created this revision. pxli168 added reviewers: Anastasia, pekka.jaaskelainen. pxli168 added subscribers: bader, cfe-commits. Add Sema checks for opencl 2.0 new features: Block, pipe, atomic etc. Also fix some old Sema check like pointer to image. This patch is based on bader's patch in SPIRV-1.0 branch. http://reviews.llvm.org/D16047 Files: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/opencl_types.cl test/SemaOpenCL/invalid-block.cl test/SemaOpenCL/invalid-decl.cl Index: test/SemaOpenCL/invalid-decl.cl === --- /dev/null +++ test/SemaOpenCL/invalid-decl.cl @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -verify -cl-std=CL2.0 %s +typedef __attribute__(( ext_vector_type(4) )) int int4; +#define ATOMIC_VAR_INIT +int; // expected-error {{declaration does not declare anything}} + +void test1(){ + myfun(); // expected-error {{implicit declaration of function 'myfun' is invalid in OpenCL}} +} + +void test2(image1d_t *i){} // expected-error {{pointer to image is invalid in OpenCL}} + +void test3() { + pipe int p; // expected-error {{pipe can only be used as a function parameter}} + image1d_t i; // expected-error {{image can only be used as a function parameter}} +} + +void kernel test4() { + atomic_int guide = ATOMIC_VAR_INIT(42); // expected-error {{initialization of atomic variables is restricted to variables in global address space in opencl}} +} Index: test/SemaOpenCL/invalid-block.cl === --- /dev/null +++ test/SemaOpenCL/invalid-block.cl @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s + +int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed}} + return 0; +}; + +typedef int (^BlkInt)(int); +void f1(int i) { + BlkInt B1 = ^int(int I) {return 1;}; + BlkInt B2 = ^int(int I) {return 2;}; + BlkInt Arr[] = {B1, B2}; // expected-error {{array of block is invalid in OpenCL}} + int tmp = i ? B1(i) // expected-error {{blocks cannot be used as expressions in ternary expressions}} + : B2(i); // expected-error {{blocks cannot be used as expressions in ternary expressions}} +} + +void f2(BlkInt *BlockPtr) { + BlkInt B = ^int(int I) {return 1;}; + BlkInt *P = // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}} + B = *BlockPtr; // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed}} +} + Index: test/CodeGenOpenCL/opencl_types.cl === --- test/CodeGenOpenCL/opencl_types.cl +++ test/CodeGenOpenCL/opencl_types.cl @@ -35,6 +35,3 @@ fnc4smp(glb_smp); // 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"}} Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -2176,6 +2176,14 @@ Diag(Loc, diag::warn_vla_used); } + // OpenCL v2.0 s6.12.5 -- The following Blocks features are currently not + // supported in OpenCL C: Arrays of Blocks. + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200 && + Context.getBaseElementType(T)->isBlockPointerType()) { +Diag(Loc, diag::err_opencl_invalid_block_array); +return QualType(); + } + return T; } Index: lib/Sema/SemaInit.cpp === --- lib/Sema/SemaInit.cpp +++ lib/Sema/SemaInit.cpp @@ -6135,6 +6135,22 @@ << Init->getSourceRange(); } + // OpenCL v2.0 s6.13.1.1 -- This macro can only be used to initialize atomic + // objects that are declared in program scope in the global address space. + if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200 && + Entity.getType()->isAtomicType()) { +Qualifiers TyQualifiers = Entity.getType().getQualifiers(); +bool HasGlobalAS = TyQualifiers.hasAddressSpace() && + TyQualifiers.getAddressSpace() == LangAS::opencl_global; +if (!HasGlobalAS && Entity.getKind() == InitializedEntity::EK_Variable && +Args.size() > 0) { + const Expr *Init = Args[0]; + S.Diag(Init->getLocStart(), diag::err_opencl_atomic_init_addressspace) + << SourceRange(Entity.getDecl()->getLocStart(), Init->getLocEnd()); + return ExprError(); +} + } + // Diagnose cases where we initialize a pointer to an array temporary, and the // pointer obviously outlives the temporary. if (Args.size() == 1 && Args[0]->getType()->isArrayType() && Index:
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
pxli168 added inline comments. Comment at: lib/Sema/SemaDecl.cpp:5733 @@ +5732,3 @@ + +#if 0 + pekka.jaaskelainen wrote: > Is this intentionally included in the patch? My mistake, just want to check if this works. But find it is handled by something else. Comment at: lib/Sema/SemaDecl.cpp:6759 @@ +6758,3 @@ + +#if 0 + // OpenCL v2.0 s6.9.b pekka.jaaskelainen wrote: > Ditto. Better not commit disabled code in the repository. Removed Comment at: lib/Sema/SemaExpr.cpp:6295 @@ +6294,3 @@ + // OpenCL v2.0 s6.12.5 -- To support these behaviors, additional + // restrictions28 in addition to the above feature restrictions are: Blocks + // cannot be used as expressions of the ternary selection operator (?:). pekka.jaaskelainen wrote: > -28 Fixed Comment at: lib/Sema/SemaExpr.cpp:6298 @@ +6297,3 @@ + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200) { +if (checkBlockType(*this, LHS.get()) | checkBlockType(*this, RHS.get())) + return QualType(); pekka.jaaskelainen wrote: > || Intend to do this in order to get both err diag for both LHS and RHS. http://reviews.llvm.org/D16047 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D16047: [OpenCL] Add Sema checks for OpenCL 2.0
pxli168 updated this revision to Diff 44599. pxli168 added a comment. Remove some unused codes and add inline comment. http://reviews.llvm.org/D16047 Files: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaType.cpp test/CodeGenOpenCL/opencl_types.cl test/SemaOpenCL/invalid-block.cl test/SemaOpenCL/invalid-decl.cl Index: test/SemaOpenCL/invalid-decl.cl === --- /dev/null +++ test/SemaOpenCL/invalid-decl.cl @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -verify -cl-std=CL2.0 %s +typedef __attribute__(( ext_vector_type(4) )) int int4; +#define ATOMIC_VAR_INIT +int; // expected-error {{declaration does not declare anything}} + +void test1(){ + myfun(); // expected-error {{implicit declaration of function 'myfun' is invalid in OpenCL}} +} + +void test2(image1d_t *i){} // expected-error {{pointer to image is invalid in OpenCL}} + +void test3() { + pipe int p; // expected-error {{pipe can only be used as a function parameter}} + image1d_t i; // expected-error {{image can only be used as a function parameter}} +} + +void kernel test4() { + atomic_int guide = ATOMIC_VAR_INIT(42); // expected-error {{initialization of atomic variables is restricted to variables in global address space in opencl}} +} Index: test/SemaOpenCL/invalid-block.cl === --- /dev/null +++ test/SemaOpenCL/invalid-block.cl @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify -fblocks -cl-std=CL2.0 %s + +int (^BlkVariadic)(int, ...) = ^int(int I, ...) { // expected-error {{invalid block prototype, variadic arguments are not allowed}} + return 0; +}; + +typedef int (^BlkInt)(int); +void f1(int i) { + BlkInt B1 = ^int(int I) {return 1;}; + BlkInt B2 = ^int(int I) {return 2;}; + BlkInt Arr[] = {B1, B2}; // expected-error {{array of block is invalid in OpenCL}} + int tmp = i ? B1(i) // expected-error {{blocks cannot be used as expressions in ternary expressions}} + : B2(i); // expected-error {{blocks cannot be used as expressions in ternary expressions}} +} + +void f2(BlkInt *BlockPtr) { + BlkInt B = ^int(int I) {return 1;}; + BlkInt *P = // expected-error {{invalid argument type 'BlkInt' (aka 'int (^)(int)') to unary expression}} + B = *BlockPtr; // expected-error {{dereferencing pointer of type '__generic BlkInt *' (aka 'int (^__generic *)(int)') is not allowed}} +} + Index: test/CodeGenOpenCL/opencl_types.cl === --- test/CodeGenOpenCL/opencl_types.cl +++ test/CodeGenOpenCL/opencl_types.cl @@ -35,6 +35,3 @@ fnc4smp(glb_smp); // 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"}} Index: lib/Sema/SemaType.cpp === --- lib/Sema/SemaType.cpp +++ lib/Sema/SemaType.cpp @@ -2176,6 +2176,14 @@ Diag(Loc, diag::warn_vla_used); } + // OpenCL v2.0 s6.12.5 - The following Blocks features are currently not + // supported in OpenCL C: Arrays of Blocks. + if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion >= 200 && + Context.getBaseElementType(T)->isBlockPointerType()) { +Diag(Loc, diag::err_opencl_invalid_block_array); +return QualType(); + } + return T; } Index: lib/Sema/SemaInit.cpp === --- lib/Sema/SemaInit.cpp +++ lib/Sema/SemaInit.cpp @@ -6135,6 +6135,22 @@ << Init->getSourceRange(); } + // OpenCL v2.0 s6.13.1.1 - This macro can only be used to initialize atomic + // objects that are declared in program scope in the global address space. + if (S.getLangOpts().OpenCL && S.getLangOpts().OpenCLVersion >= 200 && + Entity.getType()->isAtomicType()) { +Qualifiers TyQualifiers = Entity.getType().getQualifiers(); +bool HasGlobalAS = TyQualifiers.hasAddressSpace() && + TyQualifiers.getAddressSpace() == LangAS::opencl_global; +if (!HasGlobalAS && Entity.getKind() == InitializedEntity::EK_Variable && +Args.size() > 0) { + const Expr *Init = Args[0]; + S.Diag(Init->getLocStart(), diag::err_opencl_atomic_init_addressspace) + << SourceRange(Entity.getDecl()->getLocStart(), Init->getLocEnd()); + return ExprError(); +} + } + // Diagnose cases where we initialize a pointer to an array temporary, and the // pointer obviously outlives the temporary. if (Args.size() == 1 && Args[0]->getType()->isArrayType() && Index: lib/Sema/SemaExpr.cpp === --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -6230,6 +6230,18 @@ return