<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Does the error go away if you do *a+=*b ?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Dave<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> cfe-dev-bounces@cs.uiuc.edu [mailto:cfe-dev-bounces@cs.uiuc.edu] <b>On Behalf Of </b>ankur deshwal<br><b>Sent:</b> 01 February 2013 12:02<br><b>To:</b> cfe-dev@cs.uiuc.edu<br><b>Subject:</b> [cfe-dev] Fwd: intptr_t support in llvm<o:p></o:p></span></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><div><p class=MsoNormal>Hi all,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>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 ).<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>typedef int intptr_t;<o:p></o:p></p></div><div><p class=MsoNormal>and<o:p></o:p></p></div><div><p class=MsoNormal>typedef __typeof( (int*) 0) intptr_t;<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Both definitions compiles the code, however gives following warning. <o:p></o:p></p></div><div><p class=MsoNormal>warning: incompatible pointer to integer conversion assigning to 'int' from 'int *'; dereference with *<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>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 ? <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>The code I tried to compile is <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>__kernel void intptr_t_kernel(int *a, int *b)<o:p></o:p></p></div><div><p class=MsoNormal>{<o:p></o:p></p></div><div><p class=MsoNormal>  intptr_t c = (intptr_t)a;<o:p></o:p></p></div><div><p class=MsoNormal>  b = (int*) c;<o:p></o:p></p></div><div><p class=MsoNormal>  *a += b;<o:p></o:p></p></div><div><p class=MsoNormal>}<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>and the code generated is <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>define ptx_kernel void @intptr_t_kernel(i32* %a, i32* nocapture %b) nounwind noinline {<o:p></o:p></p></div><div><p class=MsoNormal>entry:<o:p></o:p></p></div><div><p class=MsoNormal>  %0 = load i32* %a, align 4, !tbaa !1<o:p></o:p></p></div><div><p class=MsoNormal>  %add.ptr = getelementptr inbounds i32* %a, i32 %0<o:p></o:p></p></div><div><p class=MsoNormal>  %conv = ptrtoint i32* %add.ptr to i32<o:p></o:p></p></div><div><p class=MsoNormal>  store i32 %conv, i32* %a, align 4, !tbaa !1<o:p></o:p></p></div><div><p class=MsoNormal>  ret void<o:p></o:p></p></div><div><p class=MsoNormal>}<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Thanks a lot for help.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Regards,<o:p></o:p></p></div><div><p class=MsoNormal>Ankur<o:p></o:p></p></div></div></div></div></div></div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>