Skip to content

Commit 6605551

Browse files
[Clang] Fix __cpuidex conflict with CUDA (llvm#152556)
The landing of llvm#126324 made it so that __has_builtin returns false for aux triple builtins. CUDA offloading can sometimes compile where the host is in the aux triple (ie x86_64). This patch explicitly carves out NVPTX so that we do not run into redefinition errors.
1 parent f7c6c7c commit 6605551

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/Headers/cpuid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,15 @@ static __inline int __get_cpuid_count (unsigned int __leaf,
345345
// In some configurations, __cpuidex is defined as a builtin (primarily
346346
// -fms-extensions) which will conflict with the __cpuidex definition below.
347347
#if !(__has_builtin(__cpuidex))
348+
// In some cases, offloading will set the host as the aux triple and define the
349+
// builtin. Given __has_builtin does not detect builtins on aux triples, we need
350+
// to explicitly check for some offloading cases.
351+
#ifndef __NVPTX__
348352
static __inline void __cpuidex(int __cpu_info[4], int __leaf, int __subleaf) {
349353
__cpuid_count(__leaf, __subleaf, __cpu_info[0], __cpu_info[1], __cpu_info[2],
350354
__cpu_info[3]);
351355
}
352356
#endif
357+
#endif
353358

354359
#endif /* __CPUID_H */

clang/test/Headers/__cpuidex_conflict.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

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
8+
// RUN: %clang_cc1 -DIS_STATIC="" -triple nvptx64-nvidia-cuda -aux-triple x86_64-unknown-linux-gnu -aux-target-cpu x86-64 -fcuda-is-device -internal-isystem /home/gha/llvm-project/build/lib/clang/22/include -x cuda %s -o -
89

910
typedef __SIZE_TYPE__ size_t;
1011

0 commit comments

Comments
 (0)