|
From: <sv...@va...> - 2010-06-15 14:55:40
|
Author: bart
Date: 2010-06-15 15:55:28 +0100 (Tue, 15 Jun 2010)
New Revision: 11180
Log:
Reimplemented the _VKI_IOC_TYPECHECK() macro such that it doesn't trigger a
compiler warning on PPC when it shouldn't.
Modified:
trunk/include/vki/vki-arm-linux.h
trunk/include/vki/vki-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-06-15 13:02:48 UTC (rev 11179)
+++ trunk/include/vki/vki-arm-linux.h 2010-06-15 14:55:28 UTC (rev 11180)
@@ -474,13 +474,6 @@
((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)))
Modified: trunk/include/vki/vki-linux.h
===================================================================
--- trunk/include/vki/vki-linux.h 2010-06-15 13:02:48 UTC (rev 11179)
+++ trunk/include/vki/vki-linux.h 2010-06-15 14:55:28 UTC (rev 11180)
@@ -94,6 +94,34 @@
#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
//----------------------------------------------------------------------
Modified: trunk/include/vki/vki-ppc32-linux.h
===================================================================
--- trunk/include/vki/vki-ppc32-linux.h 2010-06-15 13:02:48 UTC (rev 11179)
+++ trunk/include/vki/vki-ppc32-linux.h 2010-06-15 14:55:28 UTC (rev 11180)
@@ -515,13 +515,6 @@
((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)))
Modified: trunk/include/vki/vki-ppc64-linux.h
===================================================================
--- trunk/include/vki/vki-ppc64-linux.h 2010-06-15 13:02:48 UTC (rev 11179)
+++ trunk/include/vki/vki-ppc64-linux.h 2010-06-15 14:55:28 UTC (rev 11180)
@@ -558,13 +558,6 @@
((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), \
Modified: trunk/include/vki/vki-x86-linux.h
===================================================================
--- trunk/include/vki/vki-x86-linux.h 2010-06-15 13:02:48 UTC (rev 11179)
+++ trunk/include/vki/vki-x86-linux.h 2010-06-15 14:55:28 UTC (rev 11180)
@@ -479,13 +479,6 @@
((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)))
|