diff options
-rw-r--r-- | clang/include/clang/Basic/Builtins.def | 38 | ||||
-rw-r--r-- | clang/include/clang/Basic/Builtins.h | 2 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
-rw-r--r-- | clang/lib/Basic/Builtins.cpp | 3 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 10 | ||||
-rw-r--r-- | clang/test/SemaOpenCL/clang-builtin-version.cl | 44 | ||||
-rw-r--r-- | clang/test/SemaOpenCL/to_addr_builtin.cl | 15 |
8 files changed, 77 insertions, 39 deletions
diff --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def index bbefc38529e..0f88211ffa4 100644 --- a/clang/include/clang/Basic/Builtins.def +++ b/clang/include/clang/Basic/Builtins.def @@ -1282,34 +1282,34 @@ BUILTIN(__builtin_nontemporal_load, "v.", "t") // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions. // We need the generic prototype, since the packet type could be anything. -LANGBUILTIN(read_pipe, "i.", "tn", OCLC_LANG) -LANGBUILTIN(write_pipe, "i.", "tn", OCLC_LANG) +LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG) +LANGBUILTIN(write_pipe, "i.", "tn", OCLC20_LANG) -LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC_LANG) -LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC_LANG) +LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC20_LANG) +LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC20_LANG) -LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC_LANG) -LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC_LANG) +LANGBUILTIN(commit_write_pipe, "v.", "tn", OCLC20_LANG) +LANGBUILTIN(commit_read_pipe, "v.", "tn", OCLC20_LANG) -LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC_LANG) -LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC_LANG) +LANGBUILTIN(sub_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG) +LANGBUILTIN(sub_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG) -LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC_LANG) -LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC_LANG) +LANGBUILTIN(sub_group_commit_read_pipe, "v.", "tn", OCLC20_LANG) +LANGBUILTIN(sub_group_commit_write_pipe, "v.", "tn", OCLC20_LANG) -LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC_LANG) -LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC_LANG) +LANGBUILTIN(work_group_reserve_read_pipe, "i.", "tn", OCLC20_LANG) +LANGBUILTIN(work_group_reserve_write_pipe, "i.", "tn", OCLC20_LANG) -LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC_LANG) -LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC_LANG) +LANGBUILTIN(work_group_commit_read_pipe, "v.", "tn", OCLC20_LANG) +LANGBUILTIN(work_group_commit_write_pipe, "v.", "tn", OCLC20_LANG) -LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC_LANG) -LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC_LANG) +LANGBUILTIN(get_pipe_num_packets, "Ui.", "tn", OCLC20_LANG) +LANGBUILTIN(get_pipe_max_packets, "Ui.", "tn", OCLC20_LANG) // OpenCL v2.0 s6.13.9 - Address space qualifier functions. -LANGBUILTIN(to_global, "v*v*", "tn", OCLC_LANG) -LANGBUILTIN(to_local, "v*v*", "tn", OCLC_LANG) -LANGBUILTIN(to_private, "v*v*", "tn", OCLC_LANG) +LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG) +LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG) +LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG) #undef BUILTIN #undef LIBBUILTIN diff --git a/clang/include/clang/Basic/Builtins.h b/clang/include/clang/Basic/Builtins.h index 0ef35b6fbab..15e9a413fb4 100644 --- a/clang/include/clang/Basic/Builtins.h +++ b/clang/include/clang/Basic/Builtins.h @@ -36,7 +36,7 @@ enum LanguageID { CXX_LANG = 0x4, // builtin for cplusplus only. OBJC_LANG = 0x8, // builtin for objective-c and objective-c++ MS_LANG = 0x10, // builtin requires MS mode. - OCLC_LANG = 0x20, // builtin for OpenCL C only. + OCLC20_LANG = 0x20, // builtin for OpenCL C only. ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages. ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode. ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode. diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 25165bae48f..762c7c4db16 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -7908,8 +7908,6 @@ def err_opencl_type_can_only_be_used_as_function_parameter : Error < def warn_opencl_attr_deprecated_ignored : Warning < "%0 attribute is deprecated and ignored in OpenCL version %1">, InGroup<IgnoredAttributes>; -def err_opencl_builtin_requires_version : Error< - "%0 requires OpenCL version %1%select{| or above}2">; // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions def err_opencl_builtin_pipe_first_arg : Error< diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index e3d31a11d97..28695d649a8 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -69,7 +69,8 @@ bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo, bool MSModeUnsupported = !LangOpts.MicrosoftExt && (BuiltinInfo.Langs & MS_LANG); bool ObjCUnsupported = !LangOpts.ObjC1 && BuiltinInfo.Langs == OBJC_LANG; - bool OclCUnsupported = !LangOpts.OpenCL && BuiltinInfo.Langs == OCLC_LANG; + bool OclCUnsupported = LangOpts.OpenCLVersion != 200 && + BuiltinInfo.Langs == OCLC20_LANG; return !BuiltinsUnsupported && !MathBuiltinsUnsupported && !OclCUnsupported && !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported; } diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 57628f0f44c..c86c420c944 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2127,7 +2127,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, return RValue::get( Builder.CreateCall(CGM.CreateRuntimeFunction(FTy, Name), {Arg0, Arg1})); } - // OpenCL v2.0 s6.13.16 ,s9.17.3.5 - Built-in pipe commit read and write + // OpenCL v2.0 s6.13.16, s9.17.3.5 - Built-in pipe commit read and write // functions case Builtin::BIcommit_read_pipe: case Builtin::BIcommit_write_pipe: diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 89e5e3e5af1..0dbc8da9cc0 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -454,7 +454,7 @@ static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) { return false; } - +// \brief OpenCL v2.0 s6.13.9 - Address space qualifier functions. // \brief Performs semantic analysis for the to_global/local/private call. // \param S Reference to the semantic analyzer. // \param BuiltinID ID of the builtin function. @@ -462,13 +462,6 @@ static bool SemaBuiltinPipePackets(Sema &S, CallExpr *Call) { // \return True if a semantic error has been found, false otherwise. static bool SemaOpenCLBuiltinToAddr(Sema &S, unsigned BuiltinID, CallExpr *Call) { - // OpenCL v2.0 s6.13.9 - Address space qualifier functions. - if (S.getLangOpts().OpenCLVersion < 200) { - S.Diag(Call->getLocStart(), diag::err_opencl_builtin_requires_version) - << Call->getDirectCallee() << "2.0" << 1 << Call->getSourceRange(); - return true; - } - if (Call->getNumArgs() != 1) { S.Diag(Call->getLocStart(), diag::err_opencl_builtin_to_addr_arg_num) << Call->getDirectCallee() << Call->getSourceRange(); @@ -801,6 +794,7 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID, TheCall->setType(Context.VoidPtrTy); break; + // OpenCL v2.0, s6.13.16 - Pipe functions case Builtin::BIread_pipe: case Builtin::BIwrite_pipe: // Since those two functions are declared with var args, we need a semantic diff --git a/clang/test/SemaOpenCL/clang-builtin-version.cl b/clang/test/SemaOpenCL/clang-builtin-version.cl new file mode 100644 index 00000000000..8574682ab93 --- /dev/null +++ b/clang/test/SemaOpenCL/clang-builtin-version.cl @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 %s -fblocks -verify -pedantic -fsyntax-only -ferror-limit 100 + +// Confirm CL2.0 Clang builtins are not available in earlier versions + +kernel void dse_builtins() { + int tmp; + enqueue_kernel(tmp, tmp, tmp, ^(void) { // expected-warning{{implicit declaration of function 'enqueue_kernel' is invalid in C99}} + return; + }); + unsigned size = get_kernel_work_group_size(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_work_group_size' is invalid in C99}} + return; + }); + size = get_kernel_preferred_work_group_size_multiple(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_preferred_work_group_size_multiple' is invalid in C99}} + return; + }); +} + +void pipe_builtins() { + int tmp; + + read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'read_pipe' is invalid in C99}} + write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'write_pipe' is invalid in C99}} + + reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_read_pipe' is invalid in C99}} + reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_write_pipe' is invalid in C99}} + + work_group_reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_read_pipe' is invalid in C99}} + work_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_write_pipe' is invalid in C99}} + + sub_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_write_pipe' is invalid in C99}} + sub_group_reserve_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_read_pipe' is invalid in C99}} + + commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'commit_read_pipe' is invalid in C99}} + commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'commit_write_pipe' is invalid in C99}} + + work_group_commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_commit_read_pipe' is invalid in C99}} + work_group_commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_commit_write_pipe' is invalid in C99}} + + sub_group_commit_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_commit_write_pipe' is invalid in C99}} + sub_group_commit_read_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_commit_read_pipe' is invalid in C99}} + + get_pipe_num_packets(tmp); // expected-warning{{implicit declaration of function 'get_pipe_num_packets' is invalid in C99}} + get_pipe_max_packets(tmp); // expected-warning{{implicit declaration of function 'get_pipe_max_packets' is invalid in C99}} +} diff --git a/clang/test/SemaOpenCL/to_addr_builtin.cl b/clang/test/SemaOpenCL/to_addr_builtin.cl index 5fefaa5adc8..a145626cfce 100644 --- a/clang/test/SemaOpenCL/to_addr_builtin.cl +++ b/clang/test/SemaOpenCL/to_addr_builtin.cl @@ -10,43 +10,44 @@ void test(void) { glob = to_global(glob, loc); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}} + // expected-warning@-2{{implicit declaration of function 'to_global' is invalid in C99}} + // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} #else - // expected-error@-4{{invalid number of arguments to function: 'to_global'}} + // expected-error@-5{{invalid number of arguments to function: 'to_global'}} #endif int x; glob = to_global(x); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}} + // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} #else // expected-error@-4{{invalid argument x to function: 'to_global', expecting a generic pointer argument}} #endif glob = to_global(con); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}} + // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} #else // expected-error@-4{{invalid argument con to function: 'to_global', expecting a generic pointer argument}} #endif glob = to_global(con_typedef); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}} + // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}} #else // expected-error@-4{{invalid argument con_typedef to function: 'to_global', expecting a generic pointer argument}} #endif loc = to_global(glob); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}} + // expected-warning@-2{{incompatible integer to pointer conversion assigning to '__local int *' from 'int'}} #else // expected-error@-4{{assigning '__global int *' to '__local int *' changes address space of pointer}} #endif global char *glob_c = to_global(loc); #if __OPENCL_C_VERSION__ < CL_VERSION_2_0 - // expected-error@-2{{'to_global' requires OpenCL version 2.0 or above}} + // expected-warning@-2{{incompatible integer to pointer conversion initializing '__global char *' with an expression of type 'int'}} #else // expected-warning@-4{{incompatible pointer types initializing '__global char *' with an expression of type '__global int *'}} #endif |