Skip to content

Commit 2a2a18b

Browse files
committed
add release note, only define for offloading targets, update test
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 46cce74 commit 2a2a18b

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ It can be used like this:
6969

7070
When using device offloading, a builtin is considered available if it is
7171
available on either the host or the device targets.
72-
Use ``__has_target_builtin`` to consider only the current target.
72+
Use ``__has_target_builtin`` to consider only the current target for an
73+
offloading target.
7374

7475
``__has_constexpr_builtin``
7576
---------------------------
@@ -129,6 +130,8 @@ It can be used like this:
129130
``__has_target_builtin`` should not be used to detect support for a builtin macro;
130131
use ``#ifdef`` instead.
131132

133+
``__has_target_built`` is only defined for offloading targets.
134+
132135
.. _langext-__has_feature-__has_extension:
133136

134137
``__has_feature`` and ``__has_extension``

clang/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ Non-comprehensive list of changes in this release
104104
New Compiler Flags
105105
------------------
106106

107+
New Compiler Builtins
108+
---------------------
109+
110+
- The new ``__has_target_builtin`` macro can be used to check if a builtin is available
111+
on the current offloading target.
112+
107113
Deprecated Compiler Flags
108114
-------------------------
109115

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,12 @@ void Preprocessor::RegisterBuiltinMacros() {
357357
Ident__has_builtin = RegisterBuiltinMacro("__has_builtin");
358358
Ident__has_constexpr_builtin =
359359
RegisterBuiltinMacro("__has_constexpr_builtin");
360-
Ident__has_target_builtin = RegisterBuiltinMacro("__has_target_builtin");
360+
if (getLangOpts().OpenMPIsTargetDevice || getLangOpts().CUDAIsDevice ||
361+
getLangOpts().SYCLIsDevice)
362+
Ident__has_target_builtin = RegisterBuiltinMacro("__has_target_builtin");
363+
else
364+
Ident__has_target_builtin = nullptr;
365+
361366
Ident__has_attribute = RegisterBuiltinMacro("__has_attribute");
362367
if (!getLangOpts().CPlusPlus)
363368
Ident__has_c_attribute = RegisterBuiltinMacro("__has_c_attribute");
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
// RUN: %clang_cc1 -fopenmp -triple=spirv64 -fopenmp-is-target-device \
2-
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not=BAD %s
2+
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not="{{BAD|DOESNT}}" %s
33

44
// RUN: %clang_cc1 -fopenmp -triple=nvptx64 -fopenmp-is-target-device \
5-
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not=BAD %s
5+
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not="{{BAD|DOESNT}}" %s
66

77
// RUN: %clang_cc1 -fopenmp -triple=amdgcn-amd-amdhsa -fopenmp-is-target-device \
8-
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not=BAD %s
8+
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not="{{BAD|DOESNT}}" %s
99

1010
// RUN: %clang_cc1 -fopenmp -triple=aarch64 -fopenmp-is-target-device \
11-
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not=BAD %s
11+
// RUN: -aux-triple x86_64-linux-unknown -E %s | FileCheck -implicit-check-not="{{BAD|DOESNT}}" %s
12+
13+
// RUN: %clang_cc1 -triple=aarch64 -E %s | FileCheck -check-prefix=CHECK-NOTOFFLOAD -implicit-check-not="{{GOOD|HAS|BAD}}" %s
1214

1315
// CHECK: GOOD
16+
17+
// CHECK-NOTOFFLOAD: DOESNT
18+
#ifdef __has_target_builtin
19+
HAS
1420
#if __has_target_builtin(__builtin_ia32_pause)
1521
BAD
1622
#else
1723
GOOD
1824
#endif
25+
#else
26+
DOESNT
27+
#endif

0 commit comments

Comments
 (0)