Re: [SPARC] Fix PR target/60941

2014-04-26 Thread Eric Botcazou
> So, if you have int16 target, where unsigned int is 16-bit and UINT_MAX > 65535, then shift count must be >= 0 and < 16, therefore, 2U << 31 is > undefined behavior. Well, if the shift count is masked by the target, if will be masked according to the width of the register and the result will ne

Re: [SPARC] Fix PR target/60941

2014-04-26 Thread Eric Botcazou
> I believe Jakub is referring to the following in the C standard: > > "Bitwise shift operators > ... > Semantics > ... If the value of the right operand ... is greater than or equal to the > width of the promoted left operand, the behavior is undefined." > > So on 16-bit int systems you can't p

Re: [SPARC] Fix PR target/60941

2014-04-26 Thread Jakub Jelinek
On Sat, Apr 26, 2014 at 03:30:25PM +0200, Eric Botcazou wrote: > > > Not clear to me, (2U << i) should be zero if the shift count is masked. > > > > 2U << 31 is undefined behavior on those targets. > > Precisely not, or else we are not talking about the same notion of masking. Eh, C99, 6.5.7/3:

Re: [SPARC] Fix PR target/60941

2014-04-26 Thread Mikael Pettersson
Eric Botcazou writes: > > > Not clear to me, (2U << i) should be zero if the shift count is masked. > > > > 2U << 31 is undefined behavior on those targets. > > Precisely not, or else we are not talking about the same notion of masking. I believe Jakub is referring to the following in the C

Re: [SPARC] Fix PR target/60941

2014-04-26 Thread Eric Botcazou
> > Not clear to me, (2U << i) should be zero if the shift count is masked. > > 2U << 31 is undefined behavior on those targets. Precisely not, or else we are not talking about the same notion of masking. -- Eric Botcazou

Re: [SPARC] Fix PR target/60941

2014-04-25 Thread Jakub Jelinek
On Fri, Apr 25, 2014 at 01:24:13PM +0200, Eric Botcazou wrote: > > I'm afraid the testcase will fail on int16 targets, so perhaps > > you should guard the body of main other than return 0; with > > #if __INT_MAX__ >= 2147483647ULL > > or > > #if __SIZEOF_INT__ >= 4 > > or similar (or require int32p

Re: [SPARC] Fix PR target/60941

2014-04-25 Thread Eric Botcazou
> I'm afraid the testcase will fail on int16 targets, so perhaps > you should guard the body of main other than return 0; with > #if __INT_MAX__ >= 2147483647ULL > or > #if __SIZEOF_INT__ >= 4 > or similar (or require int32plus target, but gcc.c-torture/execute/ > is not a good place for that and *

Re: [SPARC] Fix PR target/60941

2014-04-25 Thread Jakub Jelinek
On Fri, Apr 25, 2014 at 12:47:32PM +0200, Eric Botcazou wrote: > /* PR target/60941 */ > /* Reported by Martin Husemann */ > > extern void abort (void); > > static void __attribute__((noinline)) > set (unsigned long *l) > { > *l = 31; > } > > int main (void) > { > unsigned long l; > int i

[SPARC] Fix PR target/60941

2014-04-25 Thread Eric Botcazou
This is a regression present on all active branches. The first pattern added by http://gcc.gnu.org/ml/gcc-patches/2011-10/msg00060.html is wrong since, as counter-intuitive as it may seem, "sll" also does a full 64-bit shift. Tested on SPARC/Solaris, applied on all active branches. 2014-04-25