Skip to content

Commit 6ff97d0

Browse files
authored
[Clang] Fix __cpuidex conflict with other offloading targets (#157741)
It seems that for whatever reason we must: 1) Declare aux builtins when the compiling for an offload device and 2) Define the aux builtin target macros when compiling for an offload device. In `cpuid.h` we try to define `__cpuidex` if it is not defined. Given the above, the function will both be defined as a builtin in the compiler and we can't rely on the `X86` macros to be undefined in the case the aux-triple is `X86`. Previously a workaround was added for NVPTX in #152556, extend it for the other offloading targets. Signed-off-by: Sarnie, Nick <[email protected]>
1 parent a301e1a commit 6ff97d0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/Headers/cpuid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static __inline int __get_cpuid_count (unsigned int __leaf,
348348
// In some cases, offloading will set the host as the aux triple and define the
349349
// builtin. Given __has_builtin does not detect builtins on aux triples, we need
350350
// to explicitly check for some offloading cases.
351-
#ifndef __NVPTX__
351+
#if !defined(__NVPTX__) && !defined(__AMDGPU__) && !defined(__SPIRV__)
352352
static __inline void __cpuidex(int __cpu_info[4], int __leaf, int __subleaf) {
353353
__cpuid_count(__leaf, __subleaf, __cpu_info[0], __cpu_info[1], __cpu_info[2],
354354
__cpu_info[3]);

clang/test/Headers/__cpuidex_conflict.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// Ensure that we do not run into conflicts when offloading.
77
// RUN: %clang_cc1 %s -DIS_STATIC=static -ffreestanding -fopenmp -fopenmp-is-target-device -aux-triple x86_64-unknown-linux-gnu
88
// RUN: %clang_cc1 -DIS_STATIC="" -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu x86-64 -fcuda-is-device -x cuda %s -o -
9+
// RUN: %clang_cc1 -DIS_STATIC="" -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu x86-64 -fcuda-is-device -x cuda %s -o -
10+
// RUN: %clang_cc1 -DIS_STATIC="" -triple spirv64 -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu x86-64 -fcuda-is-device -x cuda %s -o -
11+
// RUN: %clang_cc1 -DIS_STATIC="" -triple spirv64 -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu x86-64 -fsycl-is-device %s -o -
912

1013
typedef __SIZE_TYPE__ size_t;
1114

0 commit comments

Comments
 (0)