|
From: Bart V. A. <bva...@ac...> - 2010-06-14 19:08:13
|
On Mon, Jun 14, 2010 at 7:43 PM, Bart Van Assche <bva...@ac...> wrote:
>
> On Mon, Jun 14, 2010 at 2:20 AM, Julian Seward <js...@ac...> wrote:
> >
> > On Sunday, June 13, 2010, Bart Van Assche wrote:
> > > It took some time before I noticed, but the patch below triggers the
> > > following warnings during compilation on PPC (make check):
> > >
> > > [ ... ]
> > > g++ -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../include -I../../coregrind
> > > -I../ ../include -I../../VEX/pub -DVGA_ppc64=1 -DVGO_linux=1
> > > -DVGP_ppc64_linux=1 -Win line -Wall -Wshadow -g -m64 -g -O2 -MT
> > > valgrind_cpp_test.o -MD -MP -MF .deps/val grind_cpp_test.Tpo -c -o
> > > valgrind_cpp_test.o valgrind_cpp_test.cpp In file included from
> > > ../../include/pub_tool_vki.h:49,
> > > from valgrind_cpp_test.cpp:14:
> > > ../../include/vki/vki-linux.h:2159: warning: division by zero
> > > ../../include/vki/vki-linux.h:2162: warning: division by zero
> > > [ ... ]
> >
> > (btw, I'm sure Konstantin S et al grappled with this at some time in
> > the past.)
> >
> > > Would it be OK to rewrite the _VKI_IOC_TYPECHECK() macro and to base
> > > it on something similar to BUILD_BUG_ON() as present in the Linux
> > > kernel ?
> >
> > Sounds good. This is the old trick where for doing compile time
> > assertions, in resulting in declaration of an array of size -1 if
> > the assertion fails, yes?
>
> That trick worked until gcc allowed variable length arrays. The
> addition of support for variable length arrays in gcc caused gcc no
> longer to complain when the tested expression is not a constant. The
> current definition of BUILD_BUG_ON() is as follows:
>
> /* Force a compilation error if condition is true */
> #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition))
> * Force a compilation error if condition is true, but also produce a
> result (of value 0 and type size_t), so the expression can be used
> e.g. in a structure initializer (or where-ever else comma expressions
> aren't permitted). */
> #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
>
> For more information, see also:
> * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=include/linux/kernel.h
> * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=8c87df457cb58fe75b9b893007917cf8095660a0.
>
> > Only comment is that BUILD_BUG_ON is a terrible name (what does it
> > mean?) I'd prefer STATIC_ASSERT or something similar.
>
> Agreed.
Apparently this is not as easy to fix as I thought. The macros
#define VKI_STATIC_ASSERT(expr) (sizeof(struct { int:-!(expr); }))
#define _VKI_IOC_TYPECHECK(t) \
(VKI_STATIC_ASSERT((sizeof(t) == sizeof(t[1]) \
&& sizeof(t) < (1 << _VKI_IOC_SIZEBITS))) \
+ sizeof(t))
result in the following warnings on PPC during make check:
In file included from ../../include/pub_tool_vki.h:49,
from valgrind_cpp_test.cpp:14:
../../include/vki/vki-linux.h:2159: error: types may not be defined in
'sizeof' expressions
../../include/vki/vki-linux.h:2162: error: types may not be defined in
'sizeof' expressions
Bart.
Bart.
|