From owner-svn-src-all@FreeBSD.ORG Mon May 13 21:46:08 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 5B2C7990; Mon, 13 May 2013 21:46:08 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 4D751CEE; Mon, 13 May 2013 21:46:08 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4DLk8vt004009; Mon, 13 May 2013 21:46:08 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4DLk8FK004008; Mon, 13 May 2013 21:46:08 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201305132146.r4DLk8FK004008@svn.freebsd.org> From: Ed Schouten Date: Mon, 13 May 2013 21:46:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250623 - head/sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 May 2013 21:46:08 -0000 Author: ed Date: Mon May 13 21:46:07 2013 New Revision: 250623 URL: http://svnweb.freebsd.org/changeset/base/250623 Log: Rework the way C11 keywords are defined. Instead of only checking the __STDC_VERSION__, we can also use Clang's __has_extension() to check for features specifically. This allows us to, say, use Clang's native _Static_assert() instead of the typedef hack, making the compiler error messages a lot more readable. Reviewed by: theraven Modified: head/sys/sys/cdefs.h Modified: head/sys/sys/cdefs.h ============================================================================== --- head/sys/sys/cdefs.h Mon May 13 21:44:59 2013 (r250622) +++ head/sys/sys/cdefs.h Mon May 13 21:46:07 2013 (r250623) @@ -36,6 +36,23 @@ #ifndef _SYS_CDEFS_H_ #define _SYS_CDEFS_H_ +/* + * Testing against Clang-specific extensions. + */ + +#ifndef __has_extension +#define __has_extension __has_feature +#endif +#ifndef __has_feature +#define __has_feature(x) 0 +#endif +#ifndef __has_include +#define __has_include(x) 0 +#endif +#ifndef __has_builtin +#define __has_builtin(x) 0 +#endif + #if defined(__cplusplus) #define __BEGIN_DECLS extern "C" { #define __END_DECLS } @@ -232,22 +249,36 @@ /* * Keywords added in C11. */ -#if defined(__cplusplus) && __cplusplus >= 201103L -#define _Alignas(e) alignas(e) -#define _Alignof(e) alignof(e) -#define _Noreturn [[noreturn]] -#define _Static_assert(e, s) static_assert(e, s) -/* FIXME: change this to thread_local when clang in base supports it */ -#define _Thread_local __thread -#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L -/* Do nothing. They are language keywords. */ + +#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L + +#if !__has_extension(c_alignas) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_alignas) +#define _Alignas(x) alignas(x) #else -/* Not supported. Implement them using our versions. */ +/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ #define _Alignas(x) __aligned(x) +#endif +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Alignof(x) alignof(x) +#else #define _Alignof(x) __alignof(x) +#endif + +#if defined(__cplusplus) && __cplusplus >= 201103L +#define _Noreturn [[noreturn]] +#else #define _Noreturn __dead2 -#define _Thread_local __thread -#ifdef __COUNTER__ +#endif + +#if !__has_extension(c_static_assert) +#if (defined(__cplusplus) && __cplusplus >= 201103L) || \ + __has_extension(cxx_static_assert) +#define _Static_assert(x, y) static_assert(x, y) +#elif defined(__COUNTER__) #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) #define __Static_assert(x, y) ___Static_assert(x, y) #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] @@ -256,6 +287,20 @@ #endif #endif +#if !__has_extension(c_thread_local) +/* XXX: Change this to test against C++11 when clang in base supports it. */ +#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ + __has_extension(cxx_thread_local) +#define _Thread_local thread_local +#elif defined(lint) +#define _Thread_local +#else +#define _Thread_local __thread +#endif +#endif + +#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ + /* * Emulation of C11 _Generic(). Unlike the previously defined C11 * keywords, it is not possible to implement this using exactly the same @@ -682,19 +727,6 @@ #endif #endif -#ifndef __has_extension -#define __has_extension __has_feature -#endif -#ifndef __has_feature -#define __has_feature(x) 0 -#endif -#ifndef __has_include -#define __has_include(x) 0 -#endif -#ifndef __has_builtin -#define __has_builtin(x) 0 -#endif - #if defined(__mips) || defined(__powerpc64__) #define __NO_TLS 1 #endif