[PATCH] D95616: [OpenCL] Change extension handling for -fdeclare-opencl-builtins
Sven van Haastregt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 2 03:15:48 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdc00c96b2d1b: [OpenCL] Change extension handling for -fdeclare-opencl-builtins (authored by svenvh).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95616/new/
https://reviews.llvm.org/D95616
Files:
clang/lib/Sema/SemaLookup.cpp
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
Index: clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
===================================================================
--- clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ 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 at -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 at -6{{candidate function not viable: cannot pass pointer to address space '__global' as a pointer to address space '__local' in 1st argument}}
-// expected-note at -7{{candidate function not viable: no known conversion}}
-// expected-note at -8{{candidate function not viable: no known conversion}}
-// expected-note at -9{{candidate function not viable: no known conversion}}
-// expected-note at -10{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
-// expected-note at -11{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
-// expected-note at -12{{candidate unavailable as it requires OpenCL extension 'cl_khr_int64_base_atomics' to be enabled}}
-// expected-note at -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 at -2{{no matching function for call to 'get_sub_group_size'}}
- // expected-note at -3{{candidate unavailable as it requires OpenCL extension 'cl_khr_subgroups' to be enabled}}
-#else
- // expected-error at -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 at -2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
+ // expected-error at -3{{implicit conversion changes signedness}}
#endif
}
Index: clang/lib/Sema/SemaLookup.cpp
===================================================================
--- clang/lib/Sema/SemaLookup.cpp
+++ 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 <Index, Len> 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<QualType, 1> RetTypes;
SmallVector<SmallVector<QualType, 1>, 5> ArgTypes;
@@ -843,8 +838,6 @@
if (!S.getLangOpts().OpenCLCPlusPlus)
NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context));
- AddOpenCLExtensions(S, OpenCLBuiltin, NewOpenCLBuiltin);
-
LR.addDecl(NewOpenCLBuiltin);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95616.320729.patch
Type: text/x-patch
Size: 4246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210202/b3e1e2cb/attachment-0001.bin>
More information about the cfe-commits
mailing list