[1/6] locale: prevent maybe-uninitialized errors with -Os [BZ #19444]

Message ID 20220921135108.3324737-2-adhemerval.zanella@linaro.org
State Committed
Commit c651f9da530320e9939e6cbad57b87695eeba41c
Headers
Series Fix -Os build |

Commit Message

Adhemerval Zanella Netto Sept. 21, 2022, 1:51 p.m. UTC
  From: Martin Jansa <Martin.Jansa@gmail.com>

Fixes following error when building  with -Os:
| In file included from strcoll_l.c:43:
| strcoll_l.c: In function '__strcoll_l':
| ../locale/weight.h:31:26: error: 'seq2.back_us' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
|    int_fast32_t i = table[*(*cpp)++];
|                           ^~~~~~~~~
| strcoll_l.c:304:18: note: 'seq2.back_us' was declared here
|    coll_seq seq1, seq2;
|                   ^~~~
| In file included from strcoll_l.c:43:
| ../locale/weight.h:31:26: error: 'seq1.back_us' may be used
uninitialized in this function [-Werror=maybe-uninitialized]
|    int_fast32_t i = table[*(*cpp)++];
|                           ^~~~~~~~~
| strcoll_l.c:304:12: note: 'seq1.back_us' was declared here
|    coll_seq seq1, seq2;
|             ^~~~
---
 locale/weight.h | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Carlos O'Donell Oct. 5, 2022, 1:39 p.m. UTC | #1
On Wed, Sep 21, 2022 at 10:51:03AM -0300, Adhemerval Zanella via Libc-alpha wrote:
> From: Martin Jansa <Martin.Jansa@gmail.com>
> 
> Fixes following error when building  with -Os:
> | In file included from strcoll_l.c:43:
> | strcoll_l.c: In function '__strcoll_l':
> | ../locale/weight.h:31:26: error: 'seq2.back_us' may be used
> uninitialized in this function [-Werror=maybe-uninitialized]
> |    int_fast32_t i = table[*(*cpp)++];
> |                           ^~~~~~~~~
> | strcoll_l.c:304:18: note: 'seq2.back_us' was declared here
> |    coll_seq seq1, seq2;
> |                   ^~~~
> | In file included from strcoll_l.c:43:
> | ../locale/weight.h:31:26: error: 'seq1.back_us' may be used
> uninitialized in this function [-Werror=maybe-uninitialized]
> |    int_fast32_t i = table[*(*cpp)++];
> |                           ^~~~~~~~~
> | strcoll_l.c:304:12: note: 'seq1.back_us' was declared here
> |    coll_seq seq1, seq2;
> |             ^~~~

LGTM.

No regresions on x86_64.

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

> ---
>  locale/weight.h | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/locale/weight.h b/locale/weight.h
> index 8be2d220f8..4a4d5aa6b2 100644
> --- a/locale/weight.h
> +++ b/locale/weight.h
> @@ -27,7 +27,14 @@ findidx (const int32_t *table,
>  	 const unsigned char *extra,
>  	 const unsigned char **cpp, size_t len)
>  {
> +  /* With GCC 8 when compiling with -Os the compiler warns that
> +     seq1.back_us and seq2.back_us might be used uninitialized.
> +     This uninitialized use is impossible for the same reason
> +     as described in comments in locale/weightwc.h.  */

OK. Agreed.

> +  DIAG_PUSH_NEEDS_COMMENT;
> +  DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
>    int32_t i = table[*(*cpp)++];
> +  DIAG_POP_NEEDS_COMMENT;
>    const unsigned char *cp;
>    const unsigned char *usrc;
>  
> -- 
> 2.34.1
>
  

Patch

diff --git a/locale/weight.h b/locale/weight.h
index 8be2d220f8..4a4d5aa6b2 100644
--- a/locale/weight.h
+++ b/locale/weight.h
@@ -27,7 +27,14 @@  findidx (const int32_t *table,
 	 const unsigned char *extra,
 	 const unsigned char **cpp, size_t len)
 {
+  /* With GCC 8 when compiling with -Os the compiler warns that
+     seq1.back_us and seq2.back_us might be used uninitialized.
+     This uninitialized use is impossible for the same reason
+     as described in comments in locale/weightwc.h.  */
+  DIAG_PUSH_NEEDS_COMMENT;
+  DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wmaybe-uninitialized");
   int32_t i = table[*(*cpp)++];
+  DIAG_POP_NEEDS_COMMENT;
   const unsigned char *cp;
   const unsigned char *usrc;