diff options
Diffstat (limited to 'm4/manywarnings.m4')
-rw-r--r-- | m4/manywarnings.m4 | 119 |
1 files changed, 57 insertions, 62 deletions
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4 index 7402edcddfd..3c6795ceb28 100644 --- a/m4/manywarnings.m4 +++ b/m4/manywarnings.m4 @@ -1,4 +1,4 @@ -# manywarnings.m4 serial 23 +# manywarnings.m4 serial 25 dnl Copyright (C) 2008-2024 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -6,6 +6,8 @@ dnl with or without modifications, as long as this notice is preserved. dnl From Simon Josefsson +AC_PREREQ([2.64]) + # gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) # -------------------------------------------------- # Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. @@ -21,7 +23,7 @@ AC_DEFUN([gl_MANYWARN_COMPLEMENT], *" $gl_warn_item "*) ;; *) - gl_AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"]) + AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"]) ;; esac done @@ -46,59 +48,46 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)], dnl First, check for some issues that only occur when combining multiple dnl gcc warning categories. AC_REQUIRE([AC_PROG_CC]) - if test -n "$GCC"; then - - dnl Check if -Wextra -Werror -Wno-missing-field-initializers is supported - dnl with the current $CC $CFLAGS $CPPFLAGS. - AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported], - [gl_cv_cc_nomfi_supported], - [gl_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -Wextra -Werror -Wno-missing-field-initializers" + AS_IF([test -n "$GCC"], [ + AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed], + [gl_cv_cc_nomfi_needed], + [gl_cv_cc_nomfi_needed=no + gl_saved_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wextra -Werror" AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[]], [[]])], - [gl_cv_cc_nomfi_supported=yes], - [gl_cv_cc_nomfi_supported=no]) - CFLAGS="$gl_save_CFLAGS" - ]) - - if test "$gl_cv_cc_nomfi_supported" = yes; then - dnl Now check whether -Wno-missing-field-initializers is needed - dnl for the { 0, } construct. - AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed], - [gl_cv_cc_nomfi_needed], - [gl_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -Wextra -Werror" - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM( - [[int f (void) - { - typedef struct { int a; int b; } s_t; - s_t s1 = { 0, }; - return s1.b; - } - ]], - [[]])], - [gl_cv_cc_nomfi_needed=no], - [gl_cv_cc_nomfi_needed=yes]) - CFLAGS="$gl_save_CFLAGS" - ]) - fi + [AC_LANG_PROGRAM( + [[struct file_data { int desc, name; }; + struct cmp { struct file_data file[1]; }; + void f (struct cmp *r) + { + typedef struct { int a; int b; } s_t; + s_t s1 = { 0, }; + struct cmp cmp = { .file[0].desc = r->file[0].desc + s1.a }; + *r = cmp; + } + ]], + [[]])], + [], + [CFLAGS="$CFLAGS -Wno-missing-field-initializers" + AC_COMPILE_IFELSE([], + [gl_cv_cc_nomfi_needed=yes])]) + CFLAGS="$gl_saved_CFLAGS" + ]) dnl Next, check if -Werror -Wuninitialized is useful with the dnl user's choice of $CFLAGS; some versions of gcc warn that it dnl has no effect if -O is not also used AC_CACHE_CHECK([whether -Wuninitialized is supported], [gl_cv_cc_uninitialized_supported], - [gl_save_CFLAGS="$CFLAGS" + [gl_saved_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -Werror -Wuninitialized" AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[]], [[]])], [gl_cv_cc_uninitialized_supported=yes], [gl_cv_cc_uninitialized_supported=no]) - CFLAGS="$gl_save_CFLAGS" + CFLAGS="$gl_saved_CFLAGS" ]) - - fi + ]) # List all gcc warning categories. # To compare this list to your installed GCC's, run this Bash command: @@ -109,7 +98,7 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)], # <(LC_ALL=C gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort) $1= - for gl_manywarn_item in -fanalyzer -fno-common \ + for gl_manywarn_item in -fanalyzer -fstrict-flex-arrays \ -Wall \ -Warith-conversion \ -Wbad-function-cast \ @@ -137,6 +126,7 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)], -Wpointer-arith \ -Wshadow \ -Wstack-protector \ + -Wstrict-flex-arrays \ -Wstrict-overflow \ -Wstrict-prototypes \ -Wsuggest-attribute=cold \ @@ -160,46 +150,51 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC(C)], -Wwrite-strings \ \ ; do - gl_AS_VAR_APPEND([$1], [" $gl_manywarn_item"]) + AS_VAR_APPEND([$1], [" $gl_manywarn_item"]) done # gcc --help=warnings outputs an unusual form for these options; list # them here so that the above 'comm' command doesn't report a false match. - gl_AS_VAR_APPEND([$1], [' -Warray-bounds=2']) - gl_AS_VAR_APPEND([$1], [' -Wattribute-alias=2']) - gl_AS_VAR_APPEND([$1], [' -Wbidi-chars=any,ucn']) - gl_AS_VAR_APPEND([$1], [' -Wformat-overflow=2']) - gl_AS_VAR_APPEND([$1], [' -Wformat=2']) - gl_AS_VAR_APPEND([$1], [' -Wformat-truncation=2']) - gl_AS_VAR_APPEND([$1], [' -Wimplicit-fallthrough=5']) - gl_AS_VAR_APPEND([$1], [' -Wshift-overflow=2']) - gl_AS_VAR_APPEND([$1], [' -Wuse-after-free=3']) - gl_AS_VAR_APPEND([$1], [' -Wunused-const-variable=2']) - gl_AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031']) + AS_VAR_APPEND([$1], [' -Warray-bounds=2']) + AS_VAR_APPEND([$1], [' -Wattribute-alias=2']) + AS_VAR_APPEND([$1], [' -Wbidi-chars=any,ucn']) + AS_VAR_APPEND([$1], [' -Wformat-overflow=2']) + AS_VAR_APPEND([$1], [' -Wformat=2']) + AS_VAR_APPEND([$1], [' -Wformat-truncation=2']) + AS_VAR_APPEND([$1], [' -Wimplicit-fallthrough=5']) + AS_VAR_APPEND([$1], [' -Wshift-overflow=2']) + AS_VAR_APPEND([$1], [' -Wuse-after-free=3']) + AS_VAR_APPEND([$1], [' -Wunused-const-variable=2']) + AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031']) # These are needed for older GCC versions. - if test -n "$GCC"; then - case `($CC --version) 2>/dev/null` in + if test -n "$GCC" && gl_gcc_version=`($CC --version) 2>/dev/null`; then + case $gl_gcc_version in 'gcc (GCC) '[[0-3]].* | \ 'gcc (GCC) '4.[[0-7]].*) - gl_AS_VAR_APPEND([$1], [' -fdiagnostics-show-option']) - gl_AS_VAR_APPEND([$1], [' -funit-at-a-time']) + AS_VAR_APPEND([$1], [' -fdiagnostics-show-option']) + AS_VAR_APPEND([$1], [' -funit-at-a-time']) + ;; + esac + case $gl_gcc_version in + 'gcc (GCC) '[[0-9]].*) + AS_VAR_APPEND([$1], [' -fno-common']) ;; esac fi # Disable specific options as needed. if test "$gl_cv_cc_nomfi_needed" = yes; then - gl_AS_VAR_APPEND([$1], [' -Wno-missing-field-initializers']) + AS_VAR_APPEND([$1], [' -Wno-missing-field-initializers']) fi if test "$gl_cv_cc_uninitialized_supported" = no; then - gl_AS_VAR_APPEND([$1], [' -Wno-uninitialized']) + AS_VAR_APPEND([$1], [' -Wno-uninitialized']) fi # This warning have too many false alarms in GCC 11.2.1. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101713 - gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-malloc-leak']) + AS_VAR_APPEND([$1], [' -Wno-analyzer-malloc-leak']) AC_LANG_POP([C]) ]) |