<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 11, 2015 at 1:28 PM, Tom Stellard <span dir="ltr"><<a href="mailto:tom@stellard.net" target="_blank">tom@stellard.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Sep 10, 2015 at 08:28:02PM -0500, Aaron Watry wrote:<br>
> On Thu, Sep 10, 2015 at 12:10 PM, Tom Stellard <<a href="mailto:tom@stellard.net">tom@stellard.net</a>> wrote:<br>
><br>
> > On Thu, Sep 10, 2015 at 10:14:34AM -0500, Aaron Watry via Libclc-dev wrote:<br>
> > > The values for the char/short/integer/long minimums were declared with<br>
> > their actual values, not the definitions from the CL spec (v1.1).  As a<br>
> > result, <a href="tel:%28-2147483648" value="+12147483648">(-2147483648</a>) was actually being treated as a long by the<br>
> > compiler, not an int, which caused issues when trying to add/subtract that<br>
> > value from a vector.<br>
> > ><br>
> > > Update the definitions to use the values declared by the spec, and also<br>
> > add explicit casts for the char/short minimums so that the compiler<br>
> > actually treats them as shorts/chars. Without those casts, they actually<br>
> > end up stored as integers.<br>
> > ><br>
> > > The compiler can sign extend the values if it needs to conver the<br>
> > char->short or short->int.<br>
> > ><br>
> > > Reported-by: Moritz Pflanzer <<a href="mailto:moritz.pflanzer14@imperial.ac.uk">moritz.pflanzer14@imperial.ac.uk</a>><br>
> > > CC: Moritz Pflanzer <<a href="mailto:moritz.pflanzer14@imperial.ac.uk">moritz.pflanzer14@imperial.ac.uk</a>><br>
> > > Signed-off-by: Aaron Watry <<a href="mailto:awatry@gmail.com">awatry@gmail.com</a>><br>
> > > ---<br>
> > >  generic/include/clc/integer/definitions.h | 12 ++++++------<br>
> > >  1 file changed, 6 insertions(+), 6 deletions(-)<br>
> > ><br>
> > > diff --git a/generic/include/clc/integer/definitions.h<br>
> > b/generic/include/clc/integer/definitions.h<br>
> > > index a407974..505002f 100644<br>
> > > --- a/generic/include/clc/integer/definitions.h<br>
> > > +++ b/generic/include/clc/integer/definitions.h<br>
> > > @@ -1,14 +1,14 @@<br>
> > >  #define CHAR_BIT 8<br>
> > >  #define INT_MAX 2147483647<br>
> > > -#define INT_MIN -2147483648<br>
> > > +#define INT_MIN (-2147483647 - 1)<br>
> ><br>
> > Is there some reason why<br>
> ><br>
> > #define INT_MIN ((int)-2147483648)<br>
> ><br>
> > won't work?<br>
> ><br>
> > I also don't understand how subtracting one guarantees the result will<br>
> > be an integer and not long.<br>
> ><br>
> ><br>
> You're right that ((int)-2147483648) would work as well, which is somewhat<br>
> similar to what I did with the char/short minimums in this patch (forcibly<br>
> casting the result). The only reason that I went with the value that I did<br>
> for INT_MIN was that the spec seems pretty specific:<br>
><br>
> Section 6.11.3 of the 1.1 Spec:<br>
> "The macro names given in the following list must use the values specified.<br>
> The values shall all<br>
> be constant expressions suitable for use in #if preprocessing directives."<br>
><br>
> <snip><br>
> #define INT_MIN (-2147483647 – 1)<br>
><br>
> The only reason that I put an explicit cast in for the char/short values<br>
> was because they would not actually work correctly for charN/shortN casts<br>
> without them, and it seems to be the intention behind the spec that the<br>
> MIN/MAX of a given type should be stored as that type.<br>
><br>
> I don't personally care that much what we end up with, as the result after<br>
> preprocessing should be identical...  as long as the new unit tests pass,<br>
> I'm good.<br>
><br>
<br>
</div></div>I don't mind using the values from the spec.  The only change I would request<br>
is that we cast INT_MIN to int like we do for char and short.  I think the<br>
compiler is still allowed to evaluate that expression to long if it wants to.<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>Works for me.  v2 incoming.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888">
-Tom<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> --Aaron<br>
><br>
><br>
> > -Tom<br>
> ><br>
> > >  #define LONG_MAX  0x7fffffffffffffffL<br>
> > > -#define LONG_MIN -0x8000000000000000L<br>
> > > +#define LONG_MIN (-0x7fffffffffffffffL - 1)<br>
> > > +#define CHAR_MAX SCHAR_MAX<br>
> > > +#define CHAR_MIN SCHAR_MIN<br>
> > >  #define SCHAR_MAX 127<br>
> > > -#define SCHAR_MIN -128<br>
> > > -#define CHAR_MAX 127<br>
> > > -#define CHAR_MIN -128<br>
> > > +#define SCHAR_MIN ((char)(-127 - 1))<br>
> > >  #define SHRT_MAX 32767<br>
> > > -#define SHRT_MIN -32768<br>
> > > +#define SHRT_MIN ((short)(-32767 - 1))<br>
> > >  #define UCHAR_MAX 255<br>
> > >  #define USHRT_MAX 65535<br>
> > >  #define UINT_MAX 0xffffffff<br>
> > > --<br>
> > > 2.1.4<br>
> > ><br>
> > > _______________________________________________<br>
> > > Libclc-dev mailing list<br>
> > > <a href="mailto:Libclc-dev@lists.llvm.org">Libclc-dev@lists.llvm.org</a><br>
> > > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev</a><br>
> ><br>
</div></div></blockquote></div><br></div></div>