8218164: Improve local control of compiler warnings
authorkbarrett
Tue, 05 Feb 2019 13:21:59 -0500
changeset 53645 2c6c0fabe6a2
parent 53644 5d95a8dbb6e4
child 53646 043ae846819f
8218164: Improve local control of compiler warnings Summary: Windows warning push/pop and gcc/Windows warning suppression macros. Reviewed-by: dholmes, tschatzl
src/hotspot/share/compiler/methodMatcher.cpp
src/hotspot/share/gc/g1/g1ConcurrentMark.hpp
src/hotspot/share/utilities/compilerWarnings.hpp
src/hotspot/share/utilities/compilerWarnings_gcc.hpp
src/hotspot/share/utilities/compilerWarnings_solstudio.hpp
src/hotspot/share/utilities/compilerWarnings_visCPP.hpp
src/hotspot/share/utilities/compilerWarnings_xlc.hpp
--- a/src/hotspot/share/compiler/methodMatcher.cpp	Tue Feb 05 09:57:35 2019 -0800
+++ b/src/hotspot/share/compiler/methodMatcher.cpp	Tue Feb 05 13:21:59 2019 -0500
@@ -237,12 +237,10 @@
   }
 }
 
-#ifdef _MSC_VER
-#pragma warning(push)
+PRAGMA_DIAG_PUSH
 // warning C4189: The file contains a character that cannot be represented
 //                in the current code page
-#pragma warning(disable : 4819)
-#endif
+PRAGMA_DISABLE_MSVC_WARNING(4819)
 void MethodMatcher::parse_method_pattern(char*& line, const char*& error_msg, MethodMatcher* matcher) {
   MethodMatcher::Mode c_match;
   MethodMatcher::Mode m_match;
@@ -312,9 +310,7 @@
     error_msg = "Could not parse method pattern";
   }
 }
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
+PRAGMA_DIAG_POP
 
 bool MethodMatcher::matches(const methodHandle& method) const {
   Symbol* class_name  = method->method_holder()->name();
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp	Tue Feb 05 09:57:35 2019 -0800
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.hpp	Tue Feb 05 13:21:59 2019 -0500
@@ -32,6 +32,7 @@
 #include "gc/g1/heapRegionSet.hpp"
 #include "gc/shared/taskqueue.hpp"
 #include "memory/allocation.hpp"
+#include "utilities/compilerWarnings.hpp"
 
 class ConcurrentGCTimer;
 class G1ConcurrentMarkThread;
@@ -43,11 +44,9 @@
 class G1RegionToSpaceMapper;
 class G1SurvivorRegions;
 
-#ifdef _MSC_VER
-#pragma warning(push)
+PRAGMA_DIAG_PUSH
 // warning C4522: multiple assignment operators specified
-#pragma warning(disable:4522)
-#endif
+PRAGMA_DISABLE_MSVC_WARNING(4522)
 
 // This is a container class for either an oop or a continuation address for
 // mark stack entries. Both are pushed onto the mark stack.
@@ -93,9 +92,7 @@
   bool is_null() const { return _holder == NULL; }
 };
 
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
+PRAGMA_DIAG_POP
 
 typedef GenericTaskQueue<G1TaskQueueEntry, mtGC> G1CMTaskQueue;
 typedef GenericTaskQueueSet<G1CMTaskQueue, mtGC> G1CMTaskQueueSet;
--- a/src/hotspot/share/utilities/compilerWarnings.hpp	Tue Feb 05 09:57:35 2019 -0800
+++ b/src/hotspot/share/utilities/compilerWarnings.hpp	Tue Feb 05 13:21:59 2019 -0500
@@ -27,42 +27,27 @@
 
 // Macros related to control of compiler warnings.
 
-// We presently only have interesting macros here for gcc and variants,
-// so it's not worth going through the COMPILER_HEADER() dispatch, with
-// all the non-gcc files being empty.
-#ifdef TARGET_COMPILER_gcc
+#include "utilities/macros.hpp"
 
-// Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED
-// were only introduced in GCC 4.2. Because we have no other possibility to ignore
-// these warnings for older versions of GCC, we simply don't decorate our printf-style
-// functions with __attribute__(format) in that case.
-#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4)
-#ifndef ATTRIBUTE_PRINTF
-#define ATTRIBUTE_PRINTF(fmt,vargs)  __attribute__((format(printf, fmt, vargs)))
-#endif
-#ifndef ATTRIBUTE_SCANF
-#define ATTRIBUTE_SCANF(fmt,vargs)  __attribute__((format(scanf, fmt, vargs)))
-#endif
-#endif // gcc version check
-
-#define PRAGMA_FORMAT_NONLITERAL_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \
-                                         _Pragma("GCC diagnostic ignored \"-Wformat-security\"")
-#define PRAGMA_FORMAT_IGNORED _Pragma("GCC diagnostic ignored \"-Wformat\"")
-
-#if defined(__clang_major__) && \
-      (__clang_major__ >= 4 || \
-      (__clang_major__ >= 3 && __clang_minor__ >= 1)) || \
-    ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
-// Tested to work with clang version 3.1 and better.
-#define PRAGMA_DIAG_PUSH             _Pragma("GCC diagnostic push")
-#define PRAGMA_DIAG_POP              _Pragma("GCC diagnostic pop")
-
-#endif // clang/gcc version check
-
-#endif // TARGET_COMPILER_gcc
+#include COMPILER_HEADER(utilities/compilerWarnings)
 
 // Defaults when not defined for the TARGET_COMPILER_xxx.
 
+#ifndef PRAGMA_DIAG_PUSH
+#define PRAGMA_DIAG_PUSH
+#endif
+#ifndef PRAGMA_DIAG_POP
+#define PRAGMA_DIAG_POP
+#endif
+
+#ifndef PRAGMA_DISABLE_GCC_WARNING
+#define PRAGMA_DISABLE_GCC_WARNING(name)
+#endif
+
+#ifndef PRAGMA_DISABLE_MSVC_WARNING
+#define PRAGMA_DISABLE_MSVC_WARNING(num)
+#endif
+
 #ifndef ATTRIBUTE_PRINTF
 #define ATTRIBUTE_PRINTF(fmt, vargs)
 #endif
@@ -77,11 +62,4 @@
 #define PRAGMA_FORMAT_IGNORED
 #endif
 
-#ifndef PRAGMA_DIAG_PUSH
-#define PRAGMA_DIAG_PUSH
-#endif
-#ifndef PRAGMA_DIAG_POP
-#define PRAGMA_DIAG_POP
-#endif
-
 #endif // SHARE_UTILITIES_COMPILERWARNINGS_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/utilities/compilerWarnings_gcc.hpp	Tue Feb 05 13:21:59 2019 -0500
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_UTILITIES_COMPILERWARNINGS_GCC_HPP
+#define SHARE_UTILITIES_COMPILERWARNINGS_GCC_HPP
+
+// Macros related to control of compiler warnings.
+
+// Diagnostic pragmas like the ones defined below in PRAGMA_FORMAT_NONLITERAL_IGNORED
+// were only introduced in GCC 4.2. Because we have no other possibility to ignore
+// these warnings for older versions of GCC, we simply don't decorate our printf-style
+// functions with __attribute__(format) in that case.
+#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || (__GNUC__ > 4)
+#ifndef ATTRIBUTE_PRINTF
+#define ATTRIBUTE_PRINTF(fmt,vargs)  __attribute__((format(printf, fmt, vargs)))
+#endif
+#ifndef ATTRIBUTE_SCANF
+#define ATTRIBUTE_SCANF(fmt,vargs)  __attribute__((format(scanf, fmt, vargs)))
+#endif
+#endif // gcc version check
+
+#define PRAGMA_DISABLE_GCC_WARNING_AUX(x) _Pragma(#x)
+#define PRAGMA_DISABLE_GCC_WARNING(option_string) \
+  PRAGMA_DISABLE_GCC_WARNING_AUX(GCC diagnostic ignored option_string)
+
+#define PRAGMA_FORMAT_NONLITERAL_IGNORED                \
+  PRAGMA_DISABLE_GCC_WARNING("-Wformat-nonliteral")     \
+  PRAGMA_DISABLE_GCC_WARNING("-Wformat-security")
+
+#define PRAGMA_FORMAT_IGNORED PRAGMA_DISABLE_GCC_WARNING("-Wformat")
+
+#if defined(__clang_major__) && \
+      (__clang_major__ >= 4 || \
+      (__clang_major__ >= 3 && __clang_minor__ >= 1)) || \
+    ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) || (__GNUC__ > 4)
+// Tested to work with clang version 3.1 and better.
+#define PRAGMA_DIAG_PUSH             _Pragma("GCC diagnostic push")
+#define PRAGMA_DIAG_POP              _Pragma("GCC diagnostic pop")
+
+#endif // clang/gcc version check
+
+#endif // SHARE_UTILITIES_COMPILERWARNINGS_GCC_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/utilities/compilerWarnings_solstudio.hpp	Tue Feb 05 13:21:59 2019 -0500
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_UTILITIES_COMPILERWARNINGS_SOLSTUDIO_HPP
+#define SHARE_UTILITIES_COMPILERWARNINGS_SOLSTUDIO_HPP
+
+// Nothing here yet.
+
+#endif // SHARE_UTILITIES_COMPILERWARNINGS_SOLSTUDIO_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/utilities/compilerWarnings_visCPP.hpp	Tue Feb 05 13:21:59 2019 -0500
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_UTILITIES_COMPILERWARNINGS_VISCPP_HPP
+#define SHARE_UTILITIES_COMPILERWARNINGS_VISCPP_HPP
+
+#define PRAGMA_DIAG_PUSH __pragma(warning(push))
+#define PRAGMA_DIAG_POP  __pragma(warning(pop))
+
+#define PRAGMA_DISABLE_MSVC_WARNING(num) __pragma(warning(disable : num))
+
+#endif // SHARE_UTILITIES_COMPILERWARNINGS_VISCPP_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/hotspot/share/utilities/compilerWarnings_xlc.hpp	Tue Feb 05 13:21:59 2019 -0500
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#ifndef SHARE_UTILITIES_COMPILERWARNINGS_XLC_HPP
+#define SHARE_UTILITIES_COMPILERWARNINGS_XLC_HPP
+
+// Nothing here yet.
+
+#endif // SHARE_UTILITIES_COMPILERWARNINGS_XLC_HPP