diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -743,18 +743,6 @@ } } -/// Add extensions to the function declaration. -/// \param S (in/out) The Sema instance. -/// \param BIDecl (in) Description of the builtin. -/// \param FDecl (in/out) FunctionDecl instance. -static void AddOpenCLExtensions(Sema &S, const OpenCLBuiltinStruct &BIDecl, - FunctionDecl *FDecl) { - // Fetch extension associated with a function prototype. - StringRef E = FunctionExtensionTable[BIDecl.Extension]; - if (E != "") - S.setOpenCLExtensionForDecl(FDecl, E); -} - /// When trying to resolve a function name, if isOpenCLBuiltin() returns a /// non-null pair, then the name is referencing an OpenCL /// builtin function. Add all candidate signatures to the LookUpResult. @@ -790,6 +778,13 @@ (OpenCLVersion >= OpenCLBuiltin.MaxVersion)) continue; + // Ignore this builtin function if it carries an extension macro that is + // not defined. This indicates that the extension is not supported by the + // target, so the builtin function should not be available. + StringRef Ext = FunctionExtensionTable[OpenCLBuiltin.Extension]; + if (!Ext.empty() && !S.getPreprocessor().isMacroDefined(Ext)) + continue; + SmallVector RetTypes; SmallVector, 5> ArgTypes; @@ -843,8 +838,6 @@ if (!S.getLangOpts().OpenCLCPlusPlus) NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context)); - AddOpenCLExtensions(S, OpenCLBuiltin, NewOpenCLBuiltin); - LR.addDecl(NewOpenCLBuiltin); } } diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl --- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl +++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl @@ -38,26 +38,6 @@ prefetch(a, 2); - atom_add((volatile __global int *)global_p, i); -#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_1_1 -// expected-error@-2{{no matching function for call to 'atom_add'}} - -// There are two potential definitions of the function "atom_add", both are -// currently disabled because the associated extension is disabled. -// expected-note@-6{{candidate function not viable: cannot pass pointer to address space '__global' as a pointer to address space '__local' in 1st argument}} -// expected-note@-7{{candidate function not viable: no known conversion}} -// expected-note@-8{{candidate function not viable: no known conversion}} -// expected-note@-9{{candidate function not viable: no known conversion}} -// expected-note@-10{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}} -// expected-note@-11{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}} -// expected-note@-12{{candidate unavailable as it requires OpenCL extension 'cl_khr_int64_base_atomics' to be enabled}} -// expected-note@-13{{candidate unavailable as it requires OpenCL extension 'cl_khr_int64_base_atomics' to be enabled}} -#endif - -#if __OPENCL_C_VERSION__ < CL_VERSION_1_1 -#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable -#endif - atom_add((volatile __global int *)global_p, i); atom_cmpxchg((volatile __global unsigned int *)global_p, ui, ui); } @@ -146,11 +126,9 @@ kernel void basic_subgroup(global uint *out) { out[0] = get_sub_group_size(); -#if defined(__OPENCL_CPP_VERSION__) - // expected-error@-2{{no matching function for call to 'get_sub_group_size'}} - // expected-note@-3{{candidate unavailable as it requires OpenCL extension 'cl_khr_subgroups' to be enabled}} -#else - // expected-error@-5{{use of declaration 'get_sub_group_size' requires cl_khr_subgroups extension to be enabled}} +#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2 && !defined(__OPENCL_CPP_VERSION__) + // expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}} + // expected-error@-3{{implicit conversion changes signedness}} #endif }