<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=utf-8"><meta name=Generator content="Microsoft Word 14 (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;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 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";
        color:black;}
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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";
        color:black;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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 bgcolor=white lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>> </span><span style='font-size:10.5pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>So, when Clang do semantic check, 0 is interpreted as integer instead of null pointer?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>Yes, Clang will cast 0 implicitly to the null pointer of the type it is being compare to, so the address space will be taken into account correctly in this case.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>If you use (void *)0, Clang will apply default address space to your null pointer (as it’s not provided explicitly). Therefore, pointers will appear to point to different address spaces.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>Anastasia <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.5pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext;mso-fareast-language:ZH-CN'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext;mso-fareast-language:ZH-CN'> Anastasia Stulova [<a href="mailto:anastasia.stulova@arm.com">mailto:anastasia.stulova@arm.com</a>] <br><b>Sent:</b> Friday, February 13, 2015 6:23 PM<br><b>To:</b> 'Sameer Sahasrabuddhe'; Song, Ruiling<br><b>Cc:</b> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br><b>Subject:</b> RE: Got compile error 'comparison between non-overlapping address spaces' on 3.6 branch<o:p></o:p></span></p></div></div><p class=MsoNormal><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>Hi Ruiling,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>I agree with Sameer, in general in CL2.0 your example will have a comparison between global and generic address spaces, which is allowed.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>However, for all CL versions Clang still uses private as default address space of pointers. Some time ago, I’ve sent a patch changing this to comply with CL2.0 rules. My patch wasn’t complete though, because default address space rules are a bit more complex, i.e. program scope pointers should have global address space as default and all other pointers generic. I will see if I can find time to rework this patch.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>In  the meantime, would this be sufficient for you:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>#define NULL 0<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>This will result in the comparison between a pointer and an integer literal, which is allowed in OpenCL. Also this is the only solution for CL earlier than v2.0.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'>Anastasia<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D;mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext;mso-fareast-language:ZH-CN'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext;mso-fareast-language:ZH-CN'> Sameer Sahasrabuddhe [<a href="mailto:sameer.sahasrabuddhe@amd.com">mailto:sameer.sahasrabuddhe@amd.com</a>] <br><b>Sent:</b> 13 February 2015 06:17<br><b>To:</b> Song, Ruiling; Anastasia Stulova<br><b>Cc:</b> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br><b>Subject:</b> Re: Got compile error 'comparison between non-overlapping address spaces' on 3.6 branch<o:p></o:p></span></p></div></div><p class=MsoNormal><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></p><p class=MsoNormal style='margin-bottom:12.0pt'><span style='mso-fareast-language:ZH-CN'><br>Hello Ruiling,<br><br>As far as I can see, the C spec defines the literal "0" as the null pointer, so the following macro seems better:<br><br>#define NULL 0<br><br>But ignoring the NULL, I think the behaviour might change between OpenCL 1.2 and OpenCL 2.0. In CL12, the "void *" is likely to be a pointer to the private address space. In that case, the comparison is undefined. In CL20, it is likely to be a pointer to the generic address space, and it should be allowed by the frontend. (Because generic address space includes global address space).<br><br>I have to use words like "should" and "likely to" because this needs confirmation from language lawyers ... the question actually pushes the boundaries of how much I understand the details of OpenCL! :)<br><br>Sameer.<o:p></o:p></span></p><div><p class=MsoNormal><span style='mso-fareast-language:ZH-CN'>On 2/13/2015 11:25 AM, Song, Ruiling wrote:<o:p></o:p></span></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' id="mid_148B1B7A67D1C24B9EF0BE42EA4977062B7D75D8_SHSMSX101_ccr_corp_intel_com"><pre><span style='mso-fareast-language:ZH-CN'>Hi Sameer, Anastasia,<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Do you have any comment on this? Thanks!<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Ruiling<o:p></o:p></span></pre><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt' id="Cite_2351749"><pre><span style='mso-fareast-language:ZH-CN'>-----Original Message-----<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>From: Song, Ruiling<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Sent: Wednesday, February 11, 2015 10:38 AM<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>To: '<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>'<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Subject: Got compile error 'comparison between non-overlapping address<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>spaces' on 3.6 branch<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>I am a developer working on Beignet (OpenCL driver for Intel Graphics card).<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>I am trying Clang 3.6 branch, and encounter below problem. It works well in<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>older clang version.<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>We define NULL as "#define NULL (void *)0", so user could directly use it in<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>OpenCL language like __kernel void test(__global unsigned int *dst)<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>   if (dst != NULL) {do something;}<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>}<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>But I got below error when compiling using clang 3.6.<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>"error: comparison between  ('__global unsigned int *' and 'void *') which<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>are pointers to non-overlapping address spaces"<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Is this the expected behavior or a bug?<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Thanks!<o:p></o:p></span></pre><pre><span style='mso-fareast-language:ZH-CN'>Ruiling<o:p></o:p></span></pre></blockquote></blockquote><p class=MsoNormal style='margin-bottom:12.0pt'><span style='mso-fareast-language:ZH-CN'><o:p> </o:p></span></p></div></div></body></html>