mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Disallow object-to-void* casting. Lowering fixes. Variant fixes.
This commit is contained in:
parent
bca0440b16
commit
16be83ceda
12 changed files with 174 additions and 82 deletions
|
@ -5162,15 +5162,11 @@ void BfExprEvaluator::PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& ir
|
|||
return;
|
||||
|
||||
bool wantSplat = false;
|
||||
if (argVal.mType->IsSplattable())
|
||||
if ((argVal.mType->IsSplattable()) && (!disableSplat))
|
||||
{
|
||||
disableLowering = true;
|
||||
auto argTypeInstance = argVal.mType->ToTypeInstance();
|
||||
if ((argTypeInstance != NULL) && (argTypeInstance->mIsCRepr))
|
||||
{
|
||||
// Always splat for crepr splattables
|
||||
wantSplat = true;
|
||||
}
|
||||
else if ((!disableSplat) && (int)irArgs.size() + argVal.mType->GetSplatCount() <= mModule->mCompiler->mOptions.mMaxSplatRegs)
|
||||
if ((!disableSplat) && (int)irArgs.size() + argVal.mType->GetSplatCount() <= mModule->mCompiler->mOptions.mMaxSplatRegs)
|
||||
wantSplat = true;
|
||||
}
|
||||
|
||||
|
@ -5190,21 +5186,6 @@ void BfExprEvaluator::PushArg(BfTypedValue argVal, SizedArrayImpl<BfIRValue>& ir
|
|||
BfTypeCode loweredTypeCode2 = BfTypeCode_None;
|
||||
if (argVal.mType->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2))
|
||||
{
|
||||
// auto primType = mModule->GetPrimitiveType(loweredTypeCode);
|
||||
// auto ptrType = mModule->CreatePointerType(primType);
|
||||
// BfIRValue primPtrVal = mModule->mBfIRBuilder->CreateBitCast(argVal.mValue, mModule->mBfIRBuilder->MapType(ptrType));
|
||||
// auto primVal = mModule->mBfIRBuilder->CreateLoad(primPtrVal);
|
||||
// irArgs.push_back(primVal);
|
||||
//
|
||||
// if (loweredTypeCode2 != BfTypeCode_None)
|
||||
// {
|
||||
// auto primType2 = mModule->GetPrimitiveType(loweredTypeCode2);
|
||||
// auto ptrType2 = mModule->CreatePointerType(primType2);
|
||||
// BfIRValue primPtrVal2 = mModule->mBfIRBuilder->CreateBitCast(mModule->mBfIRBuilder->CreateInBoundsGEP(primPtrVal, 1), mModule->mBfIRBuilder->MapType(ptrType2));
|
||||
// auto primVal2 = mModule->mBfIRBuilder->CreateLoad(primPtrVal2);
|
||||
// irArgs.push_back(primVal2);
|
||||
// }
|
||||
|
||||
auto primType = mModule->mBfIRBuilder->GetPrimitiveType(loweredTypeCode);
|
||||
auto ptrType = mModule->mBfIRBuilder->GetPointerTo(primType);
|
||||
BfIRValue primPtrVal = mModule->mBfIRBuilder->CreateBitCast(argVal.mValue, ptrType);
|
||||
|
|
|
@ -15579,13 +15579,12 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp
|
|||
BfTypeUtils::SplatIterate([&](BfType* checkType) { argIdx++; }, paramVar->mResolvedType);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
argIdx++;
|
||||
if (loweredTypeCode2 != BfTypeCode_None)
|
||||
argIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (loweredTypeCode2 != BfTypeCode_None)
|
||||
argIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (argIdx == methodInstance->GetStructRetIdx())
|
||||
|
@ -15630,13 +15629,7 @@ void BfModule::ProcessMethod_SetupParams(BfMethodInstance* methodInstance, BfTyp
|
|||
}
|
||||
else if (resolvedType->IsComposite() && resolvedType->IsSplattable())
|
||||
{
|
||||
auto resolvedTypeInst = resolvedType->ToTypeInstance();
|
||||
if ((resolvedTypeInst != NULL) && (resolvedTypeInst->mIsCRepr))
|
||||
{
|
||||
// crepr splat is always splat
|
||||
paramVar->mIsSplat = true;
|
||||
}
|
||||
else if (methodInstance->AllowsSplatting())
|
||||
if (methodInstance->AllowsSplatting())
|
||||
{
|
||||
int splatCount = resolvedType->GetSplatCount();
|
||||
if (argIdx + splatCount <= mCompiler->mOptions.mMaxSplatRegs)
|
||||
|
@ -20083,10 +20076,19 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
|||
PopulateType(methodInstance->mReturnType, BfPopulateType_Data);
|
||||
if (!methodDef->mIsStatic)
|
||||
{
|
||||
auto thisType = methodInstance->GetOwner();
|
||||
if (methodInstance->GetParamIsSplat(-1))
|
||||
argIdx += methodInstance->GetParamType(-1)->GetSplatCount();
|
||||
else if (!methodInstance->GetOwner()->IsValuelessType())
|
||||
else if (!thisType->IsValuelessType())
|
||||
{
|
||||
BfTypeCode loweredTypeCode = BfTypeCode_None;
|
||||
BfTypeCode loweredTypeCode2 = BfTypeCode_None;
|
||||
if (!methodDef->mIsMutating)
|
||||
thisType->GetLoweredType(BfTypeUsage_Parameter, &loweredTypeCode, &loweredTypeCode2);
|
||||
argIdx++;
|
||||
if (loweredTypeCode2 != BfTypeCode_None)
|
||||
argIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (methodInstance->GetStructRetIdx() != -1)
|
||||
|
|
|
@ -8881,12 +8881,6 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
|
||||
if (explicitCast)
|
||||
{
|
||||
// Object -> void*
|
||||
if ((typedVal.mType->IsObject()) && (toType->IsVoidPtr()))
|
||||
{
|
||||
return mBfIRBuilder->CreateBitCast(typedVal.mValue, mBfIRBuilder->MapType(toType));
|
||||
}
|
||||
|
||||
// Func -> void*
|
||||
if ((typedVal.mType->IsFunction()) && (toType->IsVoidPtr()))
|
||||
{
|
||||
|
|
|
@ -2183,7 +2183,8 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
|
|||
|
||||
if (auto condExpr = BfNodeDynCast<BfConditionalExpression>(unaryOpExpr->mExpression))
|
||||
{
|
||||
exprLeft = condExpr;
|
||||
if (exprLeft == unaryOpExpr)
|
||||
exprLeft = condExpr;
|
||||
ApplyToFirstExpression(unaryOpExpr, condExpr);
|
||||
}
|
||||
|
||||
|
@ -2197,7 +2198,8 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
|
|||
MEMBER_SET(unaryOpExpr, mExpression, assignmentExpr->mLeft);
|
||||
unaryOpExpr->SetSrcEnd(assignmentExpr->mLeft->GetSrcEnd());
|
||||
MEMBER_SET(assignmentExpr, mLeft, unaryOpExpr);
|
||||
exprLeft = assignmentExpr;
|
||||
if (exprLeft == unaryOpExpr)
|
||||
exprLeft = assignmentExpr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2211,7 +2213,8 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
|
|||
MEMBER_SET(unaryOpExpr, mExpression, dynCastExpr->mTarget);
|
||||
unaryOpExpr->SetSrcEnd(dynCastExpr->mTarget->GetSrcEnd());
|
||||
MEMBER_SET(dynCastExpr, mTarget, unaryOpExpr);
|
||||
exprLeft = dynCastExpr;
|
||||
if (exprLeft == unaryOpExpr)
|
||||
exprLeft = dynCastExpr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2225,7 +2228,8 @@ BfExpression* BfReducer::CreateExpression(BfAstNode* node, CreateExprFlags creat
|
|||
MEMBER_SET(unaryOpExpr, mExpression, caseExpr->mValueExpression);
|
||||
unaryOpExpr->SetSrcEnd(caseExpr->mValueExpression->GetSrcEnd());
|
||||
MEMBER_SET(caseExpr, mValueExpression, unaryOpExpr);
|
||||
exprLeft = caseExpr;
|
||||
if (exprLeft == unaryOpExpr)
|
||||
exprLeft = caseExpr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -924,7 +924,7 @@ int BfMethodInstance::DbgGetVirtualMethodNum()
|
|||
void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, SizedArrayImpl<BfIRType>& paramTypes, bool forceStatic)
|
||||
{
|
||||
module->PopulateType(mReturnType);
|
||||
|
||||
|
||||
BfTypeCode loweredReturnTypeCode = BfTypeCode_None;
|
||||
BfTypeCode loweredReturnTypeCode2 = BfTypeCode_None;
|
||||
if (GetLoweredReturnType(&loweredReturnTypeCode, &loweredReturnTypeCode2))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue