Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Nov 2013 20:02:25 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Dimitry Andric <dim@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r258016 - head/sys/i386/conf
Message-ID:  <20131112190919.D1059@besplex.bde.org>
In-Reply-To: <201311112116.rABLGulr021023@svn.freebsd.org>
References:  <201311112116.rABLGulr021023@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 11 Nov 2013, Dimitry Andric wrote:

> Log:
>  Disable building the ctl module for the i386 XEN kernel configuration
>  for now, since it causes gcc warnings about casting 64 bit bus_addr_t's
>  to 32 bit pointers, and vice versa.

Why not disable clang, since it is incompatible? :-)/2

The warning is needed because detecting invalid conversions between pointers
and integers is difficult without it.  You have to cast to prevent errors,
but it is too easy to use a cast that doesn't work.

Similarly for -Wcast-qual, except an error for it is less needed.  This
is broken in clang too:

 	void *p;
 	const void *q;

 	/* Constraint error (C90 6.3.16.1): */
 	p = q;
 	/*
 	 * This is correctly handled by TenDRA (4.2*).  It is an error, and
 	 * TenDRA tells you the C90 section.
 	 *
 	 * This is incorrectly handled by gcc.  It is only a warning (even
 	 * with -pedantic).  gcc doesn't tell you the standard section.
 	 *
 	 * This is incorrectly handled by clang.  It is only a warning (even
 	 * with -pedantic).  clang doesn't tell you the standard section.
 	 * It prints more verbose and less useful message telling you that
 	 * this is controlled by
 	 * -Wincompatible-pointer-types-discards-qualifiers.  Turning this
 	 * off gives a non-C compiler that doesn't even warn for the error.
 	 */

 	/* Cast to prevent the error: */
 	p = (void *)q;
 	/*
 	 * This quietens TenDRA, gcc and clang.
 	 *
 	 * This can be be too quiet, so gcc has a -Wcast-qual feature to
 	 * turn the warning back on.  FreeBSD uses this excessively, and
 	 * this has resulted in some correct const poisoning and some
 	 * abominations like __DECONST() and its use.
 	 *
 	 * But -Wcast-qual is just broken in clang.  It has no effect for
 	 * the above, even with -pedantic.  I don't know of any
 	 * -Wno-broken-cast-qual flag to fix this.
 	 */

 	/* The error can also be prevented by casting through an integer: */
 	p = (void *)(void *)(uintptr_t)(const volatile void *)q;
 	/*
 	 * First we cast to (const volatile void *) to get a pointer on which
 	 * uintptr_t is useful (in case q is not already a qualified void *).
 	 * Then we cast to uintptr_t.  This exploits the bug that -Wcast-qual
 	 * is broken for conversions to integers even for gcc.  There should
 	 * be a way to avoid -Wcast-qual, but not this normal cast.  The
 	 * __DE*() abominations use this.  Then we cast to (void *) to get
 	 * the same result as casting the original pointer to (void *) without
 	 * the -Wcast-qual warning.  The __DE*() abominations are ugly, but
 	 * not ugly enough to do this correctly.  They assume that all pointers
 	 * have the same representation.  Finally, we cast to the lvalue's
 	 * type, in case this is not (void *).  __DE*() has a parameter for
 	 * this.  Actually, this step is not needed, except in C++ or when
 	 * the final type is an integer (this integer type must be either
 	 * intptr_t or uintptr_t to work and to avoid warnings from gcc).
 	 */

Bruce



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