Debian Codegraph @

llvm-project/llvm/projects/opencl-clang/patches/clang/0013-Clang-OpenCL-Add-OpenCL-3.1-language-version-204043.patch

raw
1 From 6b3714977dd352b353d06ffc37703a7346f7bfdc Mon Sep 17 00:00:00 2001
2 From: Wenju He <[email protected]>
3 Date: Tue, 14 Jul 2026 13:07:36 +0200
4 Subject: [PATCH 1/2] [Clang][OpenCL] Add OpenCL 3.1 language version (#204043)
5
6 OpenCL 3.1 was recently added to spec in
7 https://github.com/KhronosGroup/OpenCL-Docs/commit/9fff1a87a975
8
9 This PR adds version 3.1 to clang support, including frontend flag
10 `-std=cl3.1` (and its alias `-std=CL3.1`).
11 Updated release note.
12
13 A few extensions are promoted to 3.1 core. They'll be handled in
14 follow-up PRs.
15
16 Assisted-by: Claude Sonnet 4.6
17 ---
18 clang/docs/ReleaseNotes.rst | 4 ++++
19 clang/include/clang/Basic/LangStandards.def | 4 ++++
20 clang/include/clang/Basic/OpenCLOptions.h | 5 ++++-
21 clang/lib/Basic/LangOptions.cpp | 2 ++
22 clang/lib/Basic/TargetInfo.cpp | 2 +-
23 clang/lib/Frontend/CompilerInvocation.cpp | 1 +
24 clang/lib/Frontend/InitPreprocessor.cpp | 4 ++++
25 clang/test/Driver/opencl.cl | 2 ++
26 clang/test/Driver/unknown-std.cl | 1 +
27 clang/test/Preprocessor/predefined-macros.c | 15 +++++++++++++++
28 .../utils/TableGen/ClangOpenCLBuiltinEmitter.cpp | 2 +-
29 11 files changed, 39 insertions(+), 3 deletions(-)
30
31 diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
32 index 8d67ff904469..3d92c4bcdb90 100644
33 --- a/clang/docs/ReleaseNotes.rst
34 +++ b/clang/docs/ReleaseNotes.rst
35 @@ -957,6 +957,10 @@ Miscellaneous Clang Crashes Fixed
36 (`#58800 <https://github.com/llvm/llvm-project/issues/58800>`_)
37
38
39 +OpenCL Specific Changes
40 +-----------------------
41 +- Added support for OpenCL C 3.1 language version (``-cl-std=CL3.1``).
42 +
43 Target Specific Changes
44 -----------------------
45
46 diff --git a/clang/include/clang/Basic/LangStandards.def b/clang/include/clang/Basic/LangStandards.def
47 index c5d4da1cb2f9..02c9c439427e 100644
48 --- a/clang/include/clang/Basic/LangStandards.def
49 +++ b/clang/include/clang/Basic/LangStandards.def
50 @@ -179,6 +179,9 @@ LANGSTANDARD(opencl20, "cl2.0",
51 LANGSTANDARD(opencl30, "cl3.0",
52 OpenCL, "OpenCL 3.0",
53 LineComment | C99 | Digraphs | HexFloat | OpenCL)
54 +LANGSTANDARD(opencl31, "cl3.1",
55 + OpenCL, "OpenCL 3.1",
56 + LineComment | C99 | Digraphs | HexFloat | OpenCL)
57
58 LANGSTANDARD(openclcpp10, "clc++1.0",
59 OpenCL, "C++ for OpenCL 1.0",
60 @@ -196,6 +199,7 @@ LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")
61 LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2")
62 LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
63 LANGSTANDARD_ALIAS_DEPR(opencl30, "CL3.0")
64 +LANGSTANDARD_ALIAS_DEPR(opencl31, "CL3.1")
65 LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++")
66 LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++1.0")
67 LANGSTANDARD_ALIAS_DEPR(openclcpp2021, "CLC++2021")
68 diff --git a/clang/include/clang/Basic/OpenCLOptions.h b/clang/include/clang/Basic/OpenCLOptions.h
69 index d6cb1a210519..ec661bba94ad 100644
70 --- a/clang/include/clang/Basic/OpenCLOptions.h
71 +++ b/clang/include/clang/Basic/OpenCLOptions.h
72 @@ -32,7 +32,8 @@ enum OpenCLVersionID : unsigned int {
73 OCL_C_12 = 0x4,
74 OCL_C_20 = 0x8,
75 OCL_C_30 = 0x10,
76 - OCL_C_ALL = 0x1f,
77 + OCL_C_31 = 0x20,
78 + OCL_C_ALL = 0x3f,
79 OCL_C_11P = OCL_C_ALL ^ OCL_C_10, // OpenCL C 1.1+
80 OCL_C_12P = OCL_C_ALL ^ (OCL_C_10 | OCL_C_11), // OpenCL C 1.2+
81 };
82 @@ -51,6 +52,8 @@ static inline OpenCLVersionID encodeOpenCLVersion(unsigned OpenCLVersion) {
83 return OCL_C_20;
84 case 300:
85 return OCL_C_30;
86 + case 310:
87 + return OCL_C_31;
88 }
89 }
90
91 diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
92 index 753b6bfe18a3..193956e23427 100644
93 --- a/clang/lib/Basic/LangOptions.cpp
94 +++ b/clang/lib/Basic/LangOptions.cpp
95 @@ -132,6 +132,8 @@ void LangOptions::setLangDefaults(LangOptions &Opts, Language Lang,
96 Opts.OpenCLVersion = 200;
97 else if (LangStd == LangStandard::lang_opencl30)
98 Opts.OpenCLVersion = 300;
99 + else if (LangStd == LangStandard::lang_opencl31)
100 + Opts.OpenCLVersion = 310;
101 else if (LangStd == LangStandard::lang_openclcpp10)
102 Opts.OpenCLCPlusPlusVersion = 100;
103 else if (LangStd == LangStandard::lang_openclcpp2021)
104 diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
105 index 031e1507fe43..f32eeaf6eba9 100644
106 --- a/clang/lib/Basic/TargetInfo.cpp
107 +++ b/clang/lib/Basic/TargetInfo.cpp
108 @@ -447,7 +447,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
109 // for OpenCL C 2.0 but with no access to target capabilities. Target
110 // should be immutable once created and thus these language options need
111 // to be defined only once.
112 - if (Opts.getOpenCLCompatibleVersion() == 300) {
113 + if (Opts.getOpenCLCompatibleVersion() >= 300) {
114 const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts();
115 Opts.OpenCLGenericAddressSpace = hasFeatureEnabled(
116 OpenCLFeaturesMap, "__opencl_c_generic_address_space");
117 diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
118 index 0bb9c8c83c63..25b8a31e008e 100644
119 --- a/clang/lib/Frontend/CompilerInvocation.cpp
120 +++ b/clang/lib/Frontend/CompilerInvocation.cpp
121 @@ -3648,6 +3648,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
122 .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12)
123 .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20)
124 .Cases("cl3.0", "CL3.0", LangStandard::lang_opencl30)
125 + .Cases("cl3.1", "CL3.1", LangStandard::lang_opencl31)
126 .Cases("clc++", "CLC++", LangStandard::lang_openclcpp10)
127 .Cases("clc++1.0", "CLC++1.0", LangStandard::lang_openclcpp10)
128 .Cases("clc++2021", "CLC++2021", LangStandard::lang_openclcpp2021)
129 diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
130 index 33c8409eaf12..24919bef615e 100644
131 --- a/clang/lib/Frontend/InitPreprocessor.cpp
132 +++ b/clang/lib/Frontend/InitPreprocessor.cpp
133 @@ -539,6 +539,9 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
134 case 300:
135 Builder.defineMacro("__OPENCL_C_VERSION__", "300");
136 break;
137 + case 310:
138 + Builder.defineMacro("__OPENCL_C_VERSION__", "310");
139 + break;
140 default:
141 llvm_unreachable("Unsupported OpenCL version");
142 }
143 @@ -548,6 +551,7 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
144 Builder.defineMacro("CL_VERSION_1_2", "120");
145 Builder.defineMacro("CL_VERSION_2_0", "200");
146 Builder.defineMacro("CL_VERSION_3_0", "300");
147 + Builder.defineMacro("CL_VERSION_3_1", "310");
148
149 if (TI.isLittleEndian())
150 Builder.defineMacro("__ENDIAN_LITTLE__");
151 diff --git a/clang/test/Driver/opencl.cl b/clang/test/Driver/opencl.cl
152 index ba1ace508150..86d9960e10d4 100644
153 --- a/clang/test/Driver/opencl.cl
154 +++ b/clang/test/Driver/opencl.cl
155 @@ -4,6 +4,7 @@
156 // RUN: %clang -S -### -cl-std=CL1.2 %s 2>&1 | FileCheck --check-prefix=CHECK-CL12 %s
157 // RUN: %clang -S -### -cl-std=CL2.0 %s 2>&1 | FileCheck --check-prefix=CHECK-CL20 %s
158 // RUN: %clang -S -### -cl-std=CL3.0 %s 2>&1 | FileCheck --check-prefix=CHECK-CL30 %s
159 +// RUN: %clang -S -### -cl-std=CL3.1 %s 2>&1 | FileCheck --check-prefix=CHECK-CL31 %s
160 // RUN: %clang -S -### -cl-std=clc++ %s 2>&1 | FileCheck --check-prefix=CHECK-CLCPP %s
161 // RUN: %clang -S -### -cl-opt-disable %s 2>&1 | FileCheck --check-prefix=CHECK-OPT-DISABLE %s
162 // RUN: %clang -S -### -cl-strict-aliasing %s 2>&1 | FileCheck --check-prefix=CHECK-STRICT-ALIASING %s
163 @@ -29,6 +30,7 @@
164 // CHECK-CL12: "-cc1" {{.*}} "-cl-std=CL1.2"
165 // CHECK-CL20: "-cc1" {{.*}} "-cl-std=CL2.0"
166 // CHECK-CL30: "-cc1" {{.*}} "-cl-std=CL3.0"
167 +// CHECK-CL31: "-cc1" {{.*}} "-cl-std=CL3.1"
168 // CHECK-CLCPP: "-cc1" {{.*}} "-cl-std=clc++"
169 // CHECK-OPT-DISABLE: "-cc1" {{.*}} "-cl-opt-disable"
170 // CHECK-STRICT-ALIASING: "-cc1" {{.*}} "-cl-strict-aliasing"
171 diff --git a/clang/test/Driver/unknown-std.cl b/clang/test/Driver/unknown-std.cl
172 index 3570515ad076..a6d065d9a7d4 100644
173 --- a/clang/test/Driver/unknown-std.cl
174 +++ b/clang/test/Driver/unknown-std.cl
175 @@ -11,6 +11,7 @@
176 // CHECK-NEXT: note: use 'cl1.2' for 'OpenCL 1.2' standard
177 // CHECK-NEXT: note: use 'cl2.0' for 'OpenCL 2.0' standard
178 // CHECK-NEXT: note: use 'cl3.0' for 'OpenCL 3.0' standard
179 +// CHECK-NEXT: note: use 'cl3.1' for 'OpenCL 3.1' standard
180 // CHECK-NEXT: note: use 'clc++1.0' or 'clc++' for 'C++ for OpenCL 1.0' standard
181 // CHECK-NEXT: note: use 'clc++2021' for 'C++ for OpenCL 2021' standard
182
183 diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
184 index 4dd02c3cfde4..91df26284e4c 100644
185 --- a/clang/test/Preprocessor/predefined-macros.c
186 +++ b/clang/test/Preprocessor/predefined-macros.c
187 @@ -145,6 +145,8 @@
188 // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL20
189 // RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL3.0 \
190 // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL30
191 +// RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=CL3.1 \
192 +// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-CL31
193 // RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-fast-relaxed-math \
194 // RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-FRM
195 // RUN: %clang_cc1 %s -E -dM -o - -x cl -cl-std=clc++ \
196 @@ -158,6 +160,7 @@
197 // CHECK-CL10: #define CL_VERSION_1_2 120
198 // CHECK-CL10: #define CL_VERSION_2_0 200
199 // CHECK-CL10: #define CL_VERSION_3_0 300
200 +// CHECK-CL10: #define CL_VERSION_3_1 310
201 // CHECK-CL10: #define __OPENCL_C_VERSION__ 100
202 // CHECK-CL10-NOT: #define __FAST_RELAXED_MATH__ 1
203 // CHECK-CL11: #define CL_VERSION_1_0 100
204 @@ -165,6 +168,7 @@
205 // CHECK-CL11: #define CL_VERSION_1_2 120
206 // CHECK-CL11: #define CL_VERSION_2_0 200
207 // CHECK-CL11: #define CL_VERSION_3_0 300
208 +// CHECK-CL11: #define CL_VERSION_3_1 310
209 // CHECK-CL11: #define __OPENCL_C_VERSION__ 110
210 // CHECK-CL11-NOT: #define __FAST_RELAXED_MATH__ 1
211 // CHECK-CL12: #define CL_VERSION_1_0 100
212 @@ -172,6 +176,7 @@
213 // CHECK-CL12: #define CL_VERSION_1_2 120
214 // CHECK-CL12: #define CL_VERSION_2_0 200
215 // CHECK-CL12: #define CL_VERSION_3_0 300
216 +// CHECK-CL12: #define CL_VERSION_3_1 310
217 // CHECK-CL12: #define __OPENCL_C_VERSION__ 120
218 // CHECK-CL12-NOT: #define __FAST_RELAXED_MATH__ 1
219 // CHECK-CL20: #define CL_VERSION_1_0 100
220 @@ -179,6 +184,7 @@
221 // CHECK-CL20: #define CL_VERSION_1_2 120
222 // CHECK-CL20: #define CL_VERSION_2_0 200
223 // CHECK-CL20: #define CL_VERSION_3_0 300
224 +// CHECK-CL20: #define CL_VERSION_3_1 310
225 // CHECK-CL20: #define __OPENCL_C_VERSION__ 200
226 // CHECK-CL20-NOT: #define __FAST_RELAXED_MATH__ 1
227 // CHECK-CL30: #define CL_VERSION_1_0 100
228 @@ -186,8 +192,17 @@
229 // CHECK-CL30: #define CL_VERSION_1_2 120
230 // CHECK-CL30: #define CL_VERSION_2_0 200
231 // CHECK-CL30: #define CL_VERSION_3_0 300
232 +// CHECK-CL30: #define CL_VERSION_3_1 310
233 // CHECK-CL30: #define __OPENCL_C_VERSION__ 300
234 // CHECK-CL30-NOT: #define __FAST_RELAXED_MATH__ 1
235 +// CHECK-CL31: #define CL_VERSION_1_0 100
236 +// CHECK-CL31: #define CL_VERSION_1_1 110
237 +// CHECK-CL31: #define CL_VERSION_1_2 120
238 +// CHECK-CL31: #define CL_VERSION_2_0 200
239 +// CHECK-CL31: #define CL_VERSION_3_0 300
240 +// CHECK-CL31: #define CL_VERSION_3_1 310
241 +// CHECK-CL31: #define __OPENCL_C_VERSION__ 310
242 +// CHECK-CL31-NOT: #define __FAST_RELAXED_MATH__ 1
243 // CHECK-FRM: #define __FAST_RELAXED_MATH__ 1
244 // CHECK-CLCPP10: #define __CL_CPP_VERSION_1_0__ 100
245 // CHECK-CLCPP10: #define __CL_CPP_VERSION_2021__ 202100
246 diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
247 index da5d1fdc2eae..abf4aef9ce7d 100644
248 --- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
249 +++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
250 @@ -597,7 +597,7 @@ static unsigned short EncodeVersions(unsigned int MinVersion,
251 MaxVersion = UINT_MAX;
252 }
253
254 - unsigned VersionIDs[] = {100, 110, 120, 200, 300};
255 + unsigned VersionIDs[] = {100, 110, 120, 200, 300, 310};
256 for (unsigned I = 0; I < std::size(VersionIDs); I++) {
257 if (VersionIDs[I] >= MinVersion && VersionIDs[I] < MaxVersion) {
258 Encoded |= 1 << I;
259 --
260 2.53.0
261