threads/170073: stdatomic.h doesn't use clang builtings for C
John Baldwin
jhb at freebsd.org
Mon Jul 30 20:08:09 UTC 2012
On Sunday, July 22, 2012 3:51:56 pm Ariane van der Steldt wrote:
>
> >Number: 170073
> >Category: threads
> >Synopsis: stdatomic.h doesn't use clang builtings for C
> >Confidential: no
> >Severity: non-critical
> >Priority: low
> >Responsible: freebsd-threads
> >State: open
> >Quarter:
> >Keywords:
> >Date-Required:
> >Class: sw-bug
> >Submitter-Id: current-users
> >Arrival-Date: Sun Jul 22 20:00:18 UTC 2012
> >Closed-Date:
> >Last-Modified:
> >Originator: Ariane van der Steldt
> >Release: freebsd HEAD
> >Organization:
> >Environment:
> FreeBSD mud.stack.nl 9.0-STABLE FreeBSD 9.0-STABLE #0: Thu Jun 14 13:51:30
CEST 2012 root at mud.stack.nl:/usr/obj/usr/src/sys/GENERIC amd64
> >Description:
> First a little disclaimer: I tested this with clang-3.1 on bitrig. The
freebsd I ran this on is using clang-3.0 which does returns 0 for the
c{,xx}_atomic feature/extension.
>
> stdatomic.h tests for __has_feature(cxx_atomic) which is only true when
compiling in c++11 mode.
> However since stdatomic.h is a C header file, it should also work in c11
mode.
>
> Running:
> echo '__has_feature(cxx_atomic)' | clang-3.1 -x c -std=c11 -E -
> yields 0, while running:
> echo '__has_feature(c_atomic)' | clang-3.1 -x c -std=c11 -E -
> yields 1.
>
> In addition, I'm contemplating if __has_feature should be replaced by
__has_extension, so that non-c11 code can also include stdatomic.h.
> >How-To-Repeat:
> Run the clang 3.1 preprocessor on stdatomic.h for C code and it will use the
GNU counterparts of the contained code. Running the same code through the
clang++ 3.1 preprocessor yields the clang counterpart of the code.
> >Fix:
> See provided diff below, using __has_extension instead of __has_feature.
> This also requires a compatibility define in sys/cdefs.h:
> #ifndef __has_extension
> #define __has_extension(x) 0
> #endif
>
>
> diff --git a/include/stdatomic.h b/include/stdatomic.h
> index b0d1ea9..89f77dd 100644
> --- a/include/stdatomic.h
> +++ b/include/stdatomic.h
> @@ -33,7 +33,7 @@
> #include <sys/cdefs.h>
> #include <sys/_types.h>
>
> -#if __has_feature(cxx_atomic)
> +#if __has_extension(c_atomic) || __has_extension(cxx_atomic)
> #define __CLANG_ATOMICS
> #elif __GNUC_PREREQ__(4, 7)
> #define __GNUC_ATOMICS
Kicking this over to David and Ed who have worked on stdatomic.h.
--
John Baldwin
More information about the freebsd-threads
mailing list