<div dir="ltr"><div style>Hi Dave,</div><div><br></div>Thanks for the help. <div><br></div><div>I see my mistake. "<span style="color:rgb(31,73,125);font-family:Calibri,sans-serif;font-size:14px">*a+=*b" </span>works great.<div>
<br></div><div style>I was hoping there is a  portable way of handling intptr_t ( hoping clang's some hidden feature for the same). </div><div style><br></div><div style>Thanks again for the reply,</div><div style><br>
</div><div style>Ankur</div><div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size:14px"><br></span></font><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 1, 2013 at 6:22 PM, David Tweed <span dir="ltr"><<a href="mailto:david.tweed@arm.com" target="_blank">david.tweed@arm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-GB" link="blue" vlink="purple"><div><p class="">
<span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Leaving aside any OpenCL specific issues (you can use pointers in a more restricted way than in general C), are you sure that the final line is doing what you want (I think that's what the warning is about). You're adding _the int* address held in b_ to the _int value stored at the address held in a_. C will let you do this primarily because it's got quite weak rules about which conversions you must do explicitly, so this will go through on a machine where the int width is the same as an int* width.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Does the error go away if you do *a+=*b ?<u></u><u></u></span></p><p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I don't think either of your typedefs will reliably work (ie, in the interesting cases where sizeof(int*) != sizeof(int)), I think the only way to do it is via explicit pre-processor typedefs based on the pointer size of the machine you're compiling on.<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p><p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Regards,<u></u><u></u></span></p>
<p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Dave<u></u><u></u></span></p><p class=""><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<div style="border-style:solid none none;border-top-color:rgb(181,196,223);border-top-width:1pt;padding:3pt 0cm 0cm"><p class=""><b><span lang="EN-US" style="font-size:10pt;font-family:Tahoma,sans-serif">From:</span></b><span lang="EN-US" style="font-size:10pt;font-family:Tahoma,sans-serif"> <a href="mailto:cfe-dev-bounces@cs.uiuc.edu" target="_blank">cfe-dev-bounces@cs.uiuc.edu</a> [mailto:<a href="mailto:cfe-dev-bounces@cs.uiuc.edu" target="_blank">cfe-dev-bounces@cs.uiuc.edu</a>] <b>On Behalf Of </b>ankur deshwal<br>
<b>Sent:</b> 01 February 2013 12:02<br><b>To:</b> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br><b>Subject:</b> [cfe-dev] Fwd: intptr_t support in llvm<u></u><u></u></span></p></div><div>
<div class="h5"><p class=""><u></u> <u></u></p><div><div><div><p class="">Hi all,<u></u><u></u></p><div><p class=""><u></u> <u></u></p></div><div><p class="">I tried compiling an opencl kernel with intptr_t datatype. However it gives error by default using LLVM/Clang 3.2 for nvptx . To allow usage, I tried following typedefs ( by looking at tests in llvm sources ).<u></u><u></u></p>
</div><div><p class=""><u></u> <u></u></p></div><div><div><p class="">typedef int intptr_t;<u></u><u></u></p></div><div><p class="">and<u></u><u></u></p></div><div><p class="">typedef __typeof( (int*) 0) intptr_t;<u></u><u></u></p>
</div><div><p class=""><u></u> <u></u></p></div><div><p class="">Both definitions compiles the code, however gives following warning. <u></u><u></u></p></div><div><p class="">warning: incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *<u></u><u></u></p>
</div><div><p class=""><u></u> <u></u></p></div><div><p class="">Is it safe to use the above typedefs ? The generated code seems correct for x86 machines (with llvm instruction ptrtoint). Or is there better way to make sure that the semantics of intprt_t are preserved in clang/llvm for all archs ? <u></u><u></u></p>
</div><div><p class=""><u></u> <u></u></p></div><div><p class="">The code I tried to compile is <u></u><u></u></p></div><div><p class=""><u></u> <u></u></p></div><div><div><p class="">__kernel void intptr_t_kernel(int *a, int *b)<u></u><u></u></p>
</div><div><p class="">{<u></u><u></u></p></div><div><p class="">  intptr_t c = (intptr_t)a;<u></u><u></u></p></div><div><p class="">  b = (int*) c;<u></u><u></u></p></div><div><p class="">  *a += b;<u></u><u></u></p></div>
<div><p class="">}<u></u><u></u></p></div><div><p class=""><u></u> <u></u></p></div><div><p class="">and the code generated is <u></u><u></u></p></div><div><p class=""><u></u> <u></u></p></div><div><div><p class="">define ptx_kernel void @intptr_t_kernel(i32* %a, i32* nocapture %b) nounwind noinline {<u></u><u></u></p>
</div><div><p class="">entry:<u></u><u></u></p></div><div><p class="">  %0 = load i32* %a, align 4, !tbaa !1<u></u><u></u></p></div><div><p class="">  %add.ptr = getelementptr inbounds i32* %a, i32 %0<u></u><u></u></p></div>
<div><p class="">  %conv = ptrtoint i32* %add.ptr to i32<u></u><u></u></p></div><div><p class="">  store i32 %conv, i32* %a, align 4, !tbaa !1<u></u><u></u></p></div><div><p class="">  ret void<u></u><u></u></p></div><div>
<p class="">}<u></u><u></u></p></div><div><p class=""><u></u> <u></u></p></div><div><p class="">Thanks a lot for help.<u></u><u></u></p></div><div><p class=""><u></u> <u></u></p></div><div><p class="">Regards,<u></u><u></u></p>
</div><div><p class="">Ankur<u></u><u></u></p></div></div></div></div></div></div><p class=""><u></u> <u></u></p></div></div></div></div></div></blockquote></div><br></div></div></div></div></div>