[PATCH v2 5/6] string: Suppress Clang warnings on tester.c

Sam James sam@gentoo.org
Sun Dec 22 22:25:59 GMT 2024


"H.J. Lu" <hjl.tools@gmail.com> writes:

> Add a configure check for -Wno-fortify-source to suppress Clang warnings
> on string/tester.c, like:
>
> tester.c:385:10: error: 'strncat' size argument is too large; destination buffer has size 50, but size argument is 99 [-Werror,-Wfortify-source]
>   385 |   check (strncat (one, "lmn", 99) == one, 1);   /* Returned value. */
>
> Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
> ---
>  configure       | 34 ++++++++++++++++++++++++++++++++++
>  configure.ac    | 10 ++++++++++
>  string/Makefile |  7 +++++--
>  3 files changed, 49 insertions(+), 2 deletions(-)

Reviewed-by: Sam James <sam@gentoo.org>

>
> diff --git a/configure b/configure
> index 6be04c64cc..40063243a8 100755
> --- a/configure
> +++ b/configure
> @@ -8002,6 +8002,40 @@ test-config-cflags-wno-restrict = $libc_cv_test_cflags_wno_restrict"
>  
>  
>  
> +saved_CC="$CC"
> +CC="$TEST_CC"
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking -Wno-fortify-source in testing" >&5
> +printf %s "checking -Wno-fortify-source in testing... " >&6; }
> +if test ${libc_cv_test_cflags_wno_fortify_source+y}
> +then :
> +  printf %s "(cached) " >&6
> +else case e in #(
> +  e) if { ac_try='${CC-cc} -c -Werror -Wno-fortify-source -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_cflags_wno_fortify_source=-Wno-fortify-source
> +else case e in #(
> +  e) libc_cv_test_cflags_wno_fortify_source=
> + ;;
> +esac
> +fi ;;
> +esac
> +fi
> +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_cflags_wno_fortify_source" >&5
> +printf "%s\n" "$libc_cv_test_cflags_wno_fortify_source" >&6; }
> +
> +CC="$saved_CC"
> +
> +
> +config_vars="$config_vars
> +test-config-cflags-wno-fortify-source = $libc_cv_test_cflags_wno_fortify_source"
> +
> +
> +
>  saved_CC="$CC"
>  CC="$TEST_CC"
>  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking -finput-charset=ascii in testing" >&5
> diff --git a/configure.ac b/configure.ac
> index 5c156556d1..7eac65c630 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1590,6 +1590,16 @@ LIBC_TRY_TEST_CC_OPTION([-Wno-restrict],
>  LIBC_CONFIG_VAR([test-config-cflags-wno-restrict],
>  		[$libc_cv_test_cflags_wno_restrict])
>  
> +dnl Check if TEST_CC supports -Wno-fortify-source.
> +LIBC_TRY_TEST_CC_OPTION([-Wno-fortify-source],
> +  [-c -Werror -Wno-fortify-source],
> +  libc_cv_test_cflags_wno_fortify_source,
> +  [libc_cv_test_cflags_wno_fortify_source=-Wno-fortify-source],
> +  [libc_cv_test_cflags_wno_fortify_source=]
> +)
> +LIBC_CONFIG_VAR([test-config-cflags-wno-fortify-source],
> +		[$libc_cv_test_cflags_wno_fortify_source])
> +
>  dnl Check if TEST_CC supports -finput-charset=ascii.
>  LIBC_TRY_TEST_CC_OPTION([-finput-charset=ascii],
>    [-c -Werror -finput-charset=ascii],
> diff --git a/string/Makefile b/string/Makefile
> index 1dff405c27..ac70d63404 100644
> --- a/string/Makefile
> +++ b/string/Makefile
> @@ -252,8 +252,11 @@ endif
>  
>  include ../Rules
>  
> -CFLAGS-inl-tester.c += -fno-builtin
> -CFLAGS-noinl-tester.c += -fno-builtin
> +CFLAGS-tester.c += $(test-config-cflags-wno-fortify-source)
> +CFLAGS-inl-tester.c += -fno-builtin \
> +		       $(test-config-cflags-wno-fortify-source)
> +CFLAGS-noinl-tester.c += -fno-builtin \
> +		       $(test-config-cflags-wno-fortify-source)
>  CFLAGS-tst-strlen.c += -fno-builtin
>  CFLAGS-stratcliff.c += -fno-builtin
>  CFLAGS-test-ffs.c += -fno-builtin


More information about the Libc-alpha mailing list