[3/6] posix: Suppress -Os may be used uninitialized warnings on regexec

Message ID 20220921135108.3324737-4-adhemerval.zanella@linaro.org
State Committed
Commit 442e3a21724b07b3ae1c3c5eeba4a8e44a1a50a3
Headers
Series Fix -Os build |

Commit Message

Adhemerval Zanella Sept. 21, 2022, 1:51 p.m. UTC
  GCC with -Os issues may uninitialized warnings on regexec code.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 posix/regexec.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Carlos O'Donell Oct. 5, 2022, 1:49 p.m. UTC | #1
On Wed, Sep 21, 2022 at 10:51:05AM -0300, Adhemerval Zanella via Libc-alpha wrote:
> GCC with -Os issues may uninitialized warnings on regexec code.

LGTM.

This is also gnulib code. Needs eventual harmonization.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> Checked on x86_64-linux-gnu and i686-linux-gnu.
> ---
>  posix/regexec.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/posix/regexec.c b/posix/regexec.c
> index cffeaf2845..386a757f35 100644
> --- a/posix/regexec.c
> +++ b/posix/regexec.c
> @@ -3768,7 +3768,13 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
>  	      _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
>  	  for (i = 0; i < cset->ncoll_syms; ++i)
>  	    {
> +	      /* The compiler might warn that extra may be used uninitialized,
> +		 however the loop will be executed iff ncoll_syms is larger
> +		 than 0,which means extra will be already initialized.  */
> +	      DIAG_PUSH_NEEDS_COMMENT;
> +	      DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
>  	      const unsigned char *coll_sym = extra + cset->coll_syms[i];
> +	      DIAG_POP_NEEDS_COMMENT;

OK. Agreed.

>  	      /* Compare the length of input collating element and
>  		 the length of current collating element.  */
>  	      if (*coll_sym != elem_len)
> -- 
> 2.34.1
>
  

Patch

diff --git a/posix/regexec.c b/posix/regexec.c
index cffeaf2845..386a757f35 100644
--- a/posix/regexec.c
+++ b/posix/regexec.c
@@ -3768,7 +3768,13 @@  check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx,
 	      _NL_CURRENT (LC_COLLATE, _NL_COLLATE_SYMB_EXTRAMB);
 	  for (i = 0; i < cset->ncoll_syms; ++i)
 	    {
+	      /* The compiler might warn that extra may be used uninitialized,
+		 however the loop will be executed iff ncoll_syms is larger
+		 than 0,which means extra will be already initialized.  */
+	      DIAG_PUSH_NEEDS_COMMENT;
+	      DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
 	      const unsigned char *coll_sym = extra + cset->coll_syms[i];
+	      DIAG_POP_NEEDS_COMMENT;
 	      /* Compare the length of input collating element and
 		 the length of current collating element.  */
 	      if (*coll_sym != elem_len)