From: Stefan Liebler <stli@linux.vnet.ibm.com>
To: libc-alpha@sourceware.org
Subject: Warnings in string/stratcliff.c, wcsmbs/wcsatcliff.c with GCC 7 -O3
Date: Wed, 22 Mar 2017 14:29:00 -0000 [thread overview]
Message-ID: <ddc73696-7ae8-a98f-1d51-18ed4f758b92@linux.vnet.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 907 bytes --]
Hi,
Compiling string/stratcliff.c with GCC 7 and -O3 leads to the following
warning/errors on s390x / x86_64:
../test-skeleton.c: In function âlegacy_test_functionâ:
cc1: error: assuming signed overflow does not occur when assuming that
(X - c) <= X is always true [-Werror=strict-overflow]
This error occurs 9 times.
Compiling with -O2 is fine.
The first error occurs for strlen/wcslen tests in line 98 for the
inner-for-loop. See also the attached smaller testcase.
There's a new pass in GCC 7 and the warning also occurs
with -O2 -fsplit-loops and it disappears with -O3 -fno-split-loops.
The warning also occurs with an extra test which ensures that size is >
0. The warning disappears if the outer loop uses "outer >= 0" instead
of the MAX macro and the extra test is done.
Any ideas how to fix this?
Is this a GCC 7 regression and we should file a bug against GCC 7?
Bye
Stefan
[-- Attachment #2: tst-warn.c --]
[-- Type: text/plain, Size: 1145 bytes --]
#include <stdio.h>
#include <stdlib.h>
/*
Compiled with GCC 7 -Wall -O3 or -Wall -O2 -fsplit-loops
cc1: warning: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Wstrict-overflow]
*/
#define MAX(a,b) ((a) > (b) ? (a) : (b))
int main(int argc, char *argv[])
{
int size = 0;
if (argc >= 2)
{
/* In original testcase: sysconf (_SC_PAGESIZE); */
size = strtol (argv[1], NULL, 0);
}
#if 0
/* The warning occurs even with this extra check, but the original testcase
does not check it.
sysconf (_SC_PAGESIZE) must not return a size less than 1. */
if (size < 1)
{
printf ("size=%d is too small.\n", size);
return EXIT_FAILURE;
}
#endif
int nchars = size / sizeof (char);
int outer;
int inner;
/* Compare with string/stratcliff.c:96 */
#if 1
for (outer = nchars - 1; outer >= MAX (0, nchars - 128); --outer)
#else
for (outer = nchars - 1; outer >= 0; --outer)
#endif
{
for (inner = MAX (outer, nchars - 64); inner < nchars; ++inner)
{
printf ("outer=%d, inner=%d\n", outer, inner);
}
}
return EXIT_SUCCESS;
}
next reply other threads:[~2017-03-22 14:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-22 14:29 Stefan Liebler [this message]
2017-03-22 14:54 ` Wainer dos Santos Moschetta
2017-03-23 11:16 ` Stefan Liebler
2017-08-20 16:50 ` H.J. Lu
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=ddc73696-7ae8-a98f-1d51-18ed4f758b92@linux.vnet.ibm.com \
--to=stli@linux.vnet.ibm.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).