Skip to content

Reject half vector types without cl_khr_fp16 #96640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7448,9 +7448,15 @@ static bool diagnoseOpenCLTypes(Sema &Se, VarDecl *NewVD) {

if (!Se.getOpenCLOptions().isAvailableOption("cl_khr_fp16",
Se.getLangOpts())) {
// OpenCL v1.2 s6.1.1.1: reject declaring variables of the half and
// half array type (unless the cl_khr_fp16 extension is enabled).
if (Se.Context.getBaseElementType(R)->isHalfType()) {
// OpenCL v1.2 s6.1.1.1: reject declaring variables of the half/halfn and
// half/halfn array type (unless the cl_khr_fp16 extension is enabled).
auto HasHalfTy = [](QualType T) {
if (const auto *EVTy = T->getAs<ExtVectorType>()) {
return EVTy->getElementType()->isHalfType();
}
return T->isHalfType();
};
if (HasHalfTy(R) || HasHalfTy(Se.Context.getBaseElementType(R))) {
Se.Diag(NewVD->getLocation(), diag::err_opencl_half_declaration) << R;
NewVD->setInvalidDecl();
return false;
Expand Down
4 changes: 4 additions & 0 deletions clang/test/SemaOpenCL/half.cl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ half half_disabled(half *p, // expected-error{{declaring function return value o
half *allowed3 = p + 1;

#ifdef HAVE_BUILTINS
half2 h2; // expected-error{{declaring variable of type '__private half2' (vector of 2 'half' values) is not allowed}}
half4 h4a[2]; // expected-error{{declaring variable of type '__private half4[2]' is not allowed}}
(void)ilogb(*p); // expected-error{{loading directly from pointer to type '__private half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
vstore_half(42.0f, 0, p);
#endif
Expand Down Expand Up @@ -55,6 +57,8 @@ half half_enabled(half *p, half h)
half *allowed3 = p + 1;

#ifdef HAVE_BUILTINS
half2 h2;
half4 h4a[2];
(void)ilogb(*p);
vstore_half(42.0f, 0, p);
#endif
Expand Down
Loading