Hello Bruce, * Bruce Evans <b...@optusnet.com.au>, 20111215 15:12: > The 2 bugs are: > 1. Even __offsetof() is broken in the fallback case (that's all cases > where it uses a struct like the above and doesn't use a gccish builtin). > This is because __offsetof() uses size_t, but size_t is not necessarily > in declared. offsetof() in <stddef.h>, etc. works because size_t is > necessarily declared there. BTW, the ifdef for __offsetof in > <stddef.h> is bogus since <sys/cdefs.h> is always included so > __offsetof is always defined. > > __size_t could be used, but that would give lots of pollution for > cdefs.h, and the file that declares __size_t, namely > <machine/types.h> is broken in fallback cases: > - recently broken for K&R since it now uses signed instead of __signed > - broken for longer for K&R and C90 since it uses long long. In working > versions, the __int64_t declarations were hacked for 32-bit machines > on to make them compile (but not work). Non-hacked versions should > simply not declare the 64-bit types if the compiler doesn't support > them.
Well, the dependency is circular, as <machine/_types.h> depends on <sys/cdefs.h> as well, so that's not a real solution. This is a bit blunt, but maybe we should simply use "unsigned long" there, under the assumption that on all architectures we support it is equal in size, and if not likely big enough to store the result. > CTASSERT() has regressed for compilers that don't support __COUNTER__, > since it uses this. Previously: > - CTASSERT() never worked for K&R compilers, since it uses C90 token pasting > - CTASSERT() worked for all C90 and later compilers. Yes. I am considering merging back the __COUNTER__ fix to FreeBSD 9 after it has been released, so it shouldn't be too bad. Basically we have to make a trade-off: - Make it possible to use CTASSERT() and _Static_assert() in more places throughout the tree (headers), or - support CTASSERT() and _Static_assert() for non-default compilers that are older than GCC 4.3. I suspect that if people switch to non-default compilers to build FreeBSD sources, they aren't doing it because they want to use an older version of GCC. > Check the sorting of the new macros, especially __alignof(). I think > the ordering should be mostly on the gcc and standards version, not on > the order in which the macros were added to cdefs.h. You sorted the 2.95 > ifdef before a 2.96 ifdef, but this 2.96 ifdef is especially disordered > according to my rule. Even if the order is "logical" instead of historical, > it makes more sense to define basic macros like __alignof() before using > them. I've placed it right above the C1X block now. %%% Index: sys/sys/cdefs.h =================================================================== --- sys/sys/cdefs.h (revision 228530) +++ sys/sys/cdefs.h (working copy) @@ -218,6 +218,10 @@ #endif #endif +#if !__GNUC_PREREQ__(2, 95) +#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) +#endif + /* * Keywords added in C1X. */ @@ -230,24 +234,17 @@ #elif defined(__STDC_VERSION__) && __STDC_VERSION__ > 201000L /* Do nothing. They are language keywords. */ #else -/* Not supported. Implement them manually. */ -#ifdef __GNUC__ -#define _Alignas(e) __attribute__((__aligned__(e))) -#define _Alignof(e) __alignof__(e) -#define _Noreturn __attribute__((__noreturn__)) +/* Not supported. Implement them using our versions. */ +#define _Alignas(x) __aligned(x) +#define _Alignof(x) __alignof(x) +#define _Noreturn __dead2 #define _Thread_local __thread -#else -#define _Alignas(e) -#define _Alignof(e) __offsetof(struct { char __a; e __b; }, __b) -#define _Noreturn -#define _Thread_local -#endif #ifdef __COUNTER__ -#define _Static_assert(e, s) __Static_assert(e, __COUNTER__) -#define __Static_assert(e, c) ___Static_assert(e, c) -#define ___Static_assert(e, c) typedef char __assert ## c[(e) ? 1 : -1] +#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 ## c[(x) ? 1 : -1] #else -#define _Static_assert(e, s) +#define _Static_assert(x, y) struct __hack #endif #endif %%% -- Ed Schouten <e...@80386.nl> WWW: http://80386.nl/
pgpTcW4wwTWAv.pgp
Description: PGP signature