Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Dec 2011 15:44:43 +0100
From:      Ed Schouten <ed@80386.nl>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r228495 - head/sys/sys
Message-ID:  <20111215144443.GQ1771@hoeg.nl>
In-Reply-To: <20111216000117.R2632@besplex.bde.org>
References:  <201112140909.pBE99bS3090646@svn.freebsd.org> <20111214234615.B3839@besplex.bde.org> <20111215122047.GN1771@hoeg.nl> <20111216000117.R2632@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--Tcb1KvpfnM4LxW2s
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hello Bruce,

* Bruce Evans <brde@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.
>=20
>    __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 worki=
ng
>      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 past=
ing
> - 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 historic=
al,
> 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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/sys/cdefs.h	(revision 228530)
+++ sys/sys/cdefs.h	(working copy)
@@ -218,6 +218,10 @@
 #endif
 #endif
=20
+#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
=20
%%%

--=20
 Ed Schouten <ed@80386.nl>
 WWW: http://80386.nl/

--Tcb1KvpfnM4LxW2s
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)

iQIcBAEBAgAGBQJO6gfbAAoJEG5e2P40kaK7lZAQAIGUkZcXQooERo/IIcHo8Rgd
E6NO5Al4h4DT0gj2JLnetyffaTUQSe4Zpz1iZ3lXpNDepVeFg3zM7H2x18dpnCBx
oEsPIQOyW5NIQCq9J9kuYzBSDz1w08j65yAtBnaTqxgsb4ybbFcuAg17NzxHPl40
NCcjfNgiPJTSlQXaqmSv1oRmQ1yKQWJjnp/BFaW6ZsKK5OsYLjMYF29mW2sgpGfE
Q8x3EXdBUo3lruaYo5QMubtFaGUP+ylN/Uwo0phckAKaBJ0Hi+L3IsMLmM2WHxal
MSepf8IgxJh4NM875Lz9AVA39uDbxm0QU87UbOeFQT0VoMxfCmkY6RIIhz+vXtPw
Kn2ngnDozCGhpF7QuJ0OuM6euez+SKyxZSCfHGJNJT9RDn9mD+twQerm6uWXDope
Iqdf4+FmSd0fHxTfnWdczKmWAbP96ZSc08pQeKkLA9aQtkGl8laHGKxp/nVACrZp
peSR2N/dpYiqajk1WtvEX+5EN/LQLT5ErVM8BqSbS05kmVTvpQxUUI93N1JeYwxg
x2dSPGRuV8K7fcqXQ3QwQFxjRTxpNb6wtMj+db2Oh/ePT05DtJxKkK53UmXH3yPa
8LV/bXK8wIK9Opgtd4Q3iVpk21aqDmrgkSRlN+P5zU8rv7xuW8kXsLB5NEOirMQe
3yfhVlWoljhGh0YSbrIW
=Dafc
-----END PGP SIGNATURE-----

--Tcb1KvpfnM4LxW2s--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111215144443.GQ1771>