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

            Bug ID: 96952
           Summary: __builtin_thread_pointer support cannot be probed
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sorear at fastmail dot com
  Target Milestone: ---

I would like to use __builtin_thread_pointer instead of inline asm to access
the thread pointer (concretely, in kernel or libc code for risc-v), but it's
only supported by extremely recent versions of gcc and clang.  So, I would like
to detect it at compile time, but this does not work:

#if __has_builtin(__builtin_thread_pointer)
void *get_tp() { return __builtin_thread_pointer(); }
#else
/* inline asm fallback */
#endif

x.c: In function 'get_tp':
x.c:2:25: error: '__builtin_thread_pointer' is not supported on this target
    2 | void *get_tp() { return __builtin_thread_pointer(); }
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~

__has_builtin seems to be falsely returning true?

Reply via email to