[PATCH] Turn on -Wfree-labels by default if available
Sam James
sam@gentoo.org
Thu May 22 23:12:09 GMT 2025
Florian Weimer <fweimer@redhat.com> writes:
> This flags a hazard for backporting changes to earlier branches.
>
Do we need to do -Wmissing-parameter-name as well?
Reviewed-by: Sam James <sam@gentoo.org>
> ---
> Makeconfig | 3 ++-
> configure | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> configure.ac | 11 +++++++++++
> 3 files changed, 74 insertions(+), 1 deletion(-)
>
> diff --git a/Makeconfig b/Makeconfig
> index a2ea4f6a33..d5ca908df4 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -892,7 +892,8 @@ host-test-program-cmd = $(host-built-program-cmd)
> endif
>
> # Extra flags to pass to GCC.
> -+gccwarn := -Wall -Wwrite-strings -Wundef $(cc-option-wimplicit-fallthrough)
> ++gccwarn := -Wall -Wwrite-strings -Wundef $(cc-option-wimplicit-fallthrough) \
> + $(cc-option-wfree-labels)
> ifeq ($(enable-werror),yes)
> +gccwarn += -Werror
> endif
> diff --git a/configure b/configure
> index 7decd93baa..c8fd47caae 100755
> --- a/configure
> +++ b/configure
> @@ -649,6 +649,7 @@ have_selinux
> have_libcap
> have_libaudit
> LIBGD
> +libc_cv_test_cc_wfree_labels
> libc_cv_test_cc_wimplicit_fallthrough
> libc_cv_cc_loop_to_function
> libc_cv_test_cc_signaling_nans
> @@ -7968,6 +7969,66 @@ config_vars="$config_vars
> cc-option-wimplicit-fallthrough = $libc_cv_cc_wimplicit_fallthrough"
>
>
> +
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -Wfree-labels" >&5
> +printf %s "checking for -Wfree-labels... " >&6; }
> +if test ${libc_cv_cc_wfree_labels+y}
> +then :
> + printf %s "(cached) " >&6
> +else case e in #(
> + e) if { ac_try='${CC-cc} -Werror -Wfree-labels -xc /dev/null -S -o /dev/null'
> + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
> + (eval $ac_try) 2>&5
> + ac_status=$?
> + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
> + test $ac_status = 0; }; }
> +then :
> + libc_cv_cc_wfree_labels=-Wfree-labels
> +else case e in #(
> + e) libc_cv_cc_wfree_labels= ;;
> +esac
> +fi ;;
> +esac
> +fi
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_wfree_labels" >&5
> +printf "%s\n" "$libc_cv_cc_wfree_labels" >&6; }
> +if test "$TEST_CC" = "$CC"; then
> + libc_cv_test_cc_wfree_labels=$libc_cv_cc_wfree_labels
> +else
> +
> +saved_CC="$CC"
> +CC="$TEST_CC"
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -Wfree-labels in testing" >&5
> +printf %s "checking for -Wfree-labels in testing... " >&6; }
> +if test ${libc_cv_test_cc_wfree_labels+y}
> +then :
> + printf %s "(cached) " >&6
> +else case e in #(
> + e) if { ac_try='${CC-cc} -Werror -Wfree-labels -xc /dev/null -S -o /dev/null'
> + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
> + (eval $ac_try) 2>&5
> + ac_status=$?
> + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
> + test $ac_status = 0; }; }
> +then :
> + libc_cv_test_cc_wfree_labels=-Wfree-labels
> +else case e in #(
> + e) libc_cv_test_cc_wfree_labels= ;;
> +esac
> +fi ;;
> +esac
> +fi
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cc_wfree_labels" >&5
> +printf "%s\n" "$libc_cv_test_cc_wfree_labels" >&6; }
> +
> +CC="$saved_CC"
> +
> +fi
> +
> +config_vars="$config_vars
> +cc-option-wfree-labels = $libc_cv_cc_wfree_labels"
> +
> +
> conftest_code="
> void bar (void (*callback) (void));
> int foo (void)
> diff --git a/configure.ac b/configure.ac
> index abd3b238d2..6cf66c82a1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1575,6 +1575,17 @@ LIBC_CONFIG_VAR([cc-option-wimplicit-fallthrough],
> [$libc_cv_cc_wimplicit_fallthrough])
> AC_SUBST(libc_cv_test_cc_wimplicit_fallthrough)
>
> +LIBC_TRY_CC_AND_TEST_CC_OPTION([for -Wfree-labels],
> + [-Werror -Wfree-labels],
> + libc_cv_cc_wfree_labels,
> + [libc_cv_cc_wfree_labels=-Wfree-labels],
> + [libc_cv_cc_wfree_labels=],
> + libc_cv_test_cc_wfree_labels,
> + [libc_cv_test_cc_wfree_labels=-Wfree-labels],
> + [libc_cv_test_cc_wfree_labels=])
> +LIBC_CONFIG_VAR([cc-option-wfree-labels], [$libc_cv_cc_wfree_labels])
> +AC_SUBST(libc_cv_test_cc_wfree_labels)
> +
> conftest_code="
> void bar (void (*callback) (void));
> int foo (void)
>
> base-commit: 4052d99ead880797cf271309fd87ddd2b95bd353
More information about the Libc-alpha
mailing list