Add -Wmissing-variable-declarations to the standard compilation flags
This warning flag detects global variables not declared in header files. This is similar to what -Wmissing-prototypes does for functions. (More correctly, it is similar to what -Wmissing-declarations does for functions, but -Wmissing-prototypes is a superset of that in C.) This flag is new in GCC 14. Clang has supported it for a while. Several recent commits have cleaned up warnings triggered by this, so it should now be clean. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c95ce@eisentraut.org
This commit is contained in:
parent
7926a9a80f
commit
6618891256
49
configure
vendored
49
configure
vendored
@ -741,6 +741,7 @@ CXXFLAGS_SL_MODULE
|
|||||||
CFLAGS_SL_MODULE
|
CFLAGS_SL_MODULE
|
||||||
CFLAGS_VECTORIZE
|
CFLAGS_VECTORIZE
|
||||||
CFLAGS_UNROLL_LOOPS
|
CFLAGS_UNROLL_LOOPS
|
||||||
|
PERMIT_MISSING_VARIABLE_DECLARATIONS
|
||||||
PERMIT_DECLARATION_AFTER_STATEMENT
|
PERMIT_DECLARATION_AFTER_STATEMENT
|
||||||
LLVM_BINPATH
|
LLVM_BINPATH
|
||||||
LLVM_CXXFLAGS
|
LLVM_CXXFLAGS
|
||||||
@ -6022,6 +6023,54 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" = x"yes"; then
|
|||||||
fi
|
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"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
PERMIT_MISSING_VARIABLE_DECLARATIONS=
|
||||||
|
if test x"$save_CFLAGS" != x"$CFLAGS"; then
|
||||||
|
PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations
|
||||||
|
fi
|
||||||
|
|
||||||
# Disable strict-aliasing rules; needed for gcc 3.3+
|
# 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
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fno-strict-aliasing, for CFLAGS" >&5
|
||||||
|
@ -518,6 +518,15 @@ if test "$GCC" = yes -a "$ICC" = no; then
|
|||||||
# This was included in -Wall/-Wformat in older GCC versions
|
# This was included in -Wall/-Wformat in older GCC versions
|
||||||
PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
|
PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
|
||||||
PGAC_PROG_CXX_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
|
||||||
|
PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-variable-declarations])
|
||||||
|
PERMIT_MISSING_VARIABLE_DECLARATIONS=
|
||||||
|
if test x"$save_CFLAGS" != x"$CFLAGS"; then
|
||||||
|
PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations
|
||||||
|
fi
|
||||||
|
AC_SUBST(PERMIT_MISSING_VARIABLE_DECLARATIONS)
|
||||||
# Disable strict-aliasing rules; needed for gcc 3.3+
|
# Disable strict-aliasing rules; needed for gcc 3.3+
|
||||||
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
|
PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
|
||||||
PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing])
|
PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing])
|
||||||
|
10
meson.build
10
meson.build
@ -1986,6 +1986,16 @@ if cc.has_argument('-Wdeclaration-after-statement')
|
|||||||
cflags_no_decl_after_statement += '-Wno-declaration-after-statement'
|
cflags_no_decl_after_statement += '-Wno-declaration-after-statement'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Some code is not clean for -Wmissing-variable-declarations, so we
|
||||||
|
# make the "no" option available. Also, while clang supports this
|
||||||
|
# option for C++, gcc does not, so for consistency, leave it off for
|
||||||
|
# C++.
|
||||||
|
cflags_no_missing_var_decls = []
|
||||||
|
if cc.has_argument('-Wmissing-variable-declarations')
|
||||||
|
cflags_warn += '-Wmissing-variable-declarations'
|
||||||
|
cflags_no_missing_var_decls += '-Wno-missing-variable-declarations'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
# The following tests want to suppress various unhelpful warnings by adding
|
# The following tests want to suppress various unhelpful warnings by adding
|
||||||
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
|
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
|
||||||
|
@ -266,6 +266,7 @@ CFLAGS_POPCNT = @CFLAGS_POPCNT@
|
|||||||
CFLAGS_CRC = @CFLAGS_CRC@
|
CFLAGS_CRC = @CFLAGS_CRC@
|
||||||
CFLAGS_XSAVE = @CFLAGS_XSAVE@
|
CFLAGS_XSAVE = @CFLAGS_XSAVE@
|
||||||
PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
|
PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
|
||||||
|
PERMIT_MISSING_VARIABLE_DECLARATIONS = @PERMIT_MISSING_VARIABLE_DECLARATIONS@
|
||||||
CXXFLAGS = @CXXFLAGS@
|
CXXFLAGS = @CXXFLAGS@
|
||||||
|
|
||||||
LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
|
LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
override CPPFLAGS := -I../../include -I$(top_srcdir)/src/interfaces/ecpg/include \
|
override CPPFLAGS := -I../../include -I$(top_srcdir)/src/interfaces/ecpg/include \
|
||||||
-I$(libpq_srcdir) $(CPPFLAGS)
|
-I$(libpq_srcdir) $(CPPFLAGS)
|
||||||
override CFLAGS += $(PTHREAD_CFLAGS)
|
override CFLAGS += $(PTHREAD_CFLAGS) $(PERMIT_MISSING_VARIABLE_DECLARATIONS)
|
||||||
|
|
||||||
LDFLAGS_INTERNAL += -L../../ecpglib -lecpg -L../../pgtypeslib -lpgtypes $(libpq)
|
LDFLAGS_INTERNAL += -L../../ecpglib -lecpg -L../../pgtypeslib -lpgtypes $(libpq)
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ testprep_targets += pg_regress_ecpg
|
|||||||
|
|
||||||
# create .c files and executables from .pgc files
|
# create .c files and executables from .pgc files
|
||||||
ecpg_test_exec_kw = {
|
ecpg_test_exec_kw = {
|
||||||
|
'c_args': cflags_no_missing_var_decls,
|
||||||
'dependencies': [frontend_code, libpq],
|
'dependencies': [frontend_code, libpq],
|
||||||
'include_directories': [ecpg_inc],
|
'include_directories': [ecpg_inc],
|
||||||
'link_with': [ecpglib_so, ecpg_compat_so, ecpg_pgtypes_so],
|
'link_with': [ecpglib_so, ecpg_compat_so, ecpg_pgtypes_so],
|
||||||
|
@ -98,6 +98,8 @@ pgxs_kv = {
|
|||||||
'CXXFLAGS_SL_MODULE': ' '.join(cxxflags_mod),
|
'CXXFLAGS_SL_MODULE': ' '.join(cxxflags_mod),
|
||||||
'PERMIT_DECLARATION_AFTER_STATEMENT':
|
'PERMIT_DECLARATION_AFTER_STATEMENT':
|
||||||
' '.join(cflags_no_decl_after_statement),
|
' '.join(cflags_no_decl_after_statement),
|
||||||
|
'PERMIT_MISSING_VARIABLE_DECLARATIONS':
|
||||||
|
' '.join(cflags_no_missing_var_decls),
|
||||||
|
|
||||||
'CFLAGS_CRC': ' '.join(cflags_crc),
|
'CFLAGS_CRC': ' '.join(cflags_crc),
|
||||||
'CFLAGS_POPCNT': ' '.join(cflags_popcnt),
|
'CFLAGS_POPCNT': ' '.join(cflags_popcnt),
|
||||||
|
@ -25,6 +25,8 @@ OBJS = \
|
|||||||
parse.o \
|
parse.o \
|
||||||
pr_comment.o
|
pr_comment.o
|
||||||
|
|
||||||
|
$(OBJS): CFLAGS += $(PERMIT_MISSING_VARIABLE_DECLARATIONS)
|
||||||
|
|
||||||
all: pg_bsd_indent
|
all: pg_bsd_indent
|
||||||
|
|
||||||
pg_bsd_indent: $(OBJS) | submake-libpgport
|
pg_bsd_indent: $(OBJS) | submake-libpgport
|
||||||
|
@ -18,6 +18,7 @@ endif
|
|||||||
|
|
||||||
pg_bsd_indent = executable('pg_bsd_indent',
|
pg_bsd_indent = executable('pg_bsd_indent',
|
||||||
pg_bsd_indent_sources,
|
pg_bsd_indent_sources,
|
||||||
|
c_args: cflags_no_missing_var_decls,
|
||||||
dependencies: [frontend_code],
|
dependencies: [frontend_code],
|
||||||
include_directories: include_directories('.'),
|
include_directories: include_directories('.'),
|
||||||
kwargs: default_bin_args + {
|
kwargs: default_bin_args + {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user