Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame^] | 1 | From bd2b87eaa2e99310f5439df95bea12a48dc978bf Mon Sep 17 00:00:00 2001 |
| 2 | From: Martin Jansa <martin.jansa@gmail.com> |
| 3 | Date: Mon, 17 Dec 2018 21:36:18 +0000 |
| 4 | Subject: [PATCH] locale: prevent maybe-uninitialized errors with -Os [BZ |
| 5 | #19444] |
| 6 | |
| 7 | Fixes following error when building for aarch64 with -Os: |
| 8 | | In file included from strcoll_l.c:43: |
| 9 | | strcoll_l.c: In function '__strcoll_l': |
| 10 | | ../locale/weight.h:31:26: error: 'seq2.back_us' may be used uninitialized in this function [-Werror=maybe-uninitialized] |
| 11 | | int_fast32_t i = table[*(*cpp)++]; |
| 12 | | ^~~~~~~~~ |
| 13 | | strcoll_l.c:304:18: note: 'seq2.back_us' was declared here |
| 14 | | coll_seq seq1, seq2; |
| 15 | | ^~~~ |
| 16 | | In file included from strcoll_l.c:43: |
| 17 | | ../locale/weight.h:31:26: error: 'seq1.back_us' may be used uninitialized in this function [-Werror=maybe-uninitialized] |
| 18 | | int_fast32_t i = table[*(*cpp)++]; |
| 19 | | ^~~~~~~~~ |
| 20 | | strcoll_l.c:304:12: note: 'seq1.back_us' was declared here |
| 21 | | coll_seq seq1, seq2; |
| 22 | | ^~~~ |
| 23 | |
| 24 | Partial fix for [BZ #19444] |
| 25 | * locale/weight.h: Fix build with -Os. |
| 26 | |
| 27 | Upstream-Status: Submitted [https://patchwork.ozlabs.org/patch/1014766] |
| 28 | |
| 29 | Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> |
| 30 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 31 | --- |
| 32 | locale/weight.h | 7 +++++++ |
| 33 | 1 file changed, 7 insertions(+) |
| 34 | |
| 35 | diff --git a/locale/weight.h b/locale/weight.h |
| 36 | index 8be2d220f8..4a4d5aa6b2 100644 |
| 37 | --- a/locale/weight.h |
| 38 | +++ b/locale/weight.h |
| 39 | @@ -27,7 +27,14 @@ findidx (const int32_t *table, |
| 40 | const unsigned char *extra, |
| 41 | const unsigned char **cpp, size_t len) |
| 42 | { |
| 43 | + /* With GCC 8 when compiling with -Os the compiler warns that |
| 44 | + seq1.back_us and seq2.back_us might be used uninitialized. |
| 45 | + This uninitialized use is impossible for the same reason |
| 46 | + as described in comments in locale/weightwc.h. */ |
| 47 | + DIAG_PUSH_NEEDS_COMMENT; |
| 48 | + DIAG_IGNORE_Os_NEEDS_COMMENT (8, "-Wmaybe-uninitialized"); |
| 49 | int32_t i = table[*(*cpp)++]; |
| 50 | + DIAG_POP_NEEDS_COMMENT; |
| 51 | const unsigned char *cp; |
| 52 | const unsigned char *usrc; |
| 53 | |