From owner-svn-src-all@FreeBSD.ORG Sun Mar 18 09:19:40 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A173D1065670; Sun, 18 Mar 2012 09:19:40 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9001E8FC08; Sun, 18 Mar 2012 09:19:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q2I9Jenn010663; Sun, 18 Mar 2012 09:19:40 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q2I9Je7I010661; Sun, 18 Mar 2012 09:19:40 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201203180919.q2I9Je7I010661@svn.freebsd.org> From: Ed Schouten Date: Sun, 18 Mar 2012 09:19:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233108 - stable/9/sys/sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Sun, 18 Mar 2012 09:19:40 -0000 Author: ed Date: Sun Mar 18 09:19:40 2012 New Revision: 233108 URL: http://svn.freebsd.org/changeset/base/233108 Log: MFC r228322,228330,228477,228495,228562,228564,228859,228897,229574,230277: Bring in sync with FreeBSD HEAD: - Add an __alignof() for non-GCC and GCC < 2.95. - Attempt to implement the following C11 keywords: _Alignas(), _Alignof(), _Noreturn, _Static_assert() and _Thread_local. - Add __generic(), which allows us to do _Generic() in a portable fashion. - Improve __offsetof(), __DECONST(), __DEVOLATILE() and __DEQUALIFY() to use __uintptr_t and __size_t to make them work with less header prerequisites. - Add __has_feature(), __has_include() and __has_builtin() to make it easier to test against Clang features. Tested by: linimon@'s exp-run (thanks!) Modified: stable/9/sys/sys/cdefs.h Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/sys/cdefs.h ============================================================================== --- stable/9/sys/sys/cdefs.h Sun Mar 18 08:08:06 2012 (r233107) +++ stable/9/sys/sys/cdefs.h Sun Mar 18 09:19:40 2012 (r233108) @@ -218,6 +218,54 @@ #endif #endif +#if !__GNUC_PREREQ__(2, 95) +#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) +#endif + +/* + * 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) +#define _Thread_local thread_local +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +/* Do nothing. They are language keywords. */ +#else +/* Not supported. Implement them using our versions. */ +#define _Alignas(x) __aligned(x) +#define _Alignof(x) __alignof(x) +#define _Noreturn __dead2 +#define _Thread_local __thread +#ifdef __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] +#else +#define _Static_assert(x, y) struct __hack +#endif +#endif + +/* + * Emulation of C11 _Generic(). Unlike the previously defined C11 + * keywords, it is not possible to implement this using exactly the same + * syntax. Therefore implement something similar under the name + * __generic(). Unlike _Generic(), this macro can only distinguish + * between a single type, so it requires nested invocations to + * distinguish multiple cases. + */ + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +#define __generic(expr, t, yes, no) \ + _Generic(expr, t: yes, default: no) +#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) +#define __generic(expr, t, yes, no) \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(__typeof(expr), t), yes, no) +#endif + #if __GNUC_PREREQ__(2, 96) #define __malloc_like __attribute__((__malloc__)) #define __pure __attribute__((__pure__)) @@ -319,10 +367,11 @@ #define __offsetof(type, field) __builtin_offsetof(type, field) #else #ifndef __cplusplus -#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) +#define __offsetof(type, field) \ + ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) #else #define __offsetof(type, field) \ - (__offsetof__ (reinterpret_cast \ + (__offsetof__ (reinterpret_cast <__size_t> \ (&reinterpret_cast \ (static_cast (0)->field)))) #endif @@ -450,15 +499,15 @@ #endif #ifndef __DECONST -#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) +#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) #endif #ifndef __DEVOLATILE -#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) +#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) #endif #ifndef __DEQUALIFY -#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) +#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) #endif /*- @@ -574,4 +623,14 @@ #endif #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 + #endif /* !_SYS_CDEFS_H_ */