From b981f80e854b83fac0fd61b94b7f49f43429f7af Mon Sep 17 00:00:00 2001 From: Hunter Bridges <775593+hunterbridges@users.noreply.github.com> Date: Fri, 7 Jan 2022 19:22:47 -0800 Subject: [PATCH] Aarch64 "unsupported calling convention" compiler crash fix --- IDEHelper/Compiler/BfIRCodeGen.cpp | 34 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/IDEHelper/Compiler/BfIRCodeGen.cpp b/IDEHelper/Compiler/BfIRCodeGen.cpp index 209dcf2c..0e1da5ea 100644 --- a/IDEHelper/Compiler/BfIRCodeGen.cpp +++ b/IDEHelper/Compiler/BfIRCodeGen.cpp @@ -203,17 +203,29 @@ template class CmdParamVec : public llvm::SmallVector {}; -static int GetLLVMCallingConv(BfIRCallingConv callingConv) +static int GetLLVMCallingConv(BfIRCallingConv callingConv, BfTargetTriple& targetTriple) { int llvmCallingConv = llvm::CallingConv::C; - if (callingConv == BfIRCallingConv_ThisCall) - llvmCallingConv = llvm::CallingConv::X86_ThisCall; - else if (callingConv == BfIRCallingConv_StdCall) - llvmCallingConv = llvm::CallingConv::X86_StdCall; - else if (callingConv == BfIRCallingConv_FastCall) - llvmCallingConv = llvm::CallingConv::X86_FastCall; - else if (callingConv == BfIRCallingConv_CDecl) - llvmCallingConv = llvm::CallingConv::C; + + if (targetTriple.GetMachineType() == BfMachineType_AArch64) + { + if (callingConv == BfIRCallingConv_CDecl) + llvmCallingConv = llvm::CallingConv::C; + else + llvmCallingConv = llvm::CallingConv::PreserveMost; + } + else + { + if (callingConv == BfIRCallingConv_ThisCall) + llvmCallingConv = llvm::CallingConv::X86_ThisCall; + else if (callingConv == BfIRCallingConv_StdCall) + llvmCallingConv = llvm::CallingConv::X86_StdCall; + else if (callingConv == BfIRCallingConv_FastCall) + llvmCallingConv = llvm::CallingConv::X86_FastCall; + else if (callingConv == BfIRCallingConv_CDecl) + llvmCallingConv = llvm::CallingConv::C; + } + return llvmCallingConv; } @@ -3601,14 +3613,14 @@ void BfIRCodeGen::HandleNextCmd() CMD_PARAM(llvm::Value*, callInst); BfIRCallingConv callingConv = (BfIRCallingConv)mStream->Read(); BF_ASSERT(llvm::isa(callInst)); - ((llvm::CallInst*)callInst)->setCallingConv(GetLLVMCallingConv(callingConv)); + ((llvm::CallInst*)callInst)->setCallingConv(GetLLVMCallingConv(callingConv, mTargetTriple)); } break; case BfIRCmd_SetFuncCallingConv: { CMD_PARAM(llvm::Function*, func); BfIRCallingConv callingConv = (BfIRCallingConv)mStream->Read(); - ((llvm::Function*)func)->setCallingConv(GetLLVMCallingConv(callingConv)); + ((llvm::Function*)func)->setCallingConv(GetLLVMCallingConv(callingConv, mTargetTriple)); } break; case BfIRCmd_SetTailCall: