Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-16 Thread Jeff Law
On 02/14/2017 01:32 PM, Jakub Jelinek wrote: On Tue, Feb 14, 2017 at 12:15:59PM -0700, Martin Sebor wrote: That comment explains how the likely_adjust variable ("the adjustment") is being used, or more precisely, how it was being used in the first version of the patch. The comment became somewh

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-16 Thread Jeff Law
On 02/14/2017 06:43 AM, Jakub Jelinek wrote: On Tue, Feb 14, 2017 at 08:18:13AM +0100, Jakub Jelinek wrote: On Mon, Feb 13, 2017 at 04:53:19PM -0700, Jeff Law wrote: dirtype is one of the standard {un,}signed {char,short,int,long,long long} types, all of them have 0 in their ranges. For VR_RANG

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-14 Thread Martin Sebor
On 02/14/2017 01:32 PM, Jakub Jelinek wrote: On Tue, Feb 14, 2017 at 12:15:59PM -0700, Martin Sebor wrote: That comment explains how the likely_adjust variable ("the adjustment") is being used, or more precisely, how it was being used in the first version of the patch. The comment became somewh

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-14 Thread Jakub Jelinek
On Tue, Feb 14, 2017 at 12:15:59PM -0700, Martin Sebor wrote: > That comment explains how the likely_adjust variable ("the adjustment") > is being used, or more precisely, how it was being used in the first > version of the patch. The comment became somewhat out of date with > the committed versio

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-14 Thread Martin Sebor
On 02/14/2017 09:39 AM, Jakub Jelinek wrote: On Tue, Feb 14, 2017 at 09:36:44AM -0700, Martin Sebor wrote: @@ -1371,7 +1354,8 @@ format_integer (const directive &dir, tr else { res.range.likely = res.range.min; - if (likely_adjust && maybebase && base != 10) + if (maybeb

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-14 Thread Jakub Jelinek
On Tue, Feb 14, 2017 at 09:36:44AM -0700, Martin Sebor wrote: > > @@ -1371,7 +1354,8 @@ format_integer (const directive &dir, tr > >else > > { > >res.range.likely = res.range.min; > > - if (likely_adjust && maybebase && base != 10) > > + if (maybebase && base != 10 > > +

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-14 Thread Martin Sebor
On 02/14/2017 12:18 AM, Jakub Jelinek wrote: On Mon, Feb 13, 2017 at 04:53:19PM -0700, Jeff Law wrote: dirtype is one of the standard {un,}signed {char,short,int,long,long long} types, all of them have 0 in their ranges. For VR_RANGE we almost always set res.knownrange to true: /* Set

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-14 Thread Jakub Jelinek
On Tue, Feb 14, 2017 at 08:18:13AM +0100, Jakub Jelinek wrote: > On Mon, Feb 13, 2017 at 04:53:19PM -0700, Jeff Law wrote: > > > dirtype is one of the standard {un,}signed {char,short,int,long,long long} > > > types, all of them have 0 in their ranges. > > > For VR_RANGE we almost always set res.kn

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-13 Thread Jakub Jelinek
On Mon, Feb 13, 2017 at 04:53:19PM -0700, Jeff Law wrote: > > dirtype is one of the standard {un,}signed {char,short,int,long,long long} > > types, all of them have 0 in their ranges. > > For VR_RANGE we almost always set res.knownrange to true: > > /* Set KNOWNRANGE if the argument is in

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-13 Thread Jeff Law
On 02/04/2017 01:07 AM, Jakub Jelinek wrote: On Fri, Feb 03, 2017 at 05:39:21PM +0100, Jakub Jelinek wrote: Say in the http://gcc.gnu.org/ml/gcc-patches/2017-02/msg00234.html patch, you would with my patch need just the tree_digits part, and then the very last hunk in gimple-ssa-sprintf.c (with

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-06 Thread Jakub Jelinek
On Sat, Feb 04, 2017 at 09:07:23AM +0100, Jakub Jelinek wrote: > You've committed the patch unnecessarily complicated, see above. > The following gives the same testsuite result. > > dirtype is one of the standard {un,}signed {char,short,int,long,long long} > types, all of them have 0 in their ran

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-04 Thread Jakub Jelinek
On Fri, Feb 03, 2017 at 05:39:21PM +0100, Jakub Jelinek wrote: > Say in the http://gcc.gnu.org/ml/gcc-patches/2017-02/msg00234.html > patch, you would with my patch need just the tree_digits part, > and then the very last hunk in gimple-ssa-sprintf.c (with > likely_adjust && > removed). Because y

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Martin Sebor
On 02/03/2017 12:02 PM, Jeff Law wrote: On 02/02/2017 05:31 PM, Martin Sebor wrote: - T (2, "%#hho",a); /* { dg-warning "nul past the end" } */ - T (2, "%#hhx",a); /* { dg-warning ".%#hhx. directive writing between 3 and . bytes into a region of size 2" } */ + T (2, "%

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jeff Law
On 02/02/2017 05:49 PM, Martin Sebor wrote: That is unrelated to the patch, both in the current trunk, with your patch as well as with my patch there is just res.range.likely = res.knownrange ? res.range.max : res.range.min; res.range.unlikely = res.range.max; for these cases. Do you want l

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jeff Law
On 02/02/2017 05:31 PM, Martin Sebor wrote: - T (2, "%#hho",a); /* { dg-warning "nul past the end" } */ - T (2, "%#hhx",a); /* { dg-warning ".%#hhx. directive writing between 3 and . bytes into a region of size 2" } */ + T (2, "%#hho",a); + T (2, "%#hhx",

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jakub Jelinek
On Fri, Feb 03, 2017 at 11:43:53AM -0700, Jeff Law wrote: > > + if (TREE_CODE (argtype) == POINTER_TYPE) > > { > > - if (POINTER_TYPE_P (argtype)) > > - argmax = build_all_ones_cst (argtype); > > - else if (TYPE_UNSIGNED (argtype)) > > - argmax = TYPE_MAX_VALUE (argtype

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jeff Law
On 02/02/2017 03:15 PM, Jakub Jelinek wrote: 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,

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jeff Law
On 02/02/2017 07:12 AM, Jakub Jelinek wrote: On Thu, Feb 02, 2017 at 10:52:18AM +0100, Jakub Jelinek wrote: That said, as I've said in the PR and earlier in December on gcc-patches, the way format_integer is structured is not really maintainable, has very different code paths for arguments with

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jeff Law
On 02/03/2017 09:39 AM, Jakub Jelinek wrote: On Fri, Feb 03, 2017 at 09:13:23AM -0700, Martin Sebor wrote: I'm not opposed to the changes, certainly not to cleaning things up, but I don't think now is the time to be making these tweaks. Jakub's patch is fine with me without those tweaks, and wi

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jakub Jelinek
On Fri, Feb 03, 2017 at 10:02:48AM -0700, Martin Sebor wrote: > On 02/03/2017 09:39 AM, Jakub Jelinek wrote: > > On Fri, Feb 03, 2017 at 09:13:23AM -0700, Martin Sebor wrote: > > > I'm not opposed to the changes, certainly not to cleaning things up, > > > but I don't think now is the time to be mak

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Martin Sebor
On 02/03/2017 09:39 AM, Jakub Jelinek wrote: On Fri, Feb 03, 2017 at 09:13:23AM -0700, Martin Sebor wrote: I'm not opposed to the changes, certainly not to cleaning things up, but I don't think now is the time to be making these tweaks. Jakub's patch is fine with me without those tweaks, and wi

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Jakub Jelinek
On Fri, Feb 03, 2017 at 09:13:23AM -0700, Martin Sebor wrote: > I'm not opposed to the changes, certainly not to cleaning things up, > but I don't think now is the time to be making these tweaks. Jakub's > patch is fine with me without those tweaks, and with the correction What do you mean by my

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-03 Thread Martin Sebor
On 02/03/2017 12:35 AM, Jeff Law wrote: On 02/02/2017 09:58 AM, Martin Sebor wrote: Otherwise all the tests succeeded, though looking e.g. at the diff between builtin-sprintf-warn-1.c diagnostics with your patch and with the patch below instead, there are also differences like: -builtin-sprintf

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Jeff Law
On 02/02/2017 09:58 AM, Martin Sebor wrote: Otherwise all the tests succeeded, though looking e.g. at the diff between builtin-sprintf-warn-1.c diagnostics with your patch and with the patch below instead, there are also differences like: -builtin-sprintf-warn-1.c:1119:3: note: using the range [

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Martin Sebor
On 02/02/2017 05:31 PM, Martin Sebor wrote: - T (2, "%#hho",a); /* { dg-warning "nul past the end" } */ - T (2, "%#hhx",a); /* { dg-warning ".%#hhx. directive writing between 3 and . bytes into a region of size 2" } */ + T (2, "%#hho",a); + T (2, "%#hhx",

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Martin Sebor
On 02/02/2017 04:23 PM, Jakub Jelinek wrote: On Thu, Feb 02, 2017 at 12:59:11PM -0700, Martin Sebor wrote: - T (2, "%#hho",a); /* { dg-warning "nul past the end" } */ - T (2, "%#hhx",a); /* { dg-warning ".%#hhx. directive writing between 3 and . bytes into a region of s

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Jakub Jelinek
On Thu, Feb 02, 2017 at 05:31:19PM -0700, Martin Sebor wrote: > index 9e099f0..84dd3671 100644 > --- a/gcc/gimple-ssa-sprintf.c > +++ b/gcc/gimple-ssa-sprintf.c > @@ -1242,6 +1242,10 @@ format_integer (const directive &dir, tree arg) > of the format string by returning [-1, -1]. */ >

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Martin Sebor
- T (2, "%#hho",a); /* { dg-warning "nul past the end" } */ - T (2, "%#hhx",a); /* { dg-warning ".%#hhx. directive writing between 3 and . bytes into a region of size 2" } */ + T (2, "%#hho",a); + T (2, "%#hhx",a); On reflection, this isn't quite the r

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Jakub Jelinek
On Thu, Feb 02, 2017 at 12:59:11PM -0700, Martin Sebor wrote: > > > - T (2, "%#hho",a); /* { dg-warning "nul past the end" } */ > > > - T (2, "%#hhx",a); /* { dg-warning ".%#hhx. directive > > > writing between 3 and . bytes into a region of size 2" } */ > > > + T (2, "%#

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Jakub Jelinek
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_ab

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Martin Sebor
So far I haven't done full bootstrap/regtest on this, just make check-gcc -j16 -k RUNTESTFLAGS=tree-ssa.exp which revealed the need for gcc.dg/tree-ssa/builtin-sprintf-warn-1.c hunk below. Here it is turned into a short wrong-code without the patch below: volatile int a; int main (void) { int

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Martin Sebor
On 02/02/2017 02:52 AM, Jakub Jelinek wrote: On Thu, Feb 02, 2017 at 08:37:07AM +0100, Jakub Jelinek wrote: + if (res.range.max < res.range.min) + { + unsigned HOST_WIDE_INT tmp = res.range.max; + res.range.max = res.range.min; + res.range.min = tmp; These 3

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Jakub Jelinek
On Thu, Feb 02, 2017 at 10:52:18AM +0100, Jakub Jelinek wrote: > That said, as I've said in the PR and earlier in December on gcc-patches, > the way format_integer is structured is not really maintainable, has > very different code paths for arguments with known ranges and without them > intermixed

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-02 Thread Jakub Jelinek
On Thu, Feb 02, 2017 at 08:37:07AM +0100, Jakub Jelinek wrote: > > + if (res.range.max < res.range.min) > > + { > > + unsigned HOST_WIDE_INT tmp = res.range.max; > > + res.range.max = res.range.min; > > + res.range.min = tmp; > > These 3 lines are > std::sw

Re: [PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

2017-02-01 Thread Jakub Jelinek
On Wed, Feb 01, 2017 at 04:52:35PM -0700, Martin Sebor wrote: > --- a/gcc/gimple-ssa-sprintf.c > +++ b/gcc/gimple-ssa-sprintf.c > @@ -1382,13 +1382,26 @@ format_integer (const directive &dir, tree arg) > would reflect the largest possible precision (i.e., INT_MAX). */ >res.range.m