1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +02:00

Fixed deferring of sret methods

This commit is contained in:
Brian Fiete 2021-07-05 17:28:15 -07:00
parent 46cc3d088b
commit 246e56c144
2 changed files with 22 additions and 9 deletions

View file

@ -12010,11 +12010,17 @@ BfTypedValue BfModule::MakeAddressable(BfTypedValue typedVal, bool forceMutable)
return typedVal; return typedVal;
BfType* type = typedVal.mType; BfType* type = typedVal.mType;
PopulateType(type); PopulateType(type);
auto tempVar = CreateAlloca(type); BfIRValue tempVar;
if (typedVal.mValue.IsFake())
tempVar = mBfIRBuilder->GetFakeVal();
else
{
tempVar = CreateAlloca(type);
if (typedVal.IsSplat()) if (typedVal.IsSplat())
AggregateSplatIntoAddr(typedVal, tempVar); AggregateSplatIntoAddr(typedVal, tempVar);
else else
mBfIRBuilder->CreateAlignedStore(typedVal.mValue, tempVar, type->mAlign); mBfIRBuilder->CreateAlignedStore(typedVal.mValue, tempVar, type->mAlign);
}
if (forceMutable) if (forceMutable)
wasReadOnly = false; wasReadOnly = false;

View file

@ -72,11 +72,18 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
SizedArray<BfIRType, 8> origParamTypes; SizedArray<BfIRType, 8> origParamTypes;
BfIRType origReturnType; BfIRType origReturnType;
deferredCallEntry->mModuleMethodInstance.mMethodInstance->GetIRFunctionInfo(this, origReturnType, origParamTypes); deferredCallEntry->mModuleMethodInstance.mMethodInstance->GetIRFunctionInfo(this, origReturnType, origParamTypes);
BF_ASSERT(origParamTypes.size() == deferredCallEntry->mScopeArgs.size());
for (int paramIdx = 0; paramIdx < (int)deferredCallEntry->mScopeArgs.size(); paramIdx++) int sretIdx = deferredCallEntry->mModuleMethodInstance.mMethodInstance->GetStructRetIdx();
BF_ASSERT(origParamTypes.size() == deferredCallEntry->mScopeArgs.size() + ((sretIdx != -1) ? 1 : 0));
int argIdx = 0;
int paramIdx = 0;
for (int argIdx = 0; argIdx < (int)deferredCallEntry->mScopeArgs.size(); argIdx++, paramIdx++)
{ {
auto scopeArg = deferredCallEntry->mScopeArgs[paramIdx]; if (argIdx == sretIdx)
paramIdx++;
auto scopeArg = deferredCallEntry->mScopeArgs[argIdx];
if ((scopeArg.IsConst()) || (scopeArg.IsFake())) if ((scopeArg.IsConst()) || (scopeArg.IsFake()))
continue; continue;
@ -92,7 +99,7 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
} }
mBfIRBuilder->CreateStore(scopeArg, allocaInst); mBfIRBuilder->CreateStore(scopeArg, allocaInst);
mBfIRBuilder->ClearDebugLocation_Last(); mBfIRBuilder->ClearDebugLocation_Last();
deferredCallEntry->mScopeArgs[paramIdx] = allocaInst; deferredCallEntry->mScopeArgs[argIdx] = allocaInst;
if (WantsLifetimes()) if (WantsLifetimes())
scopeData->mDeferredLifetimeEnds.push_back(allocaInst); scopeData->mDeferredLifetimeEnds.push_back(allocaInst);
} }