From: Jakub Jelinek <jakub@redhat.com>
To: Martin Sebor <msebor@gmail.com>
Cc: Jeff Law <law@redhat.com>, Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)
Date: Thu, 02 Feb 2017 22:15:00 -0000 [thread overview]
Message-ID: <20170202221507.GY14051@tucnak> (raw)
In-Reply-To: <fd0f30f7-8b1e-4acb-f40a-02ab9088e1e5@gmail.com>
Hi!
Note, the second patch I've posted passed bootstrap/regtest on both
x86_64-linux and i686-linux.
On Thu, Feb 02, 2017 at 09:58:06AM -0700, Martin Sebor wrote:
> > int
> > main (void)
> > {
> > int i;
> > char buf[64];
> > if (__builtin_sprintf (buf, "%#hho", a) > 1)
> > __builtin_abort ();
> > if (__builtin_sprintf (buf, "%#hhx", a) > 1)
> > __builtin_abort ();
> > return 0;
> > }
> > Current trunk as well as trunk + your patch computes ranges [2, 4] and
> > [3, 4], but the correct ranges are [1, 4] and [1, 4], because for a 0
> > (or say -131072 etc.) it sets buf to "0" in both cases.
>
> That's right. This is a good find. This case is being tested in
> builtin-sprintf-warn-1.c but the assertions (on lines 1154 and
> 1155) seem to expect the wrong numbers. I would expect your fix
> to cause failures here. (And now that I've read the rest of the
> patch I see it does.)
That testcase is derived from the builtin-sprintf-warn-1.c:115{4,5}
FAILs I got with the patch + analysis (and included in the second patch
in the testsuite as executable testcase too).
> The range in the note is the artificial one the pass uses to compute
> the range of output. I went back and forth on this as I think it's
> debatable if [-128, 127] is clearer than [1, -128] (or [-128, 1]).
> The informative notes aren't completely consistent in what ranges
> they print. It would be nice to nail down what we think is the most
> useful output and make them all consistent.
You say in the wording range and print it as a range, then it really should
be a range, and not an artificial one, but one reflecting actual possible
values. If the user knows that the variable can have values -123 and 126
at that point and you still print [1, -128] or [-128, 1] as range, the
users will just think the compiler is buggy and disable the warning.
> > Plus there are certain notes removed:
> > -builtin-sprintf-warn-1.c:1311:3: note: using the range [1, -2147483648] for directive argument
> > T (0, "%d", a); /* { dg-warning "into a region" } */
> > without replacement, here a has [-2147483648, 2147483647] range, but as that
> > is equal to the type's range, I bet it omits it.
>
> Could be. As I said, there are opportunities for improvements in
> what the notes print. Someone pointed out, for example, that very
> large numbers are hard to read. It might be clearer to print some
> of them using constants like LONG_MAX - 2, or in hex, etc.
The *_MAX or hex is a separate issue, that can be done or doesn't have to be
done, the values are simply the same. But picking some random numbers in
the ranges is just wrong.
> > - tree dirmin = TYPE_MIN_VALUE (dirtype);
> > - tree dirmax = TYPE_MAX_VALUE (dirtype);
> > -
> > - if (TYPE_UNSIGNED (dirtype))
> > - {
> > - *argmin = dirmin;
> > - *argmax = dirmax;
> > - }
> > - else
> > - {
> > - *argmin = integer_zero_node;
> > - *argmax = dirmin;
> > - }
> > -
> > + *argmin = TYPE_MIN_VALUE (dirtype);
> > + *argmax = TYPE_MAX_VALUE (dirtype);
>
> This is likely behind the changes in the notes you pointed out above.
> The code here is intentional to reflect the range synthesized by
> the pass to compute the output. I don't have a big issue with
The change I've done was completely intentional, it is again mixing of
value ranges with already premature guessing on what values are shorter or
longer.
> As for the rest of the patch, while I appreciate your help and
> acknowledge it's not my call to make I'm not entirely comfortable
> with this much churn at this stage. My preference would to just
> fix the bugs and do the restructuring in stage 1.
The thing is, right now we have 3 independent but intermixed code paths,
one for arguments with VR_RANGE that doesn't need conversion for dirtype
(then argmin/argmax until very lately is actual range and the
shortest/longest computation is done at the latest point), then
VR_RANGE that does need conversion for dirtype (that one is prematurely
partly converted to the shortest/longest above), and then
another one that handles the non-VR_RANGE, which commits to the
shortest/longest immediately. What my patch does is that it unifies all
the 3 paths on essentially what the first path does. If we don't apply that
patch, we are going to have 3 times as many possibilities for bugs; you will
need to add some hack to get the above mentioned wrong-code fixed, and
IMNSHO another hack to get the bogus printed ranges fixed.
It is always better to remove code than to add it.
Jakub
next prev parent reply other threads:[~2017-02-02 22:15 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-01 23:52 Martin Sebor
2017-02-02 7:37 ` Jakub Jelinek
2017-02-02 9:52 ` Jakub Jelinek
2017-02-02 14:12 ` Jakub Jelinek
2017-02-03 18:44 ` Jeff Law
2017-02-03 19:02 ` Jakub Jelinek
2017-02-02 16:58 ` Martin Sebor
2017-02-02 19:59 ` Martin Sebor
2017-02-02 23:23 ` Jakub Jelinek
2017-02-03 0:50 ` Martin Sebor
2017-02-03 19:07 ` Jeff Law
2017-02-03 0:31 ` Martin Sebor
2017-02-03 0:48 ` Jakub Jelinek
2017-02-03 5:37 ` Martin Sebor
2017-02-03 19:02 ` Jeff Law
2017-02-03 19:08 ` Martin Sebor
2017-02-02 22:15 ` Jakub Jelinek [this message]
2017-02-03 18:53 ` Jeff Law
2017-02-03 7:35 ` Jeff Law
2017-02-03 16:13 ` Martin Sebor
2017-02-03 16:39 ` Jakub Jelinek
2017-02-03 17:02 ` Martin Sebor
2017-02-03 17:17 ` Jakub Jelinek
2017-02-03 17:49 ` Jeff Law
2017-02-04 8:07 ` Jakub Jelinek
2017-02-06 19:45 ` Jakub Jelinek
2017-02-14 0:15 ` Jeff Law
2017-02-14 7:48 ` Jakub Jelinek
2017-02-14 13:57 ` Jakub Jelinek
2017-02-16 23:22 ` Jeff Law
2017-02-14 16:37 ` Martin Sebor
2017-02-14 16:40 ` Jakub Jelinek
2017-02-14 19:24 ` Martin Sebor
2017-02-14 20:59 ` Jakub Jelinek
2017-02-14 22:17 ` Martin Sebor
2017-02-16 23:34 ` Jeff Law
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=20170202221507.GY14051@tucnak \
--to=jakub@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
--cc=msebor@gmail.com \
/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).