<span style="font-family: Tahoma, Geneva, sans-serif; font-size: 10pt"><font face="Arial, Verdana" size="2">Hi everyone,</font><div style="font-family: Arial, Verdana; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><br></div><div style="font-family: Arial, Verdana; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;">I have some problems with gettings the X86_thiscall calling convention to work. I am new to LLVM, so if this is the wrong place for this question then I appologise, please tell me where to go instead.</div><div style="font-family: Arial, Verdana; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><br></div><div style="font-family: Arial, Verdana; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;">I am generating code to call a member function of a class compiled with Microsoft Visual C++ using the JIT compiler.<br><br><div></div></div><div style="font-family: Arial, Verdana; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;">The following code is used to register the pointer to the function. as_ptr retrieves the address of a member function pointer. Yes, this is a bit of a hack, but it works (I have tested it in other situations).</div><div style="font-family: Arial, Verdana; font-size: 10pt; font-style: normal; font-variant: normal; font-weight: normal; line-height: normal;"><br></div><div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space: pre;">           </span>vector<llvm::Type *> arguments;</font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space:pre">            </span>arguments.push_back(interface_group_ptr);</font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space:pre">                </span>arguments.push_back(any);</font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space:pre">                </span>arguments.push_back(instance_ptr);</font></div><div><font face="Arial, Verdana" size="2"><br></font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space:pre">          </span>auto get_interface_type=FunctionType::get(any, arguments, false);</font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space:pre">                </span>interface_group_get_interface=Function::Create(get_interface_type, Function::ExternalLinkage, "get_interface", llvm_module);</font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space:pre">           </span>interface_group_get_interface->setCallingConv(CallingConv::X86_ThisCall);</font></div><div><font face="Arial, Verdana" size="2"><span class="Apple-tab-span" style="white-space: pre;">           </span>execution_engine->addGlobalMapping(interface_group_get_interface, (void *)as_ptr(&InterfaceGroup::get_interface));</font></div></div><div><font face="Arial, Verdana" size="2"><br></font></div><div><font face="Arial, Verdana" size="2">The following call generates the code for the call:</font></div><div><font face="Arial, Verdana" size="2"><br></font></div><div><font face="Arial, Verdana" size="2"><div><span class="Apple-tab-span" style="white-space:pre">         </span>vector<Value *> get_interface_args;</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>get_interface_args.push_back(interface_group_variable);</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>get_interface_args.push_back(requested_type);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>get_interface_args.push_back(ptr_this);</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>auto result=llvm_builder.CreateCall(module->interface_group_get_interface, get_interface_args);</div><div><br></div><div>Now the problem is that the generated code does not actually seem to be using the thiscall calling convention specified for the called function:</div><div><br></div><div><div>0011001B  mov         dword ptr [esp+8],eax  </div><div>0011001F  mov         eax,dword ptr [esp+14h]  </div><div>00110023  mov         dword ptr [esp+4],eax  </div><div>00110027  mov         dword ptr [esp],102594h  </div><div>0011002E  call        Zeo::InterfaceGroup::get_interface (0151B133h)  </div><div>00110033  add         esp,10h  </div></div><div><br></div><div>0x102594 is the address of the object that I am trying to call a member function on, and should be loaded into ecx by the code, instead of stored on the stack. The result is that the right function is called, but 'this' and the other parameters are incorrect.</div><div><br></div><div>From what I have been reading about it, this calling convention should be implemented, so either I am doing something wrong, or there is a bug in LLVM in general, or the JIT compiler specifically. The chance that I am doing something wrong is probably bigger, but I do not know what.</div><div><br></div><div>Any tips would be greatly appreciated. By the way, I am using a 3.3 release built with Visual Studio.</div><div><br></div><div>With kind regards,</div><div>Taco.</div><div><br></div><div><br></div></font></div></span>