[v2] Turn on -Wimplicit-fallthrough by default if available

Message ID 87v80b1bnz.fsf@oldenburg.str.redhat.com
State Committed
Commit 4331769c0fd522045ab6b30e0ea5dff59ec73019
Headers
Series [v2] Turn on -Wimplicit-fallthrough by default if available |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed

Commit Message

Florian Weimer Aug. 8, 2024, 11:44 a.m. UTC
  ---
v2: Use AC_CACHE_CHECK, LIBC_TRY_CC_OPTION, LIBC_CONFIG_VAR.
 Makeconfig   |  2 +-
 configure    | 26 ++++++++++++++++++++++++++
 configure.ac |  9 +++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)


base-commit: d5ce0e960dea325ccf12769681d5ce45f7b7411d
  

Comments

Adhemerval Zanella Netto Aug. 9, 2024, 12:52 p.m. UTC | #1
LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

On 08/08/24 08:44, Florian Weimer wrote:
> ---
> v2: Use AC_CACHE_CHECK, LIBC_TRY_CC_OPTION, LIBC_CONFIG_VAR.
>  Makeconfig   |  2 +-
>  configure    | 26 ++++++++++++++++++++++++++
>  configure.ac |  9 +++++++++
>  3 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/Makeconfig b/Makeconfig
> index 2d4343b604..a87ff7b1d3 100644
> --- a/Makeconfig
> +++ b/Makeconfig
> @@ -888,7 +888,7 @@ host-test-program-cmd = $(host-built-program-cmd)
>  endif
>  
>  # Extra flags to pass to GCC.
> -+gccwarn := -Wall -Wwrite-strings -Wundef
> ++gccwarn := -Wall -Wwrite-strings -Wundef $(cc-option-wimplicit-fallthrough)
>  ifeq ($(enable-werror),yes)
>  +gccwarn += -Werror
>  endif
> diff --git a/configure b/configure
> index 1d543548cd..ec0b62db36 100755
> --- a/configure
> +++ b/configure
> @@ -7465,6 +7465,32 @@ if test $libc_cv_cc_loop_to_function = yes; then
>  fi
>  
>  
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -Wimplicit-fallthrough" >&5
> +printf %s "checking for -Wimplicit-fallthrough... " >&6; }
> +if test ${libc_cv_cc_wimplicit_fallthrough+y}
> +then :
> +  printf %s "(cached) " >&6
> +else case e in #(
> +  e) if { ac_try='${CC-cc} -Werror -Wimplicit-fallthrough -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_wimplicit_fallthrough=-Wimplicit-fallthrough
> +else case e in #(
> +  e) libc_cv_cc_wimplicit_fallthrough= ;;
> +esac
> +fi
> + ;;
> +esac
> +fi
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_wimplicit_fallthrough" >&5
> +printf "%s\n" "$libc_cv_cc_wimplicit_fallthrough" >&6; }
> +config_vars="$config_vars
> +cc-option-wimplicit-fallthrough = $libc_cv_cc_wimplicit_fallthrough"
> +
>  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libgd" >&5
>  printf %s "checking for libgd... " >&6; }
>  if test "$with_gd" != "no"; then
> diff --git a/configure.ac b/configure.ac
> index 9cbc0bf68f..7c9b57789e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1468,6 +1468,15 @@ if test $libc_cv_cc_loop_to_function = yes; then
>  fi
>  AC_SUBST(libc_cv_cc_loop_to_function)
>  
> +AC_CACHE_CHECK([for -Wimplicit-fallthrough],
> +	       libc_cv_cc_wimplicit_fallthrough, [dnl
> +LIBC_TRY_CC_OPTION([-Werror -Wimplicit-fallthrough],
> +		   [libc_cv_cc_wimplicit_fallthrough=-Wimplicit-fallthrough],
> +		   [libc_cv_cc_wimplicit_fallthrough=])
> +])
> +LIBC_CONFIG_VAR([cc-option-wimplicit-fallthrough],
> +		[$libc_cv_cc_wimplicit_fallthrough])
> +
>  dnl Check whether we have the gd library available.
>  AC_MSG_CHECKING(for libgd)
>  if test "$with_gd" != "no"; then
> 
> base-commit: d5ce0e960dea325ccf12769681d5ce45f7b7411d
>
  

Patch

diff --git a/Makeconfig b/Makeconfig
index 2d4343b604..a87ff7b1d3 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -888,7 +888,7 @@  host-test-program-cmd = $(host-built-program-cmd)
 endif
 
 # Extra flags to pass to GCC.
-+gccwarn := -Wall -Wwrite-strings -Wundef
++gccwarn := -Wall -Wwrite-strings -Wundef $(cc-option-wimplicit-fallthrough)
 ifeq ($(enable-werror),yes)
 +gccwarn += -Werror
 endif
diff --git a/configure b/configure
index 1d543548cd..ec0b62db36 100755
--- a/configure
+++ b/configure
@@ -7465,6 +7465,32 @@  if test $libc_cv_cc_loop_to_function = yes; then
 fi
 
 
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -Wimplicit-fallthrough" >&5
+printf %s "checking for -Wimplicit-fallthrough... " >&6; }
+if test ${libc_cv_cc_wimplicit_fallthrough+y}
+then :
+  printf %s "(cached) " >&6
+else case e in #(
+  e) if { ac_try='${CC-cc} -Werror -Wimplicit-fallthrough -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_wimplicit_fallthrough=-Wimplicit-fallthrough
+else case e in #(
+  e) libc_cv_cc_wimplicit_fallthrough= ;;
+esac
+fi
+ ;;
+esac
+fi
+{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_wimplicit_fallthrough" >&5
+printf "%s\n" "$libc_cv_cc_wimplicit_fallthrough" >&6; }
+config_vars="$config_vars
+cc-option-wimplicit-fallthrough = $libc_cv_cc_wimplicit_fallthrough"
+
 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libgd" >&5
 printf %s "checking for libgd... " >&6; }
 if test "$with_gd" != "no"; then
diff --git a/configure.ac b/configure.ac
index 9cbc0bf68f..7c9b57789e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1468,6 +1468,15 @@  if test $libc_cv_cc_loop_to_function = yes; then
 fi
 AC_SUBST(libc_cv_cc_loop_to_function)
 
+AC_CACHE_CHECK([for -Wimplicit-fallthrough],
+	       libc_cv_cc_wimplicit_fallthrough, [dnl
+LIBC_TRY_CC_OPTION([-Werror -Wimplicit-fallthrough],
+		   [libc_cv_cc_wimplicit_fallthrough=-Wimplicit-fallthrough],
+		   [libc_cv_cc_wimplicit_fallthrough=])
+])
+LIBC_CONFIG_VAR([cc-option-wimplicit-fallthrough],
+		[$libc_cv_cc_wimplicit_fallthrough])
+
 dnl Check whether we have the gd library available.
 AC_MSG_CHECKING(for libgd)
 if test "$with_gd" != "no"; then