Date: Sun, 22 Jul 2012 19:51:56 GMT From: Ariane van der Steldt <ariane@stack.nl> To: freebsd-gnats-submit@FreeBSD.org Subject: threads/170073: stdatomic.h doesn't use clang builtings for C Message-ID: <201207221951.q6MJpuZl071441@red.freebsd.org> Resent-Message-ID: <201207222000.q6MK0IMo040590@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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@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 >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201207221951.q6MJpuZl071441>