<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">I’ve been developing an optimization pass that uses the address space attribute (__attribute__((address_space(200))) to indicate different kinds of pointers to be treated differently (I’m making them be pointers to a “global” address space as in UPC).<div><br></div><div>However, I’ve hit a snag in the frontend code generator: if I try to make a method call on a pointer with a custom address space, the frontend chokes because it can’t bitcast between different address spaces, and methods are functions that take a pointer to “this” which is assumed to be in addrspace(0):</div><div><br></div><div><div></div><blockquote type="cite"><div style="font-size: 11px;"><font face="Inconsolata LGC">Assertion failed: (castIsValid(op, S, Ty) && "Invalid cast!"), function Create, file ../lib/IR/Instructions.cpp, line 2352.</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">0 clang-3.4 0x00000001039527f8 llvm::sys::PrintStackTrace(__sFILE*) + 40</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">1 clang-3.4 0x0000000103952c54 SignalHandler(int) + 388</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">2 libsystem_platform.dylib 0x00007fff802395aa _sigtramp + 26</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">3 libsystem_platform.dylib 000000000000000000 _sigtramp + 2145151600</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">4 clang-3.4 0x0000000103952ab6 abort + 22</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">5 clang-3.4 0x0000000103952a91 __assert_rtn + 81</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">6 clang-3.4 0x000000010385f8bf llvm::CastInst::Create(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::Instruction*) + 687</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">7 clang-3.4 0x00000001030a4d1c llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) + 76</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">8 clang-3.4 0x0000000103bbeac3 clang::CodeGen::CodeGenFunction::EmitCall(clang::CodeGen::CGFunctionInfo const&, llvm::Value*, clang::CodeGen::ReturnValueSlot, clang::CodeGen::CallArgList const&, clang::Decl const*, llvm::Instruction**) + 3075</font></div><div style="font-size: 11px;"><font face="Inconsolata LGC">9 clang-3.4 0x0000000103c11c02 clang::CodeGen::CodeGenFunction::EmitCXXMemberCall(clang::CXXMethodDecl const*, clang::SourceLocation, llvm::Value*, clang::CodeGen::ReturnValueSlot, llvm::Value*, llvm::Value*, clang::QualType, clang::ConstExprIterator, clang::ConstExprIterator) + 738</font></div></blockquote></div><div><br></div><div>I know it is not actually expected to be correct behavior to use other addrspace pointers in place of addrspace(0) pointers. My transformation passes change these calls, but I don’t get a chance to make the change because the frontend chokes first.</div><div><br></div><div>My questions are:</div><div>1. Is there a more graceful way that these bitcasts could be handled? Code to load/store from alternate address spaces is allowed to be generated, it just segfaults when run. Can the same behavior be allowed without breaking things for method calls to these pointers? I can imagine simply adding code to detect if the address space is wrong and applying an addrspace cast to get around it.</div><div><br></div><div>2. Is there a way to create methods that can be called with pointers to different address spaces? It seems there is no way to declare these in C++ using GNU attributes, and addrspace() seems to not be supported by C++11 attribute syntax, which could possibly express this.</div><div><br></div><div>Thanks,</div><div>-Brandon</div><div><br></div><div>--</div><div>Brandon Holt</div><div>Grad student @ University of Washington</div><div><a href="http://homes.cs.washington.edu/~bholt">http://homes.cs.washington.edu/~bholt</a></div></body></html>