From: Carlos O'Donell <carlos@redhat.com>
To: GNU C Library <libc-alpha@sourceware.org>
Subject: [PATCH] Fix i486 builds with gcc 5.3
Date: Thu, 27 Oct 2016 20:25:00 -0000 [thread overview]
Message-ID: <b10e2136-4d2a-e1aa-5d82-ecb07bbbeef6@redhat.com> (raw)
While investigating bug 20729 I found that the i486 builds fail with
gcc 5.3 with two sets of warnings like the following, one for normal
characters and another for wide characters.
The exact warnings look like this:
~~~
In file included from ../string/strcoll_l.c:43:0,
from wcscoll_l.c:32:
../string/strcoll_l.c: In function â__wcscoll_lâ:
../string/../locale/weightwc.h:63:25: error: âseq2.back_usâ may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (cp[cnt] != usrc[cnt])
^
In file included from wcscoll_l.c:32:0:
../string/strcoll_l.c:295:18: note: âseq2.back_usâ was declared here
coll_seq seq1, seq2;
^
In file included from ../string/strcoll_l.c:43:0,
from wcscoll_l.c:32:
../string/../locale/weightwc.h:63:25: error: âseq1.back_usâ may be used uninitialized in this function [-Werror=maybe-uninitialized]
if (cp[cnt] != usrc[cnt])
^
In file included from wcscoll_l.c:32:0:
../string/strcoll_l.c:295:12: note: âseq1.back_usâ was declared here
coll_seq seq1, seq2;
^
cc1: all warnings being treated as errors
~~~
strcoll_l.c: In function â__strcoll_lâ:
strcoll_l.c:174:24: error: âseq2.save_idxâ may be used uninitialized in this function [-Werror=maybe-uninitialized]
len = weights[idx++];
^
strcoll_l.c:283:18: note: âseq2.save_idxâ was declared here
coll_seq seq1, seq2;
^
strcoll_l.c:174:20: error: âseq1.save_idxâ may be used uninitialized in this function [-Werror=maybe-uninitialized]
len = weights[idx++];
^
strcoll_l.c:283:12: note: âseq1.save_idxâ was declared here
coll_seq seq1, seq2;
^
cc1: all warnings being treated as errors
~~~
All four warnings are false positives, we have guards or other variables
which would prevent the uninitialized value from being used.
I am purposely _not_ initializing the values to zero because every such
initialization will slow down strcoll and we care about the performance
more than we care about compiler warnings.
I have specifically chosen to narrow down the warning suppression to
gcc 5.3 because I'm not sure exactly how wide-spread the warnings is and
I'd rather be conservative. Others who run into the same error can expand
the case to gcc 5 if we see a pattern of failures.
If nobody objects I'll check this in within 48 hours.
2016-10-27 Carlos O'Donell <carlos@redhat.com>
* locale/weight.h (findix): Ignore -Wmaybe-uninitialized error
for seq2.back_us and seq1.back_us.
* locale/weightwc.h (findix): Likewise.
* string/strcoll_l.c (get_next_seq): Ignore -Wmaybe-uninitialized
for seq2.save_idx and seq1.save_idx.
diff --git a/locale/weight.h b/locale/weight.h
index c99730c..8cab4df 100644
--- a/locale/weight.h
+++ b/locale/weight.h
@@ -61,9 +61,17 @@ findidx (const int32_t *table,
already. */
size_t cnt;
+ /* In GCC 5.3 compiling for i486 the compiler complains that
+ seq2.back_us, which becomes usrc, might be used
+ uninitialized. This can't be true because we pass a length
+ of -1 for len at the same time which means that this loop
+ never executes. */
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5.3, "-Wmaybe-uninitialized");
for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
if (cp[cnt] != usrc[cnt])
break;
+ DIAG_POP_NEEDS_COMMENT;
if (cnt == nhere)
{
diff --git a/locale/weightwc.h b/locale/weightwc.h
index ab26482..982ce69 100644
--- a/locale/weightwc.h
+++ b/locale/weightwc.h
@@ -59,9 +59,17 @@ findidx (const int32_t *table,
already. */
size_t cnt;
+ /* In GCC 5.3 compiling for i486 the compiler complains that
+ seq2.back_us, which becomes usrc, might be used
+ uninitialized. This can't be true because we pass a length
+ of -1 for len at the same time which means that this loop
+ never executes. */
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5.3, "-Wmaybe-uninitialized");
for (cnt = 0; cnt < nhere && cnt < len; ++cnt)
if (cp[cnt] != usrc[cnt])
break;
+ DIAG_POP_NEEDS_COMMENT;
if (cnt == nhere)
{
diff --git a/string/strcoll_l.c b/string/strcoll_l.c
index 4d1e3ab..fd61497 100644
--- a/string/strcoll_l.c
+++ b/string/strcoll_l.c
@@ -24,6 +24,7 @@
#include <stdint.h>
#include <string.h>
#include <sys/param.h>
+#include <libc-internal.h>
#ifndef STRING_TYPE
# define STRING_TYPE char
@@ -170,7 +171,19 @@ get_next_seq (coll_seq *seq, int nrules, const unsigned char *rulesets,
}
}
+ /* In GCC 5.3 compiling for i486 the compiler complains that idx,
+ taken from seq->idx (seq1 or seq2 from STRCOLL) may be used
+ uninitialized. In general this can't possibly be true since
+ seq1.idx and seq2.idx are initialized to zero in the outer
+ function. Only one case where seq->idx is restored from
+ seq->save_idx might result in an uninitialized idx value, but
+ it is guarded by a sequence of checks against backw_stop which
+ ensures that seq->save_idx was saved to first and contains a
+ valid value. */
+ DIAG_PUSH_NEEDS_COMMENT;
+ DIAG_IGNORE_NEEDS_COMMENT (5.3, "-Wmaybe-uninitialized");
len = weights[idx++];
+ DIAG_POP_NEEDS_COMMENT;
/* Skip over indices of previous levels. */
for (int i = 0; i < pass; i++)
{
---
--
Cheers,
Carlos.
next reply other threads:[~2016-10-27 20:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-27 20:25 Carlos O'Donell [this message]
2016-10-27 20:30 ` Joseph Myers
2016-10-28 2:23 ` Carlos O'Donell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b10e2136-4d2a-e1aa-5d82-ecb07bbbeef6@redhat.com \
--to=carlos@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).