Skip to content

Commit cc9260a

Browse files
committed
[OpenCL] Supports optional generic address space semantics in C++ for OpenCL 2021
Adds support for a feature macro `__opencl_c_generic_adress_space` in C++ for OpenCL 2021 enabling a respective optional core feature from OpenCL 3.0. Testing is only performed in SemaOpenCL because generic address space functionality is yet to be implemented in C++ for OpenCL 2021. This change aims to achieve compatibility between C++ for OpenCL 2021 and OpenCL 3.0. Differential Revision: https://reviews.llvm.org/D108461
1 parent 2706b1a commit cc9260a

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

clang/lib/Basic/TargetInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,13 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
406406
// for OpenCL C 2.0 but with no access to target capabilities. Target
407407
// should be immutable once created and thus these language options need
408408
// to be defined only once.
409-
if (Opts.OpenCLVersion == 300) {
409+
if (Opts.getOpenCLCompatibleVersion() == 300) {
410410
const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
411411
Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
412412
OpenCLFeaturesMap, "__opencl_c_generic_address_space");
413-
Opts.OpenCLPipes =
414-
hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
413+
if (Opts.OpenCLVersion == 300)
414+
Opts.OpenCLPipes =
415+
hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes");
415416
}
416417
}
417418

clang/test/SemaOpenCL/address-spaces-conversions-cl2.0.cl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL2.0
22
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL2.0
33
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL2.0
4-
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++
5-
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++
6-
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++
4+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++1.0
5+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++1.0
6+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++1.0
77
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
88
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
99
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space
10+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DCONSTANT -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space
11+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGLOBAL -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space
12+
// RUN: %clang_cc1 %s -ffake-address-space-map -verify -pedantic -fsyntax-only -DGENERIC -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space
1013

1114
/* OpenCLC v2.0 adds a set of restrictions for conversions between pointers to
1215
* different address spaces, mainly described in Sections 6.5.5 and 6.5.6.

clang/test/SemaOpenCL/address-spaces.cl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
22
// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
33
// RUN: %clang_cc1 %s -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
4-
// RUN: %clang_cc1 %s -cl-std=clc++ -verify -pedantic -fsyntax-only
4+
// RUN: %clang_cc1 %s -cl-std=clc++1.0 -verify -pedantic -fsyntax-only
5+
// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=+__opencl_c_generic_address_space -verify -pedantic -fsyntax-only
56

67
__constant int ci = 1;
78

0 commit comments

Comments
 (0)