]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix AssertOnCompileFailed for GCC 4.8 (kernel 3.10+)
authorVMware, Inc <>
Wed, 18 Sep 2013 03:35:40 +0000 (20:35 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:26:42 +0000 (22:26 -0700)
GCC 4.8 now includes -Wunused-local-typedefs as part of -Wall.  This
causes it to spew a gazillion warnings when compiling our modules on
3.10+ kernels.  Because it's a typedef we can't use the (void) cast
trick, so we need to use attributes.  This change introduces
UNUSED_TYPE to vm_basic_types.h and uses it where appropriate to make
the compiler happy when building our modules.

Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/include/vm_assert.h
open-vm-tools/lib/include/vm_atomic.h
open-vm-tools/lib/include/vm_basic_types.h

index d0980426ff11a6844dc4a2a3a878f301583e2a96..734bcc88f4aa917fce7ba1b1089c8b225d8c6632 100644 (file)
@@ -369,12 +369,17 @@ do {                                                        \
  * The implementation uses both enum and typedef because the typedef alone is
  * insufficient; gcc allows arrays to be declared with non-constant expressions
  * (even in typedefs, where it makes no sense).
+ *
+ * NOTE: if GCC ever changes so that it ignores unused types altogether, this
+ * assert might not fire!  We explicitly mark it as unused because GCC 4.8+
+ * uses -Wunused-local-typedefs as part of -Wall, which means the typedef will
+ * generate a warning.
  */
 
 #define ASSERT_ON_COMPILE(e) \
    do { \
       enum { AssertOnCompileMisused = ((e) ? 1 : -1) }; \
-      typedef char AssertOnCompileFailed[AssertOnCompileMisused]; \
+      UNUSED_TYPE(typedef char AssertOnCompileFailed[AssertOnCompileMisused]); \
    } while (0)
 
 
index 81ea4b6a06c4c5e2a99a9628629978e3f25e020e..6bef6301c45acd708384915d71d5c80bef4e1d31 100644 (file)
@@ -2640,6 +2640,9 @@ Atomic_TestBit64(Atomic_uint64 *var, // IN
  * (void *)val, we have (void *)(uintptr_t)val.
  * The specific problem case is the Windows ddk compiler
  * (as used by the SVGA driver).  -- edward
+ *
+ * NOTE: See the comment in vm_assert.h for why we need UNUSED_TYPE in
+ * AtomicAssertOnCompile(), and why we need to be very careful doing so.
  */
 
 #define MAKE_ATOMIC_TYPE(name, size, in, out, cast)                           \
@@ -2653,7 +2656,7 @@ Atomic_TestBit64(Atomic_uint64 *var, // IN
                                       && 8 * sizeof (out) == size             \
                                       && 8 * sizeof (cast) == size            \
                                          ? 1 : -1 };                          \
-      typedef char AssertOnCompileFailed[AssertOnCompileMisused];             \
+      UNUSED_TYPE(typedef char AssertOnCompileFailed[AssertOnCompileMisused]);\
    }                                                                          \
                                                                               \
                                                                               \
index d2093cbc57daf75ac4a66e783141f86e26f0a596..2f40dbdcd79fd8bb14a2716a53ccfd98e1f76e5e 100644 (file)
@@ -835,6 +835,11 @@ typedef void * UserVA;
 # endif
 #endif
 
+#ifndef UNUSED_TYPE
+// XXX _Pragma would better but doesn't always work right now.
+#  define UNUSED_TYPE(_parm) UNUSED_PARAM(_parm)
+#endif
+
 #ifndef UNUSED_VARIABLE
 // XXX is there a better way?
 #  define UNUSED_VARIABLE(_var) (void)_var