<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><div></div><br><div><div>On Jan 25, 2014, at 2:55 PM, Brandon Holt <<a href="mailto:bholt@cs.washington.edu">bholt@cs.washington.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Bringing this to the attention of the Clang list because that’s actually where my problems exist.<div><br></div><div>I’m working on using the “address_space” attribute to delineate special pointers in a pass I’m working on. This lets me intercept uses of these pointers and plug in calls to my runtime wherever there’s a load/store or other use. However, I’m having problems trying to call methods on pointers with this attribute.</div><div><br></div><div>I ran into a CodeGen problem where CodeGenFunction::EmitCall tried to `bitcast`an addrspace(N)* and failed an assertion. The attached patch is one possible fix, which is to use `addrspacecast` if the address spaces are different, otherwise just use `bitcast` as before. This has allowed me to then write my own pass to replace these instances with things from my runtime.</div><div><br></div><div>However, I have a new problem now: the Clang type checker seems to choke converting between `__attribute__((address_space(N))` annotated types and const types, so that, though it allows me to call a non-const method on an addrspace pointer, it issues a compile error when I try to invoke a “const” method:</div><div><br></div><div style="font-size: 11px;"><font face="Menlo">struct Foo {</font></div><div style="font-size: 11px;"><font face="Menlo">  void bar() const { /* … */ }</font></div><div style="font-size: 11px;"><font face="Menlo">};</font></div><div style="font-size: 11px;"><font face="Menlo"><br></font></div><div style="font-size: 11px;"><font face="Menlo">__attribute__((address_space(N)) Foo f;</font></div><div style="font-size: 11px;"><font face="Menlo"><br></font></div><div style="font-size: 11px;"><font face="Menlo">void main() {</font></div><div style="font-size: 11px;"><font face="Menlo">  f.bar();</font></div><div style="font-size: 11px;"><font face="Menlo">}</font></div><div><br></div><div>Results in the following error message:</div><div><br></div><div><div style="font-size: 11px;"><font face="Menlo">error: cannot initialize object parameter of type 'const Foo' with an expression of type '__attribute__((address_space(200))) Foo'</font></div><div style="font-size: 11px;"><font face="Menlo">    f.bar(0);</font></div></div><div><br></div><div>It seems to me that const/non-const is orthogonal to address space attributes, so if one method invocation works, the other should as well. So my question is: which behavior is intended to be correct? Should Clang allow methods on arbitrary address spaces? (if not, how would one write a method to be used on the address space version?) It seems like this question must come up in the OpenCL/CUDA extensions, but I am not familiar with those so don’t know how this is handled there.</div><div><br></div><div>Thanks,</div><div>-Brandon</div><div><div><br></div><div></div></div></div></blockquote></div></body></html>