Skip to content

Commit 16af23f

Browse files
committed
[clang][Headers] Use __has_builtin instead of _MSC_VER.
arm_acle.h relied on `_MSC_VER` to determine if a given function was already defined as a builtin. This was incorrect because `-fms-extensions` enables these builtins, but is not responsible for defining `_MSC_VER` on any target. The next closest thing is `_MSC_EXTENSIONS`, which is only defined on Windows targets, but even this is suboptimal. What this conditional is actually trying to determine is if the given functions are defined as builtins, so just check that directly. I also attempted to do this for `__nop`, but in that case intrin.h, which is only includable if `_MSC_VER` is defined, has its own definition. So in that case `_MSC_VER` is correct. Differential Revision: https://reviews.llvm.org/D75719 rdar://60102353
1 parent c3de1d0 commit 16af23f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

clang/lib/Headers/arm_acle.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,43 @@ extern "C" {
2222

2323
/* 8 SYNCHRONIZATION, BARRIER AND HINT INTRINSICS */
2424
/* 8.3 Memory barriers */
25-
#if !defined(_MSC_VER)
25+
#if !__has_builtin(__dmb)
2626
#define __dmb(i) __builtin_arm_dmb(i)
27+
#endif
28+
#if !__has_builtin(__dsb)
2729
#define __dsb(i) __builtin_arm_dsb(i)
30+
#endif
31+
#if !__has_builtin(__isb)
2832
#define __isb(i) __builtin_arm_isb(i)
2933
#endif
3034

3135
/* 8.4 Hints */
3236

33-
#if !defined(_MSC_VER)
37+
#if !__has_builtin(__wfi)
3438
static __inline__ void __attribute__((__always_inline__, __nodebug__)) __wfi(void) {
3539
__builtin_arm_wfi();
3640
}
41+
#endif
3742

43+
#if !__has_builtin(__wfe)
3844
static __inline__ void __attribute__((__always_inline__, __nodebug__)) __wfe(void) {
3945
__builtin_arm_wfe();
4046
}
47+
#endif
4148

49+
#if !__has_builtin(__sev)
4250
static __inline__ void __attribute__((__always_inline__, __nodebug__)) __sev(void) {
4351
__builtin_arm_sev();
4452
}
53+
#endif
4554

55+
#if !__has_builtin(__sevl)
4656
static __inline__ void __attribute__((__always_inline__, __nodebug__)) __sevl(void) {
4757
__builtin_arm_sevl();
4858
}
59+
#endif
4960

61+
#if !__has_builtin(__yield)
5062
static __inline__ void __attribute__((__always_inline__, __nodebug__)) __yield(void) {
5163
__builtin_arm_yield();
5264
}

clang/test/Headers/arm-acle-header.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// RUN: %clang_cc1 -x c++ -triple thumbv7-windows -target-cpu cortex-a15 -fsyntax-only -ffreestanding %s
77
// RUN: %clang_cc1 -x c++ -triple thumbv7-windows -target-cpu cortex-a15 -fsyntax-only -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 %s
88
// RUN: %clang_cc1 -x c++ -triple aarch64-windows -target-cpu cortex-a53 -fsyntax-only -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=19.11 %s
9+
// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios -target-cpu apple-a7 -fsyntax-only -ffreestanding -fms-extensions %s
910
// expected-no-diagnostics
1011

1112
#include <arm_acle.h>

0 commit comments

Comments
 (0)