<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
This is an OpenCL kernel he is talking about - you don't include
cl_platform.h within kernel code, that is for host only. CL mandates
that the INT_MIN preprocessor macro will be in existence, so the
code is very much allowed.<br>
<br>
Note how it is defined in the man pages here -
<a class="moz-txt-link-freetext" href="https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/macroLimits.html">https://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/macroLimits.html</a><br>
<br>
Cheers,<br>
-Neil.<br>
<br>
<div class="moz-cite-prefix">On 10/09/15 12:07, Bruce Hoult via
llvm-dev wrote:<br>
</div>
<blockquote
cite="mid:CAMU+Ekw7eDzHdQ1WU1K8_x_7Ac06Fj=mw0jx5+W9rbHq=RUa2w@mail.gmail.com"
type="cite">
<div dir="ltr">It depends on whether the '-' is part of the syntax
of a number, or is an operator applied afterwards. I believe C
says it is an operator and thus it examines '2147483648',
decides it won't fit into 32 bits and chooses a 64 bit type, and
only afterwards applies the negation.
<div><br>
</div>
<div>Testing with clang 3.4.1 on Ubuntu x86_64:</div>
<div><br>
</div>
<div>cat >intmin.cpp <<END</div>
<div>
<div>#include <iostream><br>
</div>
<div><br>
</div>
<div>int main(){</div>
<div> auto i = -2147483647;</div>
<div> auto j = -2147483648;</div>
<div> std::cout << "sizeof " << i << " = "
<< sizeof(i) << std::endl;</div>
<div> std::cout << "sizeof " << j << " = "
<< sizeof(j) << std::endl;</div>
<div> return 0;</div>
<div>}</div>
<div>END</div>
<div>clang++ -std=c++11 -o intmin intmin.cpp &&
./intmin<br>
</div>
<div><br>
</div>
<div>sizeof -2147483647 = 4<br>
</div>
<div>
<div>sizeof -2147483648 = 8</div>
</div>
<div><br>
</div>
<div>g++ 4.8.4 gives the same result.</div>
<div><br>
</div>
<div>You would not notice this with an explicit type instead
of 'auto'.</div>
<div><br>
</div>
<div>Note that there should be CL_INT_MIN available
(cl_platform.h) rather than defining your own.</div>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Sep 10, 2015 at 1:30 PM,
Pflanzer, Moritz via llvm-dev <span dir="ltr"><<a
moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org" target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a></a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I recently came across an OpenCL kernel in which an int
vector type was subtracted from the INT_MIN constant, e.g.<br>
<br>
int2 v2 = INT_MIN - (int2)(0);<br>
<br>
INT_MIN was defined as<br>
<br>
#define INT_MIN (-2147483648)<br>
<br>
Clang in OpenCL modes (-x cl) produces the following error:<br>
<br>
vector_conversion.c:12:42: error: can't convert between
vector values of different size ('long' and 'int2' (vector
of 2 'int' values))<br>
int2 v_int = INT_MIN - (int2)(0); //
Only error long to int2 conversion is not possible<br>
~~~~~~~ ^ ~~~~~~~~<br>
1 error generated.<br>
<br>
According to the OpenCL C standard (§6.2.6 and §6.3) I
expected that the scalar INT_MIN would be expanded to the
vector type and that the operation should be possible. The
problem seems to be that INT_MIN is internally represented
as long, though it is still a valid signed integer value,
and thus long cannot be casted to int and subsequently not
to int2.<br>
<br>
If on the other hand INT_MIN is defined as<br>
<br>
#define INT_MIN (-2147483647 - 1)<br>
<br>
it is represented as int, although it is the same number,
and clang does not produce an error.<br>
<br>
More surprisingly, the expression<br>
<br>
int2 t = (int2)(INT_MIN);<br>
<br>
works for both versions of INT_MIN. So in this situation
long seems to be implicitly casted to int which should not
be possible.<br>
<br>
Finally, for clang in C mode (-x c) also both version work
and no error is produced. I attached a test case in which a
summarised all my findings. The behaviour I observed should
be reproducible with<br>
<br>
$ clang -x cl -S -emit-llvm -O0 -o - vector_conversion.c<br>
$ clang -x c -S -emit-llvm -O0 -o - vector_conversion.c<br>
<br>
I would be interested in your thoughts about this behaviour,
whether it is correct that -2147483648 is represented as
long or whether the behaviour can be considered as bug in
the OpenCL frontend of Clang. (Another possibility would be
that the representation as long is correct but it is
nevertheless a bug that the subtraction is not possible.)<br>
<br>
Regards,<br>
<br>
Moritz<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a moz-do-not-send="true"
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>