<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 10, 2015 at 12:10 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">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 their actual values, not the definitions from the CL spec (v1.1).  As a result, <a href="tel:%28-2147483648" value="+12147483648">(-2147483648</a>) was actually being treated as a long by the compiler, not an int, which caused issues when trying to add/subtract that value from a vector.<br>
><br>
> Update the definitions to use the values declared by the spec, and also add explicit casts for the char/short minimums so that the compiler actually treats them as shorts/chars. Without those casts, they actually end up stored as integers.<br>
><br>
> The compiler can sign extend the values if it needs to conver the 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 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>
</span>Is there some reason why<br>
<br>
#define INT_MIN ((int)-<a href="tel:2147483648" value="+12147483648">2147483648</a>)<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></blockquote><div><br></div><div>You're right that ((int)-2147483648) would work as well, which is somewhat similar to what I did with the char/short minimums in this patch (forcibly casting the result). The only reason that I went with the value that I did 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. The values shall all<br>be constant expressions suitable for use in #if preprocessing directives."<br><br></div><div><snip><br>#define INT_MIN (-2147483647 – 1)<br><br></div><div>The only reason that I put an explicit cast in for the char/short values was because they would not actually work correctly for charN/shortN casts without them, and it seems to be the intention behind the spec that the MIN/MAX of a given type should be stored as that type.<br></div><div> <br></div><div>I don't personally care that much what we end up with, as the result after preprocessing should be identical...  as long as the new unit tests pass, I'm good.<br><br></div><div>--Aaron<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
-Tom<br>
<span class=""><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>
</span>> _______________________________________________<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>
</blockquote></div><br></div></div>