public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug sanitizer/109882] sanitizer/common_interface_defs.h bogusly defines __has_feature
Date: Wed, 17 May 2023 08:19:35 +0000	[thread overview]
Message-ID: <bug-109882-4-kZLojiX6JX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109882-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109882

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Libstdc++ itself does this:

#if __SANITIZE_THREAD__
#  define _GLIBCXX_TSAN 1
#elif defined __has_feature
# if __has_feature(thread_sanitizer)
#  define _GLIBCXX_TSAN 1
# endif
#endif

The sanitizers could do something similar, although it looks like they don't
actually need to. The only use of __has_feature in the public API is in
asan_interface.h and that could easily be replaced. Then __has_feature can be
redefined in the internal headers, which (I assume) aren't meant to be included
by user code.

Something like this (untested):

diff --git a/libsanitizer/include/sanitizer/asan_interface.h
b/libsanitizer/include/sanitizer/asan_interface.h
index 9bff21c117b..186269ad694 100644
--- a/libsanitizer/include/sanitizer/asan_interface.h
+++ b/libsanitizer/include/sanitizer/asan_interface.h
@@ -48,7 +48,15 @@ void __asan_poison_memory_region(void const volatile *addr,
size_t size);
 void __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)
+#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
@@ -74,6 +82,7 @@ void __asan_unpoison_memory_region(void const volatile *addr,
size_t size);
 #define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
   ((void)(addr), (void)(size))
 #endif
+#undef ASAN_DEFINE_REGION_MACROS

 /// Checks if an address is poisoned.
 ///
diff --git a/libsanitizer/include/sanitizer/common_interface_defs.h
b/libsanitizer/include/sanitizer/common_interface_defs.h
index 2f415bd9e85..2f9c83ef74e 100644
--- a/libsanitizer/include/sanitizer/common_interface_defs.h
+++ b/libsanitizer/include/sanitizer/common_interface_defs.h
@@ -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
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/libsanitizer/sanitizer_common/sanitizer_internal_defs.h
b/libsanitizer/sanitizer_common/sanitizer_internal_defs.h
index 98186c429e9..7574dce7f4a 100644
--- a/libsanitizer/sanitizer_common/sanitizer_internal_defs.h
+++ b/libsanitizer/sanitizer_common/sanitizer_internal_defs.h
@@ -14,6 +14,11 @@

 #include "sanitizer_platform.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

  parent reply	other threads:[~2023-05-17  8:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 23:14 [Bug libstdc++/109882] New: -fsanitize=thread #include <memory> transitively includes sanitizer/common_interface_defs.h ed at catmur dot uk
2023-05-16 23:26 ` [Bug libstdc++/109882] " pinskia at gcc dot gnu.org
2023-05-16 23:27 ` [Bug sanitizer/109882] " pinskia at gcc dot gnu.org
2023-05-16 23:28 ` pinskia at gcc dot gnu.org
2023-05-16 23:45 ` redi at gcc dot gnu.org
2023-05-17  8:19 ` redi at gcc dot gnu.org [this message]
2023-05-17  8:28 ` [Bug sanitizer/109882] sanitizer/common_interface_defs.h bogusly defines __has_feature jakub at gcc dot gnu.org
2023-05-17 11:34 ` redi at gcc dot gnu.org
2023-05-18 12:50 ` redi at gcc dot gnu.org
2023-09-18 22:34 ` redi at gcc dot gnu.org
2023-11-09 10:05 ` redi at gcc dot gnu.org
2023-11-09 10:12 ` sjames at gcc dot gnu.org
2023-11-15 11:57 ` sjames at gcc dot gnu.org
2023-11-15 12:36 ` redi at gcc dot gnu.org
2023-11-15 12:37 ` redi at gcc dot gnu.org
2023-11-15 12:40 ` jakub at gcc dot gnu.org
2023-11-15 12:47 ` sjames at gcc dot gnu.org
2023-11-27 11:08 ` acoplan at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-109882-4-kZLojiX6JX@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).