Skip to content

[sanitizers] Do not define __has_feature in sanitizer/common_interface_defs.h #66628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler-rt/include/sanitizer/asan_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ void SANITIZER_CDECL __asan_unpoison_memory_region(void const volatile *addr,
size_t size);

// Macros provided for convenience.
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
#ifdef __has_feature
#if __has_feature(address_sanitizer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either I am missing something or there is a second #endif missing below line 53.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The #ifdef on line 51 starts a group that ends with the #elif on line 55, which starts a new group that ends with the #endif on line 57.

The #if on line 51 starts a group that ends with the #endif on line 54.

Would it be clearer like this?

#ifdef __has_feature
# if __has_feature(address_sanitizer)
#  define ASAN_DEFINE_REGION_MACROS
# endif
#elif defined(__SANITIZE_ADDRESS__)
# define ASAN_DEFINE_REGION_MACROS
#endif

That's how I would format it in my own code, but that doesn't seem to be the prevailing style in the sanitizers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my fault sorry. I missed that the second is elif and not if :)

#define ASAN_DEFINE_REGION_MACROS
#endif
#elif defined(__SANITIZE_ADDRESS__)
#define ASAN_DEFINE_REGION_MACROS
#endif

#ifdef ASAN_DEFINE_REGION_MACROS
/// Marks a memory region as unaddressable.
///
/// \note Macro provided for convenience; defined as a no-op if ASan is not
Expand All @@ -74,6 +82,7 @@ void SANITIZER_CDECL __asan_unpoison_memory_region(void const volatile *addr,
#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
#endif
#undef ASAN_DEFINE_REGION_MACROS

/// Checks if an address is poisoned.
///
Expand Down
5 changes: 0 additions & 5 deletions compiler-rt/include/sanitizer/common_interface_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#include <stddef.h>
#include <stdint.h>

// GCC does not understand __has_feature.
#if !defined(__has_feature)
#define __has_feature(x) 0
#endif

// Windows allows a user to set their default calling convention, but we always
// use __cdecl
#ifdef _WIN32
Expand Down
5 changes: 5 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "sanitizer_platform.h"
#include "sanitizer_redefine_builtins.h"

// GCC does not understand __has_feature.
#if !defined(__has_feature)
#define __has_feature(x) 0
#endif

#ifndef SANITIZER_DEBUG
# define SANITIZER_DEBUG 0
#endif
Expand Down