Turn on -Wfree-labels by default if available

This flags a hazard for backporting changes to earlier branches.

Reviewed-by: Sam James <sam@gentoo.org>
This commit is contained in:
Florian Weimer 2025-05-26 08:49:19 +02:00
parent 319f94dea2
commit 4f4c4fcde7
3 changed files with 74 additions and 1 deletions

View File

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

61
configure vendored
View File

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

View File

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