From owner-freebsd-threads@FreeBSD.ORG Sun Jul 22 20:00:19 2012 Return-Path: Delivered-To: freebsd-threads@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3328D106564A for ; Sun, 22 Jul 2012 20:00:19 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E8F6C8FC18 for ; Sun, 22 Jul 2012 20:00:18 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q6MK0I6f040592 for ; Sun, 22 Jul 2012 20:00:18 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q6MK0IMo040590; Sun, 22 Jul 2012 20:00:18 GMT (envelope-from gnats) Resent-Date: Sun, 22 Jul 2012 20:00:18 GMT Resent-Message-Id: <201207222000.q6MK0IMo040590@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-threads@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ariane van der Steldt Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 951991065672 for ; Sun, 22 Jul 2012 19:51:57 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 80B1C8FC16 for ; Sun, 22 Jul 2012 19:51:57 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q6MJpumd071442 for ; Sun, 22 Jul 2012 19:51:56 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q6MJpuZl071441; Sun, 22 Jul 2012 19:51:56 GMT (envelope-from nobody) Message-Id: <201207221951.q6MJpuZl071441@red.freebsd.org> Date: Sun, 22 Jul 2012 19:51:56 GMT From: Ariane van der Steldt To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: threads/170073: stdatomic.h doesn't use clang builtings for C X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Jul 2012 20:00:19 -0000 >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 #include -#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: