mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Sized-array calling convention fix
This commit is contained in:
parent
80fcf84de2
commit
8a63a7ed80
5 changed files with 17 additions and 5 deletions
|
@ -2400,7 +2400,7 @@ void BeIRCodeGen::HandleNextCmd()
|
||||||
callInst->mArgs[argIdx - 1].mByRefSize = arg;
|
callInst->mArgs[argIdx - 1].mByRefSize = arg;
|
||||||
if (auto func = BeValueDynCast<BeFunction>(callInst->mFunc))
|
if (auto func = BeValueDynCast<BeFunction>(callInst->mFunc))
|
||||||
{
|
{
|
||||||
BF_ASSERT(func->mParams[argIdx - 1].mByValSize == arg);
|
BF_ASSERT((func->mParams[argIdx - 1].mByValSize == arg) || (func->mParams[argIdx - 1].mByValSize == -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -5371,9 +5371,9 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance*
|
||||||
mModule->mBfIRBuilder->Call_AddAttribute(callInst, argIdx + 1, BfIRAttribute_NoCapture);
|
mModule->mBfIRBuilder->Call_AddAttribute(callInst, argIdx + 1, BfIRAttribute_NoCapture);
|
||||||
addDeref = paramType->mSize;
|
addDeref = paramType->mSize;
|
||||||
}
|
}
|
||||||
else if (methodInstance->WantsStructsAttribByVal())
|
else if ((methodInstance->WantsStructsAttribByVal()) && (!paramType->IsSizedArray()))
|
||||||
{
|
{
|
||||||
mModule->mBfIRBuilder->Call_AddAttribute(callInst, argIdx + 1, BfIRAttribute_ByVal, mModule->mSystem->mPtrSize);
|
mModule->mBfIRBuilder->Call_AddAttribute(callInst, argIdx + 1, BfIRAttribute_ByVal, paramType->mAlign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15676,10 +15676,11 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
|
||||||
PopulateType(resolvedTypeRef, BfPopulateType_Data);
|
PopulateType(resolvedTypeRef, BfPopulateType_Data);
|
||||||
addDeref = resolvedTypeRef->mSize;
|
addDeref = resolvedTypeRef->mSize;
|
||||||
}
|
}
|
||||||
else if (methodInstance->WantsStructsAttribByVal())
|
else if ((methodInstance->WantsStructsAttribByVal()) && (!resolvedTypeRef->IsSizedArray()))
|
||||||
{
|
{
|
||||||
mBfIRBuilder->PopulateType(resolvedTypeRef);
|
mBfIRBuilder->PopulateType(resolvedTypeRef);
|
||||||
mBfIRBuilder->Func_AddAttribute(func, argIdx + 1, BfIRAttribute_ByVal, mSystem->mPtrSize);
|
BF_ASSERT(resolvedTypeRef->mAlign > 0);
|
||||||
|
mBfIRBuilder->Func_AddAttribute(func, argIdx + 1, BfIRAttribute_ByVal, resolvedTypeRef->mAlign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (resolvedTypeRef->IsPrimitiveType())
|
else if (resolvedTypeRef->IsPrimitiveType())
|
||||||
|
|
|
@ -534,6 +534,11 @@ extern "C" Interop::StructJ Func4J(Interop::StructJ arg0, Interop::StructJ arg1,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" double Func5(float v0[2], float v1[3])
|
||||||
|
{
|
||||||
|
return v0[0] + v0[1]*10 + v1[0]*100 + v1[1]*1000 + v1[2]*10000;
|
||||||
|
}
|
||||||
|
|
||||||
void UseIt()
|
void UseIt()
|
||||||
{
|
{
|
||||||
Interop::StructA sa;
|
Interop::StructA sa;
|
||||||
|
|
|
@ -308,6 +308,9 @@ namespace Tests
|
||||||
[LinkName(.C)]
|
[LinkName(.C)]
|
||||||
public static extern StructJ Func4J(StructJ arg0, StructJ arg1, StructJ arg2, StructJ arg3);
|
public static extern StructJ Func4J(StructJ arg0, StructJ arg1, StructJ arg2, StructJ arg3);
|
||||||
|
|
||||||
|
[LinkName(.C)]
|
||||||
|
public static extern double Func5(float[2] v0, float[3] v1);
|
||||||
|
|
||||||
static int32 LocalFunc0K(int32 a, StructK b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
static int32 LocalFunc0K(int32 a, StructK b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||||
static int32 LocalFunc0L(int32 a, StructL b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
static int32 LocalFunc0L(int32 a, StructL b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||||
static int32 LocalFunc0M(int32 a, StructM b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
static int32 LocalFunc0M(int32 a, StructM b) => a + (int32)b.mX * 100 + (int32)b.mY * 10000;
|
||||||
|
@ -517,6 +520,9 @@ namespace Tests
|
||||||
sj3.mLength = 6;
|
sj3.mLength = 6;
|
||||||
var sjRet = Func4J(sj0, sj1, sj2, sj3);
|
var sjRet = Func4J(sj0, sj1, sj2, sj3);
|
||||||
Test.Assert(sjRet.mLength == 6050403);
|
Test.Assert(sjRet.mLength == 6050403);
|
||||||
|
|
||||||
|
var val5 = Func5(.(1, 2), .(3, 4, 5));
|
||||||
|
Test.Assert(Math.Round(val5) == 54321);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue