1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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 f9fc9a78a3.  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 704ef84ef2 but
then reverted in 7a0aa99e51, 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
This commit is contained in:
Peter Eisentraut
2026-09-24 11:12:17 +02:00
parent 4545cee303
commit 3ee0edb916
7 changed files with 130 additions and 95 deletions

193
configure vendored
View File

@@ -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,96 +5903,6 @@ 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 :
$as_echo_n "(cached) " >&6
else
pgac_save_CFLAGS=$CFLAGS
pgac_save_CC=$CC
CC=${CC}
CFLAGS="${CFLAGS} -Wshadow=compatible-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_compatible_local=yes
else
pgac_cv_prog_CC_cflags__Wshadow_compatible_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_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"
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_n "(cached) " >&6
else
pgac_save_CXXFLAGS=$CXXFLAGS
pgac_save_CXX=$CXX
CXX=${CXX}
CXXFLAGS="${CXXFLAGS} -Wshadow=compatible-local"
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
ac_cxx_werror_flag=yes
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local=yes
else
pgac_cv_prog_CXX_cxxflags__Wshadow_compatible_local=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
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"
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
@@ -6084,6 +5995,7 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" = x"yes"; then
fi
# gcc 14+, clang for a while
# (Supported in C++ by clang but not gcc. For consistency, omit in C++.)
save_CFLAGS=$CFLAGS
@@ -6132,6 +6044,107 @@ fi
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} -Wshadow=local"
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
ac_cxx_werror_flag=yes
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int
main ()
{
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_compile "$LINENO"; then :
pgac_cv_prog_CXX_cxxflags__Wshadow_local=yes
else
pgac_cv_prog_CXX_cxxflags__Wshadow_local=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
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_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_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

View File

@@ -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])

View File

@@ -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,

View File

@@ -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@

View File

@@ -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)

View File

@@ -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,
}
)

View File

@@ -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),