Skip to content

Commit 0aed36d

Browse files
committed
[OpenCL] Support -fdeclare-opencl-builtins in C++ mode
Support for C++ mode was accidentally lacking due to not checking the OpenCLCPlusPlus LangOpts version. Differential Revision: https://reviews.llvm.org/D69233
1 parent e57f8ad commit 0aed36d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clang/lib/Sema/SemaLookup.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,10 +765,13 @@ static void InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR,
765765
ASTContext &Context = S.Context;
766766

767767
// Ignore this BIF if its version does not match the language options.
768-
if (Context.getLangOpts().OpenCLVersion < OpenCLBuiltin.MinVersion)
768+
unsigned OpenCLVersion = Context.getLangOpts().OpenCLVersion;
769+
if (Context.getLangOpts().OpenCLCPlusPlus)
770+
OpenCLVersion = 200;
771+
if (OpenCLVersion < OpenCLBuiltin.MinVersion)
769772
continue;
770773
if ((OpenCLBuiltin.MaxVersion != 0) &&
771-
(Context.getLangOpts().OpenCLVersion >= OpenCLBuiltin.MaxVersion))
774+
(OpenCLVersion >= OpenCLBuiltin.MaxVersion))
772775
continue;
773776

774777
SmallVector<QualType, 1> RetTypes;

clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
55
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
66
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
7+
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -DNO_HEADER
8+
// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror -fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header
79

8-
#if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
10+
#if defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= CL_VERSION_2_0
911
// expected-no-diagnostics
1012
#endif
1113

@@ -97,7 +99,7 @@ kernel void basic_image_writeonly(write_only image1d_buffer_t image_write_only_i
9799

98100
kernel void basic_subgroup(global uint *out) {
99101
out[0] = get_sub_group_size();
100-
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
102+
#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
101103
// expected-error@-2{{implicit declaration of function 'get_sub_group_size' is invalid in OpenCL}}
102104
// expected-error@-3{{implicit conversion changes signedness: 'int' to 'uint' (aka 'unsigned int')}}
103105
#endif
@@ -130,7 +132,7 @@ kernel void basic_work_item() {
130132
uint ui;
131133

132134
get_enqueued_local_size(ui);
133-
#if __OPENCL_C_VERSION__ < CL_VERSION_2_0
135+
#if !defined(__OPENCL_CPP_VERSION__) && __OPENCL_C_VERSION__ < CL_VERSION_2_0
134136
// expected-error@-2{{implicit declaration of function 'get_enqueued_local_size' is invalid in OpenCL}}
135137
#endif
136138
}

0 commit comments

Comments
 (0)