From c16ac37d501c0c04bd68be8f500ea3dc24b28fa4 Mon Sep 17 00:00:00 2001 From: Leo Korinth Date: Tue, 24 Feb 2026 09:21:34 +0000 Subject: [PATCH] 8376892: Allow conversion warnings in subsets of the code base Reviewed-by: kbarrett, erikj, azafari --- make/autoconf/flags-cflags.m4 | 4 ++ make/autoconf/spec.gmk.template | 3 +- make/common/MakeBase.gmk | 67 ++++++++++++++++++++++++++++++++- make/hotspot/lib/CompileJvm.gmk | 4 +- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4 index 0cdf02c61c6..2d39d84f52e 100644 --- a/make/autoconf/flags-cflags.m4 +++ b/make/autoconf/flags-cflags.m4 @@ -214,6 +214,7 @@ AC_DEFUN([FLAGS_SETUP_WARNINGS], WARNINGS_ENABLE_ADDITIONAL_CXX="" WARNINGS_ENABLE_ADDITIONAL_JVM="" DISABLED_WARNINGS="4800 5105" + CFLAGS_CONVERSION_WARNINGS= ;; gcc) @@ -239,6 +240,7 @@ AC_DEFUN([FLAGS_SETUP_WARNINGS], if test "x$OPENJDK_TARGET_CPU_ARCH" = "xppc"; then DISABLED_WARNINGS="$DISABLED_WARNINGS psabi" fi + CFLAGS_CONVERSION_WARNINGS="-Wconversion -Wno-float-conversion" ;; clang) @@ -258,6 +260,7 @@ AC_DEFUN([FLAGS_SETUP_WARNINGS], # These warnings will never be turned on, since they generate too many # false positives. DISABLED_WARNINGS="unknown-warning-option unused-parameter" + CFLAGS_CONVERSION_WARNINGS="-Wimplicit-int-conversion" ;; esac WARNINGS_ENABLE_ALL="$WARNINGS_ENABLE_ALL_NORMAL $WARNINGS_ENABLE_ADDITIONAL" @@ -270,6 +273,7 @@ AC_DEFUN([FLAGS_SETUP_WARNINGS], AC_SUBST(DISABLED_WARNINGS) AC_SUBST(DISABLED_WARNINGS_C) AC_SUBST(DISABLED_WARNINGS_CXX) + AC_SUBST(CFLAGS_CONVERSION_WARNINGS) ]) AC_DEFUN([FLAGS_SETUP_QUALITY_CHECKS], diff --git a/make/autoconf/spec.gmk.template b/make/autoconf/spec.gmk.template index b3d58704c50..c4e5a23d31a 100644 --- a/make/autoconf/spec.gmk.template +++ b/make/autoconf/spec.gmk.template @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2026, 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 @@ -529,6 +529,7 @@ CFLAGS_WARNINGS_ARE_ERRORS := @CFLAGS_WARNINGS_ARE_ERRORS@ DISABLED_WARNINGS := @DISABLED_WARNINGS@ DISABLED_WARNINGS_C := @DISABLED_WARNINGS_C@ DISABLED_WARNINGS_CXX := @DISABLED_WARNINGS_CXX@ +CFLAGS_CONVERSION_WARNINGS := @CFLAGS_CONVERSION_WARNINGS@ # A global flag (true or false) determining if native warnings are considered errors. WARNINGS_AS_ERRORS := @WARNINGS_AS_ERRORS@ diff --git a/make/common/MakeBase.gmk b/make/common/MakeBase.gmk index 97ef88932cb..45cc3c77dea 100644 --- a/make/common/MakeBase.gmk +++ b/make/common/MakeBase.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 2026, 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 @@ -141,6 +141,66 @@ endef # Make sure logging is setup for everyone that includes MakeBase.gmk. $(eval $(call SetupLogging)) +################################################################################ +# Make does not have support for VARARGS, you can send variable amount +# of arguments, but you can for example not append a list at the end. +# It is therefore not easy to send the elements of a list of unknown +# length as argument to a function. This can somewhat be worked around +# by sending a list as an argument, and then interpreting each element +# of the list as an argument to the function. However, Make is +# limited, and using this method you can not easily send spaces. +# +# We need to quote strings for two reasons when sending them as +# "variable append packs": +# +# 1) variable appends can include spaces, and those must be preserved +# 2) variable appends can include assignment strings ":=", and those +# must be quoted to a form so that we can recognise the "append pack". +# We recognise an "append pack" by its lack of strict assignment ":=" + +Q := $(HASH) +SpaceQ := $(Q)s +AppendQ := $(Q)+ +AssignQ := $(Q)a +QQ := $(Q)$(Q) + +# $(call Quote,echo "#trala:=") -> echo#s"##trala#a" +Quote = $(subst :=,$(AssignQ),$(subst $(SPACE),$(SpaceQ),$(subst $(Q),$(QQ),$1))) + +# $(call Unquote,echo#s"##trala#a") -> echo "#trala:=" +Unquote = $(subst $(QQ),$(Q),$(subst $(SpaceQ),$(SPACE),$(subst $(AssignQ),:=,$1))) + +# $(call QuoteAppend,name,some value) -> name#+some#svalue +# $(call QuoteAppend,bad+=name,some value) -> error +QuoteAppend = $(if $(findstring +=,$1),$(error you can not have += in a variable name: "$1"),$(call Quote,$1)$(AppendQ)$(call Quote,$2)) + +# $(call UnquoteAppendIndex,name#+some#svalue,1) -> name +# $(call UnquoteAppendIndex,name#+some#svalue,2) -> some value +UnquoteAppendIndex = $(call Unquote,$(word $2,$(subst $(AppendQ),$(SPACE),$1))) + +# $(call FilterFiles,dir,%.cpp) -> file1.cpp file2.cpp (without path) +FilterFiles = $(filter $2,$(notdir $(call FindFiles,$1))) + +# $(call Unpack module_,file1.cpp_CXXFLAGS#+-Wconversion file2.cpp_CXXFLAGS#+-Wconversion) -> module_file1.cpp_CXXFLAGS += -Wconversion +# module_file2.cpp_CXXFLAGS += -Wconversion +Unpack = $(foreach pair,$2,$1$(call UnquoteAppendIndex,$(pair),1) += $(call UnquoteAppendIndex,$(pair),2)$(NEWLINE)) + +# This macro takes four arguments: +# $1: directory where to find files (striped), example: $(TOPDIR)/src/hotspot/share/gc/g1 +# $2: filter to match what to keep (striped), example: g1Concurrent%.cpp +# $3: what flags to override (striped), example: _CXXFLAGS +# $4: what value to append to the flag (striped), example: $(CFLAGS_CONVERSION_WARNINGS) +# +# The result will be a quoted string that can be unpacked to a list of +# variable appendings (see macro Unpack above). You do not need to take +# care of unpacking, it is done in NamedParamsMacroTemplate. +# +# This feature should only be used for warnings that we want to +# incrementally add to the rest of the code base. +# +# $(call ExtendFlags,dir,%.cpp,_CXXFLAGS,-Wconversion) -> file1.cpp_CXXFLAGS#+-Wconversion file2.cpp_CXXFLAGS#+-Wconversion +ExtendFlags = $(foreach file,$(call FilterFiles,$(strip $1),$(strip $2)),$(call QuoteAppend,$(file)$(strip $3),$(strip $4))) + ################################################################################ MAX_PARAMS := 96 @@ -166,7 +226,10 @@ define NamedParamsMacroTemplate Too many named arguments to macro, please update MAX_PARAMS in MakeBase.gmk)) # Iterate over 2 3 4... and evaluate the named parameters with $1_ as prefix $(foreach i, $(PARAM_SEQUENCE), $(if $(strip $($i)), \ - $(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE))) + $(if $(findstring :=,$($i)), \ + $(strip $1)_$(strip $(call EscapeHash, $(call DoubleDollar, $($i))))$(NEWLINE), \ + $(call Unpack,$(strip $1)_,$($i))))) + # Debug print all named parameter names and values $(if $(findstring $(LOG_LEVEL), trace), \ $(info $0 $(strip $1) $(foreach i, $(PARAM_SEQUENCE), \ diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk index 39a549b7db0..76e0056658c 100644 --- a/make/hotspot/lib/CompileJvm.gmk +++ b/make/hotspot/lib/CompileJvm.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2013, 2026, 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 @@ -190,6 +190,8 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \ abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \ whitebox.cpp_CXXFLAGS := $(CFLAGS_SHIP_DEBUGINFO), \ + $(call ExtendFlags, $(TOPDIR)/src/hotspot/share/gc/g1, \ + g1Numa.cpp, _CXXFLAGS, $(CFLAGS_CONVERSION_WARNINGS)), \ DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \ DISABLED_WARNINGS_gcc_ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp := nonnull, \ DISABLED_WARNINGS_gcc_bytecodeInterpreter.cpp := unused-label, \