|
From: <sv...@va...> - 2010-01-02 10:41:53
|
Author: sewardj
Date: 2010-01-02 10:41:46 +0000 (Sat, 02 Jan 2010)
New Revision: 10990
Log:
Redo r10971 ("Made sure that C++ compilers do not complain about the
_VKI_IOC_TYPECHECK() macro") in a way which is easier to understand.
Also, add it for arm-linux.
Modified:
trunk/include/vki/vki-arm-linux.h
trunk/include/vki/vki-ppc32-linux.h
trunk/include/vki/vki-ppc64-linux.h
trunk/include/vki/vki-x86-linux.h
Modified: trunk/include/vki/vki-arm-linux.h
===================================================================
--- trunk/include/vki/vki-arm-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
+++ trunk/include/vki/vki-arm-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
@@ -475,11 +475,11 @@
((size) << _VKI_IOC_SIZESHIFT))
/* provoke compile error for invalid uses of size argument */
-extern unsigned int __vki_invalid_size_argument_for_IOC;
#define _VKI_IOC_TYPECHECK(t) \
((sizeof(t) == sizeof(t[1]) && \
- sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) ? \
- sizeof(t) : __vki_invalid_size_argument_for_IOC)
+ sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
+ ? sizeof(t) \
+ : /*cause gcc to complain about division by zero*/(1/0) )
/* used to create numbers */
#define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
Modified: trunk/include/vki/vki-ppc32-linux.h
===================================================================
--- trunk/include/vki/vki-ppc32-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
+++ trunk/include/vki/vki-ppc32-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
@@ -517,8 +517,10 @@
/* provoke compile error for invalid uses of size argument */
#define _VKI_IOC_TYPECHECK(t) \
- (sizeof(t) / (sizeof(t) == sizeof(t[1]) && \
- sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))
+ ((sizeof(t) == sizeof(t[1]) && \
+ sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
+ ? sizeof(t) \
+ : /*cause gcc to complain about division by zero*/(1/0) )
/* used to create numbers */
#define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
Modified: trunk/include/vki/vki-ppc64-linux.h
===================================================================
--- trunk/include/vki/vki-ppc64-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
+++ trunk/include/vki/vki-ppc64-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
@@ -560,8 +560,10 @@
/* provoke compile error for invalid uses of size argument */
#define _VKI_IOC_TYPECHECK(t) \
- (sizeof(t) / (sizeof(t) == sizeof(t[1]) && \
- sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))
+ ((sizeof(t) == sizeof(t[1]) && \
+ sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
+ ? sizeof(t) \
+ : /*cause gcc to complain about division by zero*/(1/0) )
/* used to create numbers */
#define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
Modified: trunk/include/vki/vki-x86-linux.h
===================================================================
--- trunk/include/vki/vki-x86-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
+++ trunk/include/vki/vki-x86-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
@@ -481,8 +481,10 @@
/* provoke compile error for invalid uses of size argument */
#define _VKI_IOC_TYPECHECK(t) \
- (sizeof(t) / (sizeof(t) == sizeof(t[1]) && \
- sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))
+ ((sizeof(t) == sizeof(t[1]) && \
+ sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
+ ? sizeof(t) \
+ : /*cause gcc to complain about division by zero*/(1/0) )
/* used to create numbers */
#define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
|
|
From: Bart V. A. <bva...@ac...> - 2010-06-13 18:24:57
|
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
[ ... ]
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 ?
Bart.
On Sat, Jan 2, 2010 at 12:41 PM, <sv...@va...> wrote:
> Author: sewardj
> Date: 2010-01-02 10:41:46 +0000 (Sat, 02 Jan 2010)
> New Revision: 10990
>
> Log:
> Redo r10971 ("Made sure that C++ compilers do not complain about the
> _VKI_IOC_TYPECHECK() macro") in a way which is easier to understand.
> Also, add it for arm-linux.
>
>
>
> Modified:
> trunk/include/vki/vki-arm-linux.h
> trunk/include/vki/vki-ppc32-linux.h
> trunk/include/vki/vki-ppc64-linux.h
> trunk/include/vki/vki-x86-linux.h
>
>
> Modified: trunk/include/vki/vki-arm-linux.h
> ===================================================================
> --- trunk/include/vki/vki-arm-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
> +++ trunk/include/vki/vki-arm-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
> @@ -475,11 +475,11 @@
> ((size) << _VKI_IOC_SIZESHIFT))
>
> /* provoke compile error for invalid uses of size argument */
> -extern unsigned int __vki_invalid_size_argument_for_IOC;
> #define _VKI_IOC_TYPECHECK(t) \
> ((sizeof(t) == sizeof(t[1]) && \
> - sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) ? \
> - sizeof(t) : __vki_invalid_size_argument_for_IOC)
> + sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
> + ? sizeof(t) \
> + : /*cause gcc to complain about division by zero*/(1/0) )
>
> /* used to create numbers */
> #define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
>
> Modified: trunk/include/vki/vki-ppc32-linux.h
> ===================================================================
> --- trunk/include/vki/vki-ppc32-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
> +++ trunk/include/vki/vki-ppc32-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
> @@ -517,8 +517,10 @@
>
> /* provoke compile error for invalid uses of size argument */
> #define _VKI_IOC_TYPECHECK(t) \
> - (sizeof(t) / (sizeof(t) == sizeof(t[1]) && \
> - sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))
> + ((sizeof(t) == sizeof(t[1]) && \
> + sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
> + ? sizeof(t) \
> + : /*cause gcc to complain about division by zero*/(1/0) )
>
> /* used to create numbers */
> #define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
>
> Modified: trunk/include/vki/vki-ppc64-linux.h
> ===================================================================
> --- trunk/include/vki/vki-ppc64-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
> +++ trunk/include/vki/vki-ppc64-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
> @@ -560,8 +560,10 @@
>
> /* provoke compile error for invalid uses of size argument */
> #define _VKI_IOC_TYPECHECK(t) \
> - (sizeof(t) / (sizeof(t) == sizeof(t[1]) && \
> - sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))
> + ((sizeof(t) == sizeof(t[1]) && \
> + sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
> + ? sizeof(t) \
> + : /*cause gcc to complain about division by zero*/(1/0) )
>
> /* used to create numbers */
> #define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
>
> Modified: trunk/include/vki/vki-x86-linux.h
> ===================================================================
> --- trunk/include/vki/vki-x86-linux.h 2010-01-02 10:37:58 UTC (rev 10989)
> +++ trunk/include/vki/vki-x86-linux.h 2010-01-02 10:41:46 UTC (rev 10990)
> @@ -481,8 +481,10 @@
>
> /* provoke compile error for invalid uses of size argument */
> #define _VKI_IOC_TYPECHECK(t) \
> - (sizeof(t) / (sizeof(t) == sizeof(t[1]) && \
> - sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))
> + ((sizeof(t) == sizeof(t[1]) && \
> + sizeof(t) < (1 << _VKI_IOC_SIZEBITS)) \
> + ? sizeof(t) \
> + : /*cause gcc to complain about division by zero*/(1/0) )
>
> /* used to create numbers */
> #define _VKI_IO(type,nr) _VKI_IOC(_VKI_IOC_NONE,(type),(nr),0)
|
|
From: Julian S. <js...@ac...> - 2010-06-14 00:23:33
|
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? Only comment is that BUILD_BUG_ON is a terrible name (what does it mean?) I'd prefer STATIC_ASSERT or something similar. J |
|
From: Bart V. A. <bva...@ac...> - 2010-06-14 17:43:18
|
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.
Bart.
|
|
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.
|