Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-11 Thread Steve Ellcey
On Fri, 2015-05-08 at 14:54 -0700, Paul Eggert wrote: > On 05/08/2015 09:59 AM, Joseph Myers wrote: > > Paul, although glibc's copy of parts of tzcode is a bit out of date, it > > looks like the currenthttps://github.com/eggert/tz.git still has the > > problematic code in private.h, relying on lef

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-08 Thread Paul Eggert
On 05/08/2015 09:59 AM, Joseph Myers wrote: Paul, although glibc's copy of parts of tzcode is a bit out of date, it looks like the currenthttps://github.com/eggert/tz.git still has the problematic code in private.h, relying on left-shifting -1 which has undefined behavior in C99/C11 (implementat

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-08 Thread Joseph Myers
On Fri, 8 May 2015, Steve Ellcey wrote: > On Thu, 2015-05-07 at 21:15 +0200, Marek Polacek wrote: > > On Thu, May 07, 2015 at 12:00:20PM -0600, Jeff Law wrote: > > > OK. Please install if you haven't already. > > > > I have not, so will do momentarily. Thanks, > > > > Marek > > Marek, >

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-08 Thread Markus Trippelsdorf
On 2015.05.08 at 09:38 -0700, Steve Ellcey wrote: > > This patch has broken the glibc build. I am not sure if the problem is > a bug in your patch or a bug in the code used by glibc. Here is a > cutdown test case from glibc (timezone/scheck.c). This code compiled > before your patch but now it

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-08 Thread Steve Ellcey
On Thu, 2015-05-07 at 21:15 +0200, Marek Polacek wrote: > On Thu, May 07, 2015 at 12:00:20PM -0600, Jeff Law wrote: > > OK. Please install if you haven't already. > > I have not, so will do momentarily. Thanks, > > Marek Marek, This patch has broken the glibc build. I am not sure if th

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-07 Thread Marek Polacek
On Thu, May 07, 2015 at 12:00:20PM -0600, Jeff Law wrote: > OK. Please install if you haven't already. I have not, so will do momentarily. Thanks, Marek

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-07 Thread Jeff Law
On 05/06/2015 05:37 AM, Marek Polacek wrote: On Wed, Apr 29, 2015 at 10:54:58PM +, Joseph Myers wrote: On Mon, 27 Apr 2015, Marek Polacek wrote: trigger by default. One change is that we reject programs that use shift with undefined behavior in a context where a constant expression is req

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-05-06 Thread Marek Polacek
On Wed, Apr 29, 2015 at 10:54:58PM +, Joseph Myers wrote: > On Mon, 27 Apr 2015, Marek Polacek wrote: > > > trigger by default. One change is that we reject programs that use shift > > with > > undefined behavior in a context where a constant expression is required, > > thus > > e.g. enum E

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-29 Thread Joseph Myers
On Mon, 27 Apr 2015, Marek Polacek wrote: > trigger by default. One change is that we reject programs that use shift with > undefined behavior in a context where a constant expression is required, thus > e.g. enum E { A = -1 << 0 }; > But I hope that's reasonable. That seems appropriate (for C99

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-27 Thread Marek Polacek
On Sat, Apr 25, 2015 at 08:13:08PM +, Joseph Myers wrote: > On Sat, 25 Apr 2015, Marek Polacek wrote: > > > + pedwarn (location, OPT_Wshift_negative_value, > > +"left shift of negative value"); > > Use of pedwarn is always suspect for something only undefined at

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-25 Thread Joseph Myers
On Sat, 25 Apr 2015, Marek Polacek wrote: > + pedwarn (location, OPT_Wshift_negative_value, > + "left shift of negative value"); Use of pedwarn is always suspect for something only undefined at runtime; it must not produce an error with -pedantic-errors in any co

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-25 Thread Marek Polacek
On Fri, Apr 24, 2015 at 03:31:55PM -0600, Martin Sebor wrote: > There's a significant difference between the reasons why > the behavior of the left shift is undefined when the left > operand is negative vs when the right operand is, and > between the results of such expressions computed by GCC > an

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-24 Thread Martin Sebor
On 04/24/2015 03:31 PM, Martin Sebor wrote: On 04/24/2015 10:27 AM, Marek Polacek wrote: On Thu, Apr 23, 2015 at 09:11:39PM -0600, Martin Sebor wrote: I wonder if the tests where the left shift operands are both constants really do invoke undefined behavior in GCC. For example, AFAICS, in (-1 <

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-24 Thread Martin Sebor
On 04/24/2015 10:27 AM, Marek Polacek wrote: On Thu, Apr 23, 2015 at 09:11:39PM -0600, Martin Sebor wrote: I wonder if the tests where the left shift operands are both constants really do invoke undefined behavior in GCC. For example, AFAICS, in (-1 << 0) and other constant expressions gcc compu

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-24 Thread Marek Polacek
On Thu, Apr 23, 2015 at 09:11:39PM -0600, Martin Sebor wrote: > I wonder if the tests where the left shift operands are both > constants really do invoke undefined behavior in GCC. For > example, AFAICS, in (-1 << 0) and other constant expressions > gcc computes the shift in unsigned HOST_WIDE_INT

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-23 Thread Martin Sebor
On 04/22/2015 12:36 PM, Marek Polacek wrote: Currently, we warn if the right operand of a shift expression is negative, or greater than or equal to the length in bits of the promoted left operand. But we don't warn when we see a left shift of a negative value. That is undefined behavior since C

Re: [C/C++ PATCH] Implement -Wshift-negative-value (PR c/65179)

2015-04-23 Thread Jeff Law
On 04/22/2015 12:36 PM, Marek Polacek wrote: Currently, we warn if the right operand of a shift expression is negative, or greater than or equal to the length in bits of the promoted left operand. But we don't warn when we see a left shift of a negative value. That is undefined behavior since C