Debian Codegraph @

llvm-project/llvm/projects/opencl-clang/patches/clang/0004-OpenCL-Allow-undefining-header-only-macros.patch

raw
1 From a60b8f468119065f8a6cb4a16598263cb00de0b5 Mon Sep 17 00:00:00 2001
2 From: Sven van Haastregt <[email protected]>
3 Date: Mon, 16 Jan 2023 11:32:12 +0000
4 Subject: [PATCH] [OpenCL] Allow undefining header-only features
5
6 `opencl-c-base.h` always defines 5 particular feature macros for
7 SPIR-V, making it impossible to disable those features.
8
9 To allow disabling any of those features, let the header recognize
10 `__undef_<feature>` macros. The user can then pass the
11 `-D__undef_<feature>` flag on the command line to disable a specific
12 feature. The __undef macro could potentially also be set from
13 `-cl-ext=-feature`, but for now only change the header and only
14 provide __undef macros for the 5 features that are always enabled in
15 `opencl-c-base.h`.
16
17 Differential Revision: https://reviews.llvm.org/D141297
18
19 diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
20 index fad2f9c0272b..84a2d834aa3c 100644
21 --- a/clang/lib/Headers/opencl-c-base.h
22 +++ b/clang/lib/Headers/opencl-c-base.h
23 @@ -93,6 +93,24 @@
24 #undef __opencl_c_read_write_images
25 #endif
26
27 +// Undefine any feature macros that have been explicitly disabled using
28 +// an __undef_<feature> macro.
29 +#ifdef __undef___opencl_c_work_group_collective_functions
30 +#undef __opencl_c_work_group_collective_functions
31 +#endif
32 +#ifdef __undef___opencl_c_atomic_order_seq_cst
33 +#undef __opencl_c_atomic_order_seq_cst
34 +#endif
35 +#ifdef __undef___opencl_c_atomic_scope_device
36 +#undef __opencl_c_atomic_scope_device
37 +#endif
38 +#ifdef __undef___opencl_c_atomic_scope_all_devices
39 +#undef __opencl_c_atomic_scope_all_devices
40 +#endif
41 +#ifdef __undef___opencl_c_read_write_images
42 +#undef __opencl_c_read_write_images
43 +#endif
44 +
45 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
46
47 #if !defined(__opencl_c_generic_address_space)
48 diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl
49 index 3f59b4ea3b5a..7006fb5d181a 100644
50 --- a/clang/test/SemaOpenCL/features.cl
51 +++ b/clang/test/SemaOpenCL/features.cl
52 @@ -35,6 +35,15 @@
53 // RUN: -D__undef___opencl_c_read_write_images=1 \
54 // RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
55
56 +// For OpenCL C 3.0, header-only features can be disabled using macros.
57 +// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
58 +// RUN: -D__undef___opencl_c_work_group_collective_functions=1 \
59 +// RUN: -D__undef___opencl_c_atomic_order_seq_cst=1 \
60 +// RUN: -D__undef___opencl_c_atomic_scope_device=1 \
61 +// RUN: -D__undef___opencl_c_atomic_scope_all_devices=1 \
62 +// RUN: -D__undef___opencl_c_read_write_images=1 \
63 +// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
64 +
65 // Note that __opencl_c_int64 is always defined assuming
66 // always compiling for FULL OpenCL profile
67