postgres.git / summary / log / commit / refs

commit    3ee0edb9169ff7b46bc858062007bb97c7cc1ae7
Author:   Peter Eisentraut <peter@eisentraut.org>
Date:     Thu Sep 24 09:12:17 2026 +0000

    Use warning option -Wshadow=local
    
    Change the existing -Wshadow=compatible-local to -Wshadow=local.  This
    covers more cases than before.  In particular, some types are
    assignable to each other, such as char * and const char *, or bool and
    some integer type, but they are not "compatible" in the C sense, so
    they are missed by the previous warning setting, but they are really
    the same basic problem.
    
    The warnings were already fixed in commit f9fc9a78a36.  This just
    enables the compiler option.
    
    But: The LLVM headers are not clean for this option, so we need to
    disable this option for those headers.  We do this by also detecting
    in configure and meson the negative form of the warning option and
    applying it when compiling the respective files, similar to how other
    per-file warning disabling already works.
    
    This technically loses the previous -Wshadow=compatible-local checking
    of the LLVM-using files, but this worked only by accident anyway and
    there is no guarantee that future LLVM versions wouldn't run afoul of
    that warning level.
    
    The variables are intentionally named "...shadow", not
    "...shadow_local" or similar, so that other shadow warning option
    variants could be substituted easily.
    
    In the long run, a better solution might be to use -isystem for the
    LLVM include directories, as was attempted in commit 704ef84ef23 but
    then reverted in 7a0aa99e51c, because porting that logic from meson
    accurately to configure is complicated and fragile and hard to test
    and maintain.
    
    Discussion: https://www.postgresql.org/message-id/flat/84b6f128-91f5-480e-8a9e-7d0e8f538cea%40eisentraut.org


configure | 187 +++++++++++++++++++++------------------ configure.ac | 16 +++- meson.build | 9 +- src/Makefile.global.in | 1 + src/backend/jit/llvm/Makefile | 2 +- src/backend/jit/llvm/meson.build | 2 +- src/makefiles/meson.build | 2 + 7 files changed, 127 insertions(+), 92 deletions(-) diff --git a/configure b/configure index d42a7a794ff..6b05d4c84ab 100755 --- a/configure +++ b/configure @@ -749,6 +749,7 @@ CXXFLAGS_SL_MODULE CFLAGS_SL_MODULE CFLAGS_VECTORIZE CFLAGS_UNROLL_LOOPS +PERMIT_CXX_SHADOW PERMIT_MISSING_VARIABLE_DECLARATIONS PERMIT_DECLARATION_AFTER_STATEMENT LLVM_BINPATH @@ -5902,15 +5903,17 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wshadow=compatible-local, for CFLAGS" >&5 -$as_echo_n "checking whether ${CC} supports -Wshadow=compatible-local, for CFLAGS... " >&6; } -if ${pgac_cv_prog_CC_cflags__Wshadow_compatible_local+:} false; then : + # This was included in -Wall/-Wformat in older GCC versions + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wformat-security, for CFLAGS" >&5 +$as_echo_n "checking whether ${CC} supports -Wformat-security, for CFLAGS... " >&6; } +if ${pgac_cv_prog_CC_cflags__Wformat_security+:} false; then : $as_echo_n "(cached) " >&6 else pgac_save_CFLAGS=$CFLAGS pgac_save_CC=$CC CC=${CC} -CFLAGS="${CFLAGS} -Wshadow=compatible-local" +CFLAGS="${CFLAGS} -Wformat-security" ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -5925,31 +5928,31 @@ main () } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - pgac_cv_prog_CC_cflags__Wshadow_compatible_local=yes + pgac_cv_prog_CC_cflags__Wformat_security=yes else - pgac_cv_prog_CC_cflags__Wshadow_compatible_local=no + pgac_cv_prog_CC_cflags__Wformat_security=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="$pgac_save_CFLAGS" CC="$pgac_save_CC" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wshadow_compatible_local" >&5 -$as_echo "$pgac_cv_prog_CC_cflags__Wshadow_compatible_local" >&6; } -if test x"$pgac_cv_prog_CC_cflags__Wshadow_compatible_local" = x"yes"; then - CFLAGS="${CFLAGS} -Wshadow=compatible-local" +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wformat_security" >&5 +$as_echo "$pgac_cv_prog_CC_cflags__Wformat_security" >&6; } +if test x"$pgac_cv_prog_CC_cflags__Wformat_security" = x"yes"; then + CFLAGS="${CFLAGS} -Wformat-security" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Wshadow=compatible-local, for CXXFLAGS" >&5 -$as_echo_n "checking whether ${CXX} supports -Wshadow=compatible-local, for CXXFLAGS... " >&6; } -if ${pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Wformat-security, for CXXFLAGS" >&5 +$as_echo_n "checking whether ${CXX} supports -Wformat-security, for CXXFLAGS... " >&6; } +if ${pgac_cv_prog_CXX_cxxflags__Wformat_security+:} false; then : $as_echo_n "(cached) " >&6 else pgac_save_CXXFLAGS=$CXXFLAGS pgac_save_CXX=$CXX CXX=${CXX} -CXXFLAGS="${CXXFLAGS} -Wshadow=compatible-local" +CXXFLAGS="${CXXFLAGS} -Wformat-security" ac_save_cxx_werror_flag=$ac_cxx_werror_flag ac_cxx_werror_flag=yes ac_ext=cpp @@ -5970,9 +5973,9 @@ main () } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : - pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local=yes + pgac_cv_prog_CXX_cxxflags__Wformat_security=yes else - pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local=no + pgac_cv_prog_CXX_cxxflags__Wformat_security=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_ext=c @@ -5985,24 +5988,27 @@ ac_cxx_werror_flag=$ac_save_cxx_werror_flag CXXFLAGS="$pgac_save_CXXFLAGS" CXX="$pgac_save_CXX" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local" >&5 -$as_echo "$pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local" >&6; } -if test x"$pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local" = x"yes"; then - CXXFLAGS="${CXXFLAGS} -Wshadow=compatible-local" +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Wformat_security" >&5 +$as_echo "$pgac_cv_prog_CXX_cxxflags__Wformat_security" >&6; } +if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" = x"yes"; then + CXXFLAGS="${CXXFLAGS} -Wformat-security" fi - # This was included in -Wall/-Wformat in older GCC versions -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wformat-security, for CFLAGS" >&5 -$as_echo_n "checking whether ${CC} supports -Wformat-security, for CFLAGS... " >&6; } -if ${pgac_cv_prog_CC_cflags__Wformat_security+:} false; then : + # gcc 14+, clang for a while + # (Supported in C++ by clang but not gcc. For consistency, omit in C++.) + save_CFLAGS=$CFLAGS + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wmissing-variable-declarations, for CFLAGS" >&5 +$as_echo_n "checking whether ${CC} supports -Wmissing-variable-declarations, for CFLAGS... " >&6; } +if ${pgac_cv_prog_CC_cflags__Wmissing_variable_declarations+:} false; then : $as_echo_n "(cached) " >&6 else pgac_save_CFLAGS=$CFLAGS pgac_save_CC=$CC CC=${CC} -CFLAGS="${CFLAGS} -Wformat-security" +CFLAGS="${CFLAGS} -Wmissing-variable-declarations" ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -6017,31 +6023,80 @@ main () } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - pgac_cv_prog_CC_cflags__Wformat_security=yes + pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=yes else - pgac_cv_prog_CC_cflags__Wformat_security=no + pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="$pgac_save_CFLAGS" CC="$pgac_save_CC" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wformat_security" >&5 -$as_echo "$pgac_cv_prog_CC_cflags__Wformat_security" >&6; } -if test x"$pgac_cv_prog_CC_cflags__Wformat_security" = x"yes"; then - CFLAGS="${CFLAGS} -Wformat-security" +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&5 +$as_echo "$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&6; } +if test x"$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" = x"yes"; then + CFLAGS="${CFLAGS} -Wmissing-variable-declarations" fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Wformat-security, for CXXFLAGS" >&5 -$as_echo_n "checking whether ${CXX} supports -Wformat-security, for CXXFLAGS... " >&6; } -if ${pgac_cv_prog_CXX_cxxflags__Wformat_security+:} false; then : + PERMIT_MISSING_VARIABLE_DECLARATIONS= + if test x"$save_CFLAGS" != x"$CFLAGS"; then + PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations + fi + + + # We need to be able to disable shadow warnings for the LLVM + # includes. + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wshadow=local, for CFLAGS" >&5 +$as_echo_n "checking whether ${CC} supports -Wshadow=local, for CFLAGS... " >&6; } +if ${pgac_cv_prog_CC_cflags__Wshadow_local+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_save_CFLAGS=$CFLAGS +pgac_save_CC=$CC +CC=${CC} +CFLAGS="${CFLAGS} -Wshadow=local" +ac_save_c_werror_flag=$ac_c_werror_flag +ac_c_werror_flag=yes +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + pgac_cv_prog_CC_cflags__Wshadow_local=yes +else + pgac_cv_prog_CC_cflags__Wshadow_local=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_c_werror_flag=$ac_save_c_werror_flag +CFLAGS="$pgac_save_CFLAGS" +CC="$pgac_save_CC" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wshadow_local" >&5 +$as_echo "$pgac_cv_prog_CC_cflags__Wshadow_local" >&6; } +if test x"$pgac_cv_prog_CC_cflags__Wshadow_local" = x"yes"; then + CFLAGS="${CFLAGS} -Wshadow=local" +fi + + + save_CXXFLAGS=$CXXFLAGS + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Wshadow=local, for CXXFLAGS" >&5 +$as_echo_n "checking whether ${CXX} supports -Wshadow=local, for CXXFLAGS... " >&6; } +if ${pgac_cv_prog_CXX_cxxflags__Wshadow_local+:} false; then : $as_echo_n "(cached) " >&6 else pgac_save_CXXFLAGS=$CXXFLAGS pgac_save_CXX=$CXX CXX=${CXX} -CXXFLAGS="${CXXFLAGS} -Wformat-security" +CXXFLAGS="${CXXFLAGS} -Wshadow=local" ac_save_cxx_werror_flag=$ac_cxx_werror_flag ac_cxx_werror_flag=yes ac_ext=cpp @@ -6062,9 +6117,9 @@ main () } _ACEOF if ac_fn_cxx_try_compile "$LINENO"; then : - pgac_cv_prog_CXX_cxxflags__Wformat_security=yes + pgac_cv_prog_CXX_cxxflags__Wshadow_local=yes else - pgac_cv_prog_CXX_cxxflags__Wformat_security=no + pgac_cv_prog_CXX_cxxflags__Wshadow_local=no fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext ac_ext=c @@ -6077,61 +6132,19 @@ ac_cxx_werror_flag=$ac_save_cxx_werror_flag CXXFLAGS="$pgac_save_CXXFLAGS" CXX="$pgac_save_CXX" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Wformat_security" >&5 -$as_echo "$pgac_cv_prog_CXX_cxxflags__Wformat_security" >&6; } -if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" = x"yes"; then - CXXFLAGS="${CXXFLAGS} -Wformat-security" -fi - - - # gcc 14+, clang for a while - # (Supported in C++ by clang but not gcc. For consistency, omit in C++.) - save_CFLAGS=$CFLAGS - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wmissing-variable-declarations, for CFLAGS" >&5 -$as_echo_n "checking whether ${CC} supports -Wmissing-variable-declarations, for CFLAGS... " >&6; } -if ${pgac_cv_prog_CC_cflags__Wmissing_variable_declarations+:} false; then : - $as_echo_n "(cached) " >&6 -else - pgac_save_CFLAGS=$CFLAGS -pgac_save_CC=$CC -CC=${CC} -CFLAGS="${CFLAGS} -Wmissing-variable-declarations" -ac_save_c_werror_flag=$ac_c_werror_flag -ac_c_werror_flag=yes -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=yes -else - pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -ac_c_werror_flag=$ac_save_c_werror_flag -CFLAGS="$pgac_save_CFLAGS" -CC="$pgac_save_CC" -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&5 -$as_echo "$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&6; } -if test x"$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" = x"yes"; then - CFLAGS="${CFLAGS} -Wmissing-variable-declarations" +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Wshadow_local" >&5 +$as_echo "$pgac_cv_prog_CXX_cxxflags__Wshadow_local" >&6; } +if test x"$pgac_cv_prog_CXX_cxxflags__Wshadow_local" = x"yes"; then + CXXFLAGS="${CXXFLAGS} -Wshadow=local" fi - PERMIT_MISSING_VARIABLE_DECLARATIONS= - if test x"$save_CFLAGS" != x"$CFLAGS"; then - PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations + PERMIT_CXX_SHADOW= + if test x"$save_CXXFLAGS" != x"$CXXFLAGS"; then + PERMIT_CXX_SHADOW=-Wno-shadow=local fi + # Disable strict-aliasing rules; needed for gcc 3.3+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fno-strict-aliasing, for CFLAGS" >&5 diff --git a/configure.ac b/configure.ac index a331749fcb5..6864268eaa0 100644 --- a/configure.ac +++ b/configure.ac @@ -575,11 +575,11 @@ if test "$GCC" = yes -a "$ICC" = no; then PGAC_PROG_CC_CFLAGS_OPT([-Wcast-function-type]) PGAC_PROG_CXX_CFLAGS_OPT([-Wcast-function-type]) - PGAC_PROG_CC_CFLAGS_OPT([-Wshadow=compatible-local]) - PGAC_PROG_CXX_CFLAGS_OPT([-Wshadow=compatible-local]) + # This was included in -Wall/-Wformat in older GCC versions PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security]) PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security]) + # gcc 14+, clang for a while # (Supported in C++ by clang but not gcc. For consistency, omit in C++.) save_CFLAGS=$CFLAGS @@ -589,6 +589,18 @@ if test "$GCC" = yes -a "$ICC" = no; then PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations fi AC_SUBST(PERMIT_MISSING_VARIABLE_DECLARATIONS) + + # We need to be able to disable shadow warnings for the LLVM + # includes. + PGAC_PROG_CC_CFLAGS_OPT([-Wshadow=local]) + save_CXXFLAGS=$CXXFLAGS + PGAC_PROG_CXX_CFLAGS_OPT([-Wshadow=local]) + PERMIT_CXX_SHADOW= + if test x"$save_CXXFLAGS" != x"$CXXFLAGS"; then + PERMIT_CXX_SHADOW=-Wno-shadow=local + fi + AC_SUBST(PERMIT_CXX_SHADOW) + # Disable strict-aliasing rules; needed for gcc 3.3+ PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing]) PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing]) diff --git a/meson.build b/meson.build index f4cde249242..d05634fef0d 100644 --- a/meson.build +++ b/meson.build @@ -2209,7 +2209,6 @@ common_warning_flags = [ '-Werror=unguarded-availability-new', '-Wmissing-format-attribute', '-Wcast-function-type', - '-Wshadow=compatible-local', # This was included in -Wall/-Wformat in older GCC versions '-Wformat-security', ] @@ -2263,6 +2262,14 @@ if cc.has_argument('-Wmissing-variable-declarations') cflags_no_missing_var_decls += '-Wno-missing-variable-declarations' endif +# We need to be able to disable shadow warnings for the LLVM includes. +cflags_warn += cc.get_supported_arguments('-Wshadow=local') +cxxflags_no_shadow = [] +if have_cxx and cxx.has_argument('-Wshadow=local') + cxxflags_warn += '-Wshadow=local' + cxxflags_no_shadow += '-Wno-shadow=local' +endif + # The following tests want to suppress various unhelpful warnings by adding # -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo # switches, so we have to test for the positive form and if that works, diff --git a/src/Makefile.global.in b/src/Makefile.global.in index cef1ad7f87d..3279ea87eff 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -279,6 +279,7 @@ CFLAGS_CRC = @CFLAGS_CRC@ PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@ PERMIT_MISSING_VARIABLE_DECLARATIONS = @PERMIT_MISSING_VARIABLE_DECLARATIONS@ CXXFLAGS = @CXXFLAGS@ +PERMIT_CXX_SHADOW = @PERMIT_CXX_SHADOW@ have_cxx = @have_cxx@ diff --git a/src/backend/jit/llvm/Makefile b/src/backend/jit/llvm/Makefile index 7a65290a85a..b70a6019f24 100644 --- a/src/backend/jit/llvm/Makefile +++ b/src/backend/jit/llvm/Makefile @@ -24,7 +24,7 @@ NAME = llvmjit # All files in this directory use LLVM. CFLAGS += $(LLVM_CFLAGS) -CXXFLAGS += $(LLVM_CXXFLAGS) +CXXFLAGS += $(LLVM_CXXFLAGS) $(PERMIT_CXX_SHADOW) override CPPFLAGS += $(LLVM_CPPFLAGS) SHLIB_LINK += $(LLVM_LIBS) diff --git a/src/backend/jit/llvm/meson.build b/src/backend/jit/llvm/meson.build index 7df8453ad6f..dc2e129faf1 100644 --- a/src/backend/jit/llvm/meson.build +++ b/src/backend/jit/llvm/meson.build @@ -33,7 +33,7 @@ llvmjit = shared_module('llvmjit', llvmjit_sources, kwargs: pg_mod_args + { 'dependencies': pg_mod_args['dependencies'] + [llvm], - 'cpp_args': pg_mod_args['cpp_args'] + llvm.get_variable(configtool: 'cxxflags').split(), + 'cpp_args': pg_mod_args['cpp_args'] + llvm.get_variable(configtool: 'cxxflags').split() + cxxflags_no_shadow, } ) diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build index 2401025d1cd..d0430b3519e 100644 --- a/src/makefiles/meson.build +++ b/src/makefiles/meson.build @@ -102,6 +102,8 @@ pgxs_kv = { ' '.join(cflags_no_decl_after_statement), 'PERMIT_MISSING_VARIABLE_DECLARATIONS': ' '.join(cflags_no_missing_var_decls), + 'PERMIT_CXX_SHADOW': + ' '.join(cxxflags_no_shadow), 'CFLAGS_CRC': ' '.join(cflags_crc), 'CFLAGS_UNROLL_LOOPS': ' '.join(unroll_loops_cflags),