Browse Source

llvm: specify calling convention on call

Looks like the compiler only was specifying the calling convention on
function declarations, but not on function calls.
But LLVM seems to produce "bad" code when optimizing with level -O2
unless you specify the same calling convention on the call too.
Morten Hauke Solvang 1 year ago
parent
commit
fb5bb1cd83
1 changed files with 3 additions and 0 deletions
  1. 3 0
      src/llvm_backend_proc.cpp

+ 3 - 0
src/llvm_backend_proc.cpp

@@ -891,6 +891,9 @@ gb_internal lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue
 
 		LLVMValueRef ret = LLVMBuildCall2(p->builder, fnp, fn, args, arg_count, "");
 
+		auto llvm_cc = lb_calling_convention_map[proc_type->Proc.calling_convention];
+		LLVMSetInstructionCallConv(ret, llvm_cc);
+
 		LLVMAttributeIndex param_offset = LLVMAttributeIndex_FirstArgIndex;
 		if (return_ptr.value != nullptr) {
 			param_offset += 1;