]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Reimplemented the _VKI_IOC_TYPECHECK() macro such that it doesn't trigger a
authorBart Van Assche <bvanassche@acm.org>
Tue, 15 Jun 2010 14:55:28 +0000 (14:55 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 15 Jun 2010 14:55:28 +0000 (14:55 +0000)
compiler warning on PPC when it shouldn't.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11180

include/vki/vki-arm-linux.h
include/vki/vki-linux.h
include/vki/vki-ppc32-linux.h
include/vki/vki-ppc64-linux.h
include/vki/vki-x86-linux.h

index ab745bbea8bede2ddd2e671065d642996b9a279c..65da4e037752a7d45e35354160d7472ee4325c94 100644 (file)
@@ -474,13 +474,6 @@ struct vki_termios {
         ((nr)   << _VKI_IOC_NRSHIFT) | \
         ((size) << _VKI_IOC_SIZESHIFT))
 
-/* provoke compile error for invalid uses of size argument */
-#define _VKI_IOC_TYPECHECK(t) \
-       ((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)
 #define _VKI_IOR(type,nr,size) _VKI_IOC(_VKI_IOC_READ,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
index 395a059da25a6bc46dcb94e892634826df3435aa..beff378b3140a14357bc157b35900d3cbef9cf9e 100644 (file)
 #  error Unknown platform
 #endif
 
+//----------------------------------------------------------------------
+// VKI_STATIC_ASSERT(). Inspired by BUILD_BUG_ON() from
+// linux-2.6.34/include/linux/kernel.h
+//----------------------------------------------------------------------
+
+/*
+ * Evaluates to zero if 'expr' is true and forces a compilation error if
+ * 'expr' is false. Can be used in a context where no comma expressions
+ * are allowed.
+ */
+#ifdef __cplusplus
+template <bool b> struct vki_static_assert { int m_bitfield:(2*b-1); };
+#define VKI_STATIC_ASSERT(expr)                         \
+    (sizeof(vki_static_assert<(expr)>) - sizeof(int))
+#else
+#define VKI_STATIC_ASSERT(expr) (sizeof(struct { int:-!(expr); }))
+#endif
+
+//----------------------------------------------------------------------
+// Based on _IOC_TYPECHECK() from linux-2.6.34/asm-generic/ioctl.h
+//----------------------------------------------------------------------
+
+/* provoke compile error for invalid uses of size argument */
+#define _VKI_IOC_TYPECHECK(t)                                           \
+    (VKI_STATIC_ASSERT((sizeof(t) == sizeof(t[1])                       \
+                        && sizeof(t) < (1 << _VKI_IOC_SIZEBITS)))       \
+     + sizeof(t))
+
 //----------------------------------------------------------------------
 // From linux-2.6.8.1/include/linux/compiler.h
 //----------------------------------------------------------------------
index 224397d69a6ff9fa836f79feb8bd4280594c9e18..858f9417a188b9e948217a7ef1133aa52f0916ef 100644 (file)
@@ -515,13 +515,6 @@ struct vki_termios {
          ((nr)   << _VKI_IOC_NRSHIFT) | \
          ((size) << _VKI_IOC_SIZESHIFT))
 
-/* provoke compile error for invalid uses of size argument */
-#define _VKI_IOC_TYPECHECK(t) \
-       ((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)
 #define _VKI_IOR(type,nr,size) _VKI_IOC(_VKI_IOC_READ,(type),(nr),(_VKI_IOC_TYPECHECK(size)))
index c310741e72645513bafb563196dce399d42c7a22..4d786bb242680638edc439eaa6ea005da9bfd250 100644 (file)
@@ -558,13 +558,6 @@ struct vki_termios {
          ((nr)   << _VKI_IOC_NRSHIFT) | \
          ((size) << _VKI_IOC_SIZESHIFT))
 
-/* provoke compile error for invalid uses of size argument */
-#define _VKI_IOC_TYPECHECK(t) \
-       ((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)
 #define _VKI_IOR(type,nr,size)      _VKI_IOC(_VKI_IOC_READ,(type),(nr), \
index e45a0ed639aa9fddc67408409fdb3e09dd0d4608..0d50529467122202408fbe48dadd2cac48f37e0a 100644 (file)
@@ -479,13 +479,6 @@ struct vki_termios {
         ((nr)   << _VKI_IOC_NRSHIFT) | \
         ((size) << _VKI_IOC_SIZESHIFT))
 
-/* provoke compile error for invalid uses of size argument */
-#define _VKI_IOC_TYPECHECK(t) \
-       ((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)
 #define _VKI_IOR(type,nr,size) _VKI_IOC(_VKI_IOC_READ,(type),(nr),(_VKI_IOC_TYPECHECK(size)))