Skip to content

Commit c670cdb

Browse files
authored
[sanitizers] Do not define __has_feature in sanitizer/common_interface_defs.h (#66628)
Public headers intended for user code should not define `__has_feature`, because this can break preprocessor checks done later in user code, e.g. if they test `#ifdef __has_feature` to check for real support in the compiler. Replace the only use in the public header with a check for it being supported before trying to use it. Define the fallback definition in the internal headers, so that other internal sanitizer headers can continue to use it as preferred. This resolves a bug reported to GCC as https://gcc.gnu.org/PR109882
1 parent 1d95a07 commit c670cdb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

compiler-rt/include/sanitizer/asan_interface.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,15 @@ void SANITIZER_CDECL __asan_unpoison_memory_region(void const volatile *addr,
5050
size_t size);
5151

5252
// Macros provided for convenience.
53-
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
53+
#ifdef __has_feature
54+
#if __has_feature(address_sanitizer)
55+
#define ASAN_DEFINE_REGION_MACROS
56+
#endif
57+
#elif defined(__SANITIZE_ADDRESS__)
58+
#define ASAN_DEFINE_REGION_MACROS
59+
#endif
60+
61+
#ifdef ASAN_DEFINE_REGION_MACROS
5462
/// Marks a memory region as unaddressable.
5563
///
5664
/// \note Macro provided for convenience; defined as a no-op if ASan is not
@@ -74,6 +82,7 @@ void SANITIZER_CDECL __asan_unpoison_memory_region(void const volatile *addr,
7482
#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
7583
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
7684
#endif
85+
#undef ASAN_DEFINE_REGION_MACROS
7786

7887
/// Checks if an address is poisoned.
7988
///

compiler-rt/include/sanitizer/common_interface_defs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
#include <stddef.h>
1616
#include <stdint.h>
1717

18-
// GCC does not understand __has_feature.
19-
#if !defined(__has_feature)
20-
#define __has_feature(x) 0
21-
#endif
22-
2318
// Windows allows a user to set their default calling convention, but we always
2419
// use __cdecl
2520
#ifdef _WIN32

compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#include "sanitizer_platform.h"
1616
#include "sanitizer_redefine_builtins.h"
1717

18+
// GCC does not understand __has_feature.
19+
#if !defined(__has_feature)
20+
#define __has_feature(x) 0
21+
#endif
22+
1823
#ifndef SANITIZER_DEBUG
1924
# define SANITIZER_DEBUG 0
2025
#endif

0 commit comments

Comments
 (0)