Bug 1318979 - Suppress unused dummy variable warnings, r=kaie
authorMartin Thomson <martin.thomson@gmail.com>
Mon, 21 Nov 2016 12:30:21 +1100
changeset 4711 0835554ac65ebbf1875c37454f34f315fbb514a6
parent 4710 8319f7a459dc64fd6d62e24381d114b460e9fb9d
child 4712 271a33c4c9a40299f481ec9c151673ae5aa14605
push id234
push usermartin.thomson@gmail.com
push dateThu, 16 Mar 2017 04:01:16 +0000
reviewerskaie
bugs1318979
Bug 1318979 - Suppress unused dummy variable warnings, r=kaie
configure
configure.in
lib/ds/plvrsion.c
lib/libc/src/plvrsion.c
lib/prstreams/plvrsion.c
pr/src/prvrsion.c
--- a/configure
+++ b/configure
@@ -5419,16 +5419,50 @@ rm -f core conftest.err conftest.$ac_obj
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_res" >&5
 $as_echo "$_res" >&6; }
 else
     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pragma diagnostic" >&5
+$as_echo_n "checking for pragma diagnostic... " >&6; }
+if test "$GNU_CC" = "1"; then
+    cat >dummy-hello.c <<EOF
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+int main() {
+    char *dummy = "";
+    return 0;
+}
+EOF
+    ${CC} -Werror=unused-but-set-variable -S dummy-hello.c -o dummy-hello.s 2>&5
+    if test $? != 0; then
+        ${CC} -Werror=unused-but-set-variable -D_PR_HAS_PRAGMA_DIAGNOSTIC -S dummy-hello.c -o dummy-hello.s 2>&5
+        if test $? = 0; then
+            CFLAGS="$CFLAGS -D_PR_HAS_PRAGMA_DIAGNOSTIC=1"
+            _res=yes
+        else
+            _res=no
+        fi
+    else
+        _res=no
+    fi
+    rm -f dummy-hello.c dummy-hello.s
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $_res" >&5
+$as_echo "$_res" >&6; }
+else
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
 _SAVE_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -fprofile-generate -fprofile-correction"
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler supports -fprofile-generate" >&5
 $as_echo_n "checking whether C compiler supports -fprofile-generate... " >&6; }
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
--- a/configure.in
+++ b/configure.in
@@ -711,16 +711,50 @@ if test -n "$GNU_CC" && test -n "$GNU_CX
     fi
     rm -f dummy-hello.c dummy-hello.s dummy-hello.S dummy-hello a.out
     AC_MSG_RESULT([$_res])
 else
     AC_MSG_RESULT([no])
 fi
 
 dnl ========================================================
+dnl Check for pragma diagnostic
+dnl ========================================================
+
+AC_MSG_CHECKING([for pragma diagnostic])
+if test "$GNU_CC" = "1"; then
+    cat >dummy-hello.c <<EOF
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
+int main() {
+    char *dummy = "";
+    return 0;
+}
+EOF
+    ${CC} -Werror=unused-but-set-variable -S dummy-hello.c -o dummy-hello.s 2>&5
+    if test $? != 0; then
+        ${CC} -Werror=unused-but-set-variable -D_PR_HAS_PRAGMA_DIAGNOSTIC -S dummy-hello.c -o dummy-hello.s 2>&5
+        if test $? = 0; then
+            CFLAGS="$CFLAGS -D_PR_HAS_PRAGMA_DIAGNOSTIC=1"
+            _res=yes
+        else
+            _res=no
+        fi
+    else
+        _res=no
+    fi
+    rm -f dummy-hello.c dummy-hello.s
+    AC_MSG_RESULT([$_res])
+else
+    AC_MSG_RESULT([no])
+fi
+
+dnl ========================================================
 dnl Profile guided optimization
 dnl ========================================================
 dnl Test for profiling options
 dnl Under gcc 3.4+, use -fprofile-generate/-fprofile-use
 
 _SAVE_CFLAGS="$CFLAGS"
 CFLAGS="$CFLAGS -fprofile-generate -fprofile-correction"
 
--- a/lib/ds/plvrsion.c
+++ b/lib/ds/plvrsion.c
@@ -69,25 +69,32 @@ PRVersionDescription VERSION_DESC_NAME =
  */
 static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING " $";
 static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING;
 
 #endif /* XP_UNIX */
 
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
 PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
 {
 #ifdef XP_UNIX
     /*
      * Add dummy references to rcsid and sccsid to prevent them
      * from being optimized away as unused variables.
      */
     const char *dummy;
     
     dummy = rcsid;
     dummy = sccsid;
 #endif
     return &VERSION_DESC_NAME;
 }  /* versionEntryPointType */
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic pop
+#endif
 
 /* plvrsion.c */
 
--- a/lib/libc/src/plvrsion.c
+++ b/lib/libc/src/plvrsion.c
@@ -69,25 +69,32 @@ PRVersionDescription VERSION_DESC_NAME =
  */
 static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING " $";
 static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING;
 
 #endif /* XP_UNIX */
 
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
 PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
 {
 #ifdef XP_UNIX
     /*
      * Add dummy references to rcsid and sccsid to prevent them
      * from being optimized away as unused variables.
      */
     const char *dummy;
     
     dummy = rcsid;
     dummy = sccsid;
 #endif
     return &VERSION_DESC_NAME;
 }  /* versionEntryPointType */
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic pop
+#endif
 
 /* plvrsion.c */
 
--- a/lib/prstreams/plvrsion.c
+++ b/lib/prstreams/plvrsion.c
@@ -69,25 +69,32 @@ PRVersionDescription VERSION_DESC_NAME =
  */
 static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING " $";
 static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING;
 
 #endif /* XP_UNIX */
 
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
 PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint()
 {
 #ifdef XP_UNIX
     /*
      * Add dummy references to rcsid and sccsid to prevent them
      * from being optimized away as unused variables.
      */
     const char *dummy;
     
     dummy = rcsid;
     dummy = sccsid;
 #endif
     return &VERSION_DESC_NAME;
 }  /* versionEntryPointType */
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic pop
+#endif
 
 /* plvrsion.c */
 
--- a/pr/src/prvrsion.c
+++ b/pr/src/prvrsion.c
@@ -69,25 +69,32 @@ PRVersionDescription VERSION_DESC_NAME =
  */
 static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING " $";
 static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
         "  " _BUILD_STRING;
 
 #endif /* XP_UNIX */
 
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+#endif
 PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint(void)
 {
 #ifdef XP_UNIX
     /*
      * Add dummy references to rcsid and sccsid to prevent them
      * from being optimized away as unused variables.
      */ 
     const char *dummy;
 
     dummy = rcsid;
     dummy = sccsid;
 #endif
     return &VERSION_DESC_NAME;
 }  /* versionEntryPointType */
+#ifdef _PR_HAS_PRAGMA_DIAGNOSTIC
+#pragma GCC diagnostic pop
+#endif
 
 /* prvrsion.c */