From owner-freebsd-threads@FreeBSD.ORG Mon Jul 30 20:08:09 2012 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B63E5106566B; Mon, 30 Jul 2012 20:08:09 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 8913F8FC12; Mon, 30 Jul 2012 20:08:09 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id D339DB944; Mon, 30 Jul 2012 16:08:08 -0400 (EDT) From: John Baldwin To: freebsd-threads@freebsd.org Date: Mon, 30 Jul 2012 14:15:59 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p17; KDE/4.5.5; amd64; ; ) References: <201207221951.q6MJpuZl071441@red.freebsd.org> In-Reply-To: <201207221951.q6MJpuZl071441@red.freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201207301416.00168.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 30 Jul 2012 16:08:08 -0400 (EDT) Cc: freebsd-gnats-submit@freebsd.org, Ed Schouten , Ariane van der Steldt , David Chisnall Subject: Re: 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: Mon, 30 Jul 2012 20:08:09 -0000 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@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 Kicking this over to David and Ed who have worked on stdatomic.h. -- John Baldwin