[PATCH 4/4] libtests/malloctest/init.c: Fix warning v2

Joel Sherrill joel.sherrill at oarcorp.com
Thu Nov 20 16:32:16 UTC 2014


Gedare.. does this look better?

posix_memalign() is prototyped to take a non-NULL parameter. But our
test is deliberately passing one in. With the -Wnon-null warning flag
enabled, we will always get warnings on this test unless we disable
that warning for this single test case.
---
 testsuites/libtests/malloctest/init.c | 24 ++++++++++--------------
 testsuites/support/include/tmacros.h  | 32 +++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/testsuites/libtests/malloctest/init.c b/testsuites/libtests/malloctest/init.c
index 0d95e3b..399cdd5 100644
--- a/testsuites/libtests/malloctest/init.c
+++ b/testsuites/libtests/malloctest/init.c
@@ -1,17 +1,5 @@
-/*  Init
- *
- *  This routine is the initialization task for this test program.
- *  It is a user initialization task and has the responsibility for creating
- *  and starting the tasks that make up the test.  If the time of day
- *  clock is required for the test, it should also be set to a known
- *  value by this function.
- *
- *  Input parameters:
- *    argument - task argument
- *
- *  Output parameters:  NONE
- *
- *  COPYRIGHT (c) 1989-2011.
+/* 
+ *  COPYRIGHT (c) 1989-2011, 2014.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  Copyright (c) 2009, 2010 embedded brains GmbH.
@@ -1188,9 +1176,17 @@ static void test_posix_memalign(void)
   int sc;
   int maximumShift;
 
+  /*
+   * posix_memalign() is declared as never having a NULL first parameter.
+   * We need to explicitly disable this compiler warning to make this code
+   * warning free.
+   */
+  COMPILER_DIAGNOSTIC_SETTINGS_PUSH
+  COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL
   puts( "posix_memalign - NULL return pointer -- EINVAL" );
   sc = posix_memalign( NULL, 32, 8 );
   fatal_posix_service_status( sc, EINVAL, "posix_memalign NULL pointer" );
+  COMPILER_DIAGNOSTIC_SETTINGS_POP
 
   puts( "posix_memalign - alignment of 0 -- EINVAL" );
   sc = posix_memalign( &p1, 0, 8 );
diff --git a/testsuites/support/include/tmacros.h b/testsuites/support/include/tmacros.h
index 91f23e0..4524cf9 100644
--- a/testsuites/support/include/tmacros.h
+++ b/testsuites/support/include/tmacros.h
@@ -1,9 +1,12 @@
-/*  tmacros.h
+/**
+ * @file
  *
- *  This include file contains macros which are useful in the RTEMS
- *  test suites.
- *
- *  COPYRIGHT (c) 1989-2009.
+ * This include file contains macros which are useful in the RTEMS
+ * test suites.
+ */
+
+/*
+ *  COPYRIGHT (c) 1989-2014.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
@@ -297,6 +300,25 @@ extern "C" {
 /* newlib's ino_t is a typedef to "unsigned long" */
 #define PRIxino_t "lx"
 
+/**
+ * This assists in clearly disabling warnings on GCC in certain very
+ * specific cases.
+ *
+ * + -Wnon-null - If a method is declared as never having a NULL first
+ *   parameter. We need to explicitly disable this compiler warning to make
+ *   the code warning free.
+ */
+#ifdef __GNUC__
+  #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH _Pragma("GCC diagnostic push")
+  #define COMPILER_DIAGNOSTIC_SETTINGS_POP _Pragma("GCC diagnostic pop")
+  #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL \
+    _Pragma("GCC diagnostic ignored \"-Wnonnull\"")
+#else
+  #define COMPILER_DIAGNOSTIC_SETTINGS_PUSH
+  #define COMPILER_DIAGNOSTIC_SETTINGS_POP
+  #define COMPILER_DIAGNOSTIC_SETTINGS_DISABLE_NONNULL
+#endif
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.9.3



More information about the devel mailing list