# HG changeset patch # User ihse # Date 1537558512 -7200 # Node ID ab54a4d61d7fe4795d29497034aac72b0cae2291 # Parent f8af1f1f3518be87ce2f8923e1d6e1e747cf8566 8210988: Improved handling of compiler warnings in the build Reviewed-by: erikj diff -r f8af1f1f3518 -r ab54a4d61d7f make/autoconf/flags-cflags.m4 --- a/make/autoconf/flags-cflags.m4 Fri Sep 21 12:08:13 2018 -0700 +++ b/make/autoconf/flags-cflags.m4 Fri Sep 21 21:35:12 2018 +0200 @@ -161,14 +161,31 @@ microsoft) DISABLE_WARNING_PREFIX="-wd" CFLAGS_WARNINGS_ARE_ERRORS="-WX" + + WARNINGS_ENABLE_ALL="-W3" + DISABLED_WARNINGS="4800" ;; + solstudio) DISABLE_WARNING_PREFIX="-erroff=" - CFLAGS_WARNINGS_ARE_ERRORS="-errtags -errwarn=%all" + CFLAGS_WARNINGS_ARE_ERRORS="-errwarn=%all" + + WARNINGS_ENABLE_ALL_CFLAGS="-v" + WARNINGS_ENABLE_ALL_CXXFLAGS="+w" + + DISABLED_WARNINGS_C="" + DISABLED_WARNINGS_CXX="" ;; + gcc) DISABLE_WARNING_PREFIX="-Wno-" CFLAGS_WARNINGS_ARE_ERRORS="-Werror" + + WARNINGS_ENABLE_ALL="-Wall -Wextra -Wformat=2" + WARNINGS_ENABLE_ADDITIONAL_JVM="-Wpointer-arith -Wsign-compare -Wunused-function -Wundef -Wunused-value -Woverloaded-virtual -Wreorder -Wreturn-type" + + DISABLED_WARNINGS="unused-parameter unused" + # Repeate the check for the BUILD_CC and BUILD_CXX. Need to also reset # CFLAGS since any target specific flags will likely not work with the # build compiler @@ -183,18 +200,32 @@ CXX="$CXX_OLD" CFLAGS="$CFLAGS_OLD" ;; + clang) DISABLE_WARNING_PREFIX="-Wno-" CFLAGS_WARNINGS_ARE_ERRORS="-Werror" + + WARNINGS_ENABLE_ALL="-Wall -Wextra -Wformat=2" + WARNINGS_ENABLE_ADDITIONAL_JVM="-Wpointer-arith -Wsign-compare -Wunused-function -Wundef -Wunused-value -Woverloaded-virtual -Wreorder" + + DISABLED_WARNINGS="unused-parameter unused" ;; + xlc) DISABLE_WARNING_PREFIX="-qsuppress=" CFLAGS_WARNINGS_ARE_ERRORS="-qhalt=w" + + # Possibly a better subset than "all" is "lan:trx:ret:zea:cmp:ret" + WARNINGS_ENABLE_ALL="-qinfo=all -qformat=all" + DISABLED_WARNINGS="" ;; esac AC_SUBST(DISABLE_WARNING_PREFIX) AC_SUBST(BUILD_CC_DISABLE_WARNING_PREFIX) AC_SUBST(CFLAGS_WARNINGS_ARE_ERRORS) + AC_SUBST(DISABLED_WARNINGS) + AC_SUBST(DISABLED_WARNINGS_C) + AC_SUBST(DISABLED_WARNINGS_CXX) ]) AC_DEFUN([FLAGS_SETUP_QUALITY_CHECKS], @@ -512,11 +543,14 @@ TOOLCHAIN_CFLAGS_JDK_CONLY="-fno-strict-aliasing" # technically NOT for CXX fi elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then - TOOLCHAIN_CFLAGS_JDK="-mt" - TOOLCHAIN_CFLAGS_JDK_CONLY="-xc99=%none -xCC -Xa -v -W0,-noglobal" # C only + TOOLCHAIN_FLAGS="-errtags -errfmt" + TOOLCHAIN_CFLAGS="-errshort=tags" + + TOOLCHAIN_CFLAGS_JDK="-mt $TOOLCHAIN_FLAGS" + TOOLCHAIN_CFLAGS_JDK_CONLY="-xc99=%none -xCC -Xa -W0,-noglobal $TOOLCHAIN_CFLAGS" # C only TOOLCHAIN_CFLAGS_JDK_CXXONLY="-features=no%except -norunpath -xnolib" # CXX only TOOLCHAIN_CFLAGS_JVM="-template=no%extdef -features=no%split_init \ - -library=stlport4 -mt -features=no%except" + -library=stlport4 -mt -features=no%except $TOOLCHAIN_FLAGS" if test "x$DEBUG_LEVEL" = xslowdebug; then # Previously -g was used instead of -g0 for slowdebug; this is equivalent # to setting +d. @@ -524,6 +558,7 @@ fi elif test "x$TOOLCHAIN_TYPE" = xxlc; then + # Suggested additions: -qsrcmsg to get improved error reporting TOOLCHAIN_CFLAGS_JDK="-qchars=signed -qfullpath -qsaveopt" # add on both CFLAGS TOOLCHAIN_CFLAGS_JVM="-qtune=balanced \ -qalias=noansi -qstrict -qtls=default -qlanglvl=c99vla \ @@ -535,37 +570,26 @@ # CFLAGS WARNINGS STUFF # Set JVM_CFLAGS warning handling - if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then - # COMMON to gcc and clang - WARNING_CFLAGS_JVM="-Wpointer-arith -Wsign-compare -Wunused-function" - if ! HOTSPOT_CHECK_JVM_VARIANT(zero); then - # Non-zero builds have stricter warnings - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wundef -Wformat=2" - fi - - fi if test "x$TOOLCHAIN_TYPE" = xgcc; then - WARNING_CFLAGS_JDK="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2" - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wunused-value -Woverloaded-virtual -Wreorder" + WARNING_CFLAGS_JDK="$WARNINGS_ENABLE_ALL" + WARNING_CFLAGS_JVM="$WARNINGS_ENABLE_ALL $WARNINGS_ENABLE_ADDITIONAL_JVM" - if ! HOTSPOT_CHECK_JVM_VARIANT(zero); then - # Non-zero builds have stricter warnings - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wreturn-type" - fi elif test "x$TOOLCHAIN_TYPE" = xclang; then - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wno-deprecated -Wreorder" if test "x$OPENJDK_TARGET_OS" = xlinux; then - WARNING_CFLAGS_JVM="$WARNING_CFLAGS_JVM -Wno-sometimes-uninitialized" - WARNING_CFLAGS_JDK="-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wformat=2" + WARNING_CFLAGS_JDK="$WARNINGS_ENABLE_ALL" + else + WARNING_CFLAGS_JDK="" # currently left empty fi + WARNING_CFLAGS_JVM="$WARNINGS_ENABLE_ALL $WARNINGS_ENABLE_ADDITIONAL_JVM" + elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then - WARNING_CFLAGS_JDK_CONLY="-errshort=tags" - WARNING_CFLAGS_JDK_CXXONLY="+w" - WARNING_CFLAGS_JDK="-errtags=yes -errfmt" + WARNING_CFLAGS_JDK_CONLY="$WARNINGS_ENABLE_ALL_CFLAGS" + WARNING_CFLAGS_JDK_CXXONLY="$WARNINGS_ENABLE_ALL_CXXFLAGS" + WARNING_CFLAGS_JVM="" # currently left empty elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then - WARNING_CFLAGS="-W3" - WARNING_CFLAGS_JDK="-wd4800" - WARNING_CFLAGS_JVM="-wd4800" + WARNING_CFLAGS="$WARNINGS_ENABLE_ALL" + elif test "x$TOOLCHAIN_TYPE" = xxlc; then + WARNING_CFLAGS="" # currently left empty fi # Set some additional per-OS defines. diff -r f8af1f1f3518 -r ab54a4d61d7f make/autoconf/flags-ldflags.m4 --- a/make/autoconf/flags-ldflags.m4 Fri Sep 21 12:08:13 2018 -0700 +++ b/make/autoconf/flags-ldflags.m4 Fri Sep 21 21:35:12 2018 +0200 @@ -139,6 +139,14 @@ fi fi + # Setup warning flags + if test "x$TOOLCHAIN_TYPE" = xsolstudio; then + LDFLAGS_WARNINGS_ARE_ERRORS="-Wl,-z,fatal-warnings" + else + LDFLAGS_WARNINGS_ARE_ERRORS="" + fi + AC_SUBST(LDFLAGS_WARNINGS_ARE_ERRORS) + # Setup LDFLAGS for linking executables if test "x$TOOLCHAIN_TYPE" = xgcc; then EXECUTABLE_LDFLAGS="$EXECUTABLE_LDFLAGS -Wl,--allow-shlib-undefined" diff -r f8af1f1f3518 -r ab54a4d61d7f make/autoconf/spec.gmk.in --- a/make/autoconf/spec.gmk.in Fri Sep 21 12:08:13 2018 -0700 +++ b/make/autoconf/spec.gmk.in Fri Sep 21 21:35:12 2018 +0200 @@ -423,6 +423,10 @@ DISABLE_WARNING_PREFIX := @DISABLE_WARNING_PREFIX@ CFLAGS_WARNINGS_ARE_ERRORS:=@CFLAGS_WARNINGS_ARE_ERRORS@ +LDFLAGS_WARNINGS_ARE_ERRORS:=@LDFLAGS_WARNINGS_ARE_ERRORS@ +DISABLED_WARNINGS := @DISABLED_WARNINGS@ +DISABLED_WARNINGS_C := @DISABLED_WARNINGS_C@ +DISABLED_WARNINGS_CXX := @DISABLED_WARNINGS_CXX@ # A global flag (true or false) determining if native warnings are considered errors. WARNINGS_AS_ERRORS := @WARNINGS_AS_ERRORS@ diff -r f8af1f1f3518 -r ab54a4d61d7f make/common/NativeCompilation.gmk --- a/make/common/NativeCompilation.gmk Fri Sep 21 12:08:13 2018 -0700 +++ b/make/common/NativeCompilation.gmk Fri Sep 21 21:35:12 2018 +0200 @@ -594,9 +594,13 @@ # Pick up disabled warnings, if possible on this platform. ifneq ($(DISABLE_WARNING_PREFIX), ) $1_EXTRA_CFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ + $$(DISABLED_WARNINGS) \ + $$(DISABLED_WARNINGS_C) \ $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ $$($1_DISABLED_WARNINGS_C_$(TOOLCHAIN_TYPE))) $1_EXTRA_CXXFLAGS += $$(addprefix $(DISABLE_WARNING_PREFIX), \ + $$(DISABLED_WARNINGS) \ + $$(DISABLED_WARNINGS_CXX) \ $$($1_DISABLED_WARNINGS_$(TOOLCHAIN_TYPE)) \ $$($1_DISABLED_WARNINGS_CXX_$(TOOLCHAIN_TYPE))) endif @@ -614,6 +618,7 @@ ifeq ($$($1_WARNINGS_AS_ERRORS_$(TOOLCHAIN_TYPE)), true) $1_EXTRA_CFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) $1_EXTRA_CXXFLAGS += $(CFLAGS_WARNINGS_ARE_ERRORS) + $1_EXTRA_LDFLAGS += $(LDFLAGS_WARNINGS_ARE_ERRORS) endif ifeq (NONE, $$($1_OPTIMIZATION)) @@ -780,8 +785,8 @@ # Pickup extra OPENJDK_TARGET_OS_TYPE and/or OPENJDK_TARGET_OS dependent variables # for LDFLAGS and LIBS - $1_EXTRA_LDFLAGS := $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) - $1_EXTRA_LIBS := $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) + $1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) + $1_EXTRA_LIBS += $$($1_LIBS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LIBS_$(OPENJDK_TARGET_OS)) ifneq ($$($1_REAL_MAPFILE), ) $1_EXTRA_LDFLAGS += $(call SET_SHARED_LIBRARY_MAPFILE,$$($1_REAL_MAPFILE)) endif diff -r f8af1f1f3518 -r ab54a4d61d7f make/hotspot/lib/CompileGtest.gmk --- a/make/hotspot/lib/CompileGtest.gmk Fri Sep 21 12:08:13 2018 -0700 +++ b/make/hotspot/lib/CompileGtest.gmk Fri Sep 21 21:35:12 2018 +0200 @@ -73,11 +73,14 @@ CFLAGS_windows := -EHsc, \ CFLAGS_solaris := -DGTEST_HAS_EXCEPTIONS=0 -library=stlport4, \ CFLAGS_macosx := -DGTEST_OS_MAC=1, \ - DISABLED_WARNINGS_gcc := undef, \ - DISABLED_WARNINGS_clang := undef switch format-nonliteral \ - tautological-undefined-compare $(BUILD_LIBJVM_DISABLED_WARNINGS_clang), \ - DISABLED_WARNINGS_solstudio := identexpected, \ - DISABLED_WARNINGS_CXX_microsoft := 4996, \ + DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc) \ + undef, \ + DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang) \ + undef switch format-nonliteral tautological-undefined-compare, \ + DISABLED_WARNINGS_solstudio := $(DISABLED_WARNINGS_solstudio) \ + identexpected, \ + DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft) \ + 4996, \ LDFLAGS := $(JVM_LDFLAGS), \ LDFLAGS_solaris := -library=stlport4 $(call SET_SHARED_LIBRARY_ORIGIN), \ LIBS := $(JVM_LIBS), \ diff -r f8af1f1f3518 -r ab54a4d61d7f make/hotspot/lib/CompileJvm.gmk --- a/make/hotspot/lib/CompileJvm.gmk Fri Sep 21 12:08:13 2018 -0700 +++ b/make/hotspot/lib/CompileJvm.gmk Fri Sep 21 21:35:12 2018 +0200 @@ -80,6 +80,25 @@ # ################################################################################ +# Disabled warnings + +DISABLED_WARNINGS_gcc := extra all +ifeq ($(call check-jvm-feature, zero), true) + DISABLED_WARNINGS_gcc += return-type +endif + +DISABLED_WARNINGS_clang := extra all tautological-compare deprecated-declarations + +DISABLED_WARNINGS_solstudio := + +DISABLED_WARNINGS_xlc := 1540-0216 1540-0198 1540-1090 1540-1639 1540-1088 \ + 1500-010 + +DISABLED_WARNINGS_microsoft := + + + +################################################################################ # Platform specific setup # ARM source selection @@ -115,7 +134,7 @@ endif # Exclude warnings in devstudio 12.6 ifeq ($(CC_VERSION_NUMBER), 5.15) - DISABLED_WARNINGS_solstudio := SEC_ARR_OUTSIDE_BOUND_READ \ + DISABLED_WARNINGS_solstudio += SEC_ARR_OUTSIDE_BOUND_READ \ SEC_ARR_OUTSIDE_BOUND_WRITE endif endif @@ -158,10 +177,11 @@ CFLAGS := $(JVM_CFLAGS), \ vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ - DISABLED_WARNINGS_clang := tautological-compare, \ + DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \ + DISABLED_WARNINGS_clang := $(DISABLED_WARNINGS_clang), \ DISABLED_WARNINGS_solstudio := $(DISABLED_WARNINGS_solstudio), \ - DISABLED_WARNINGS_xlc := 1540-0216 1540-0198 1540-1090 1540-1639 \ - 1540-1088 1500-010, \ + DISABLED_WARNINGS_xlc := $(DISABLED_WARNINGS_xlc), \ + DISABLED_WARNINGS_microsoft := $(DISABLED_WARNINGS_microsoft), \ ASFLAGS := $(JVM_ASFLAGS), \ LDFLAGS := $(JVM_LDFLAGS), \ LIBS := $(JVM_LIBS), \