1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed issues with global var addresses in const arrays

This commit is contained in:
Brian Fiete 2020-07-13 08:51:02 -07:00
parent 52af512b4f
commit b30a72719c
13 changed files with 376 additions and 36 deletions

View file

@ -17660,9 +17660,30 @@ void BfExprEvaluator::PerformUnaryOperation_OnResult(BfExpression* unaryOpExpr,
return;
}
if (mResult.mValue.IsConst())
{
auto constant = mModule->mBfIRBuilder->GetConstant(mResult.mValue);
bool isNull = constant->mTypeCode == BfTypeCode_NullPtr;
if (constant->mConstType == BfConstType_ExtractValue)
{
auto constExtract = (BfConstantExtractValue*)constant;
auto targetConst = mModule->mBfIRBuilder->GetConstantById(constExtract->mTarget);
if (targetConst->mConstType == BfConstType_AggZero)
isNull = true;
}
if (isNull)
{
mModule->Warn(0, "Cannot dereference a null pointer", unaryOpExpr);
mResult = mModule->GetDefaultTypedValue(mResult.mType, false, BfDefaultValueKind_Addr);
mResult = mModule->LoadValue(mResult);
}
}
auto derefTarget = mModule->LoadValue(mResult);
BfPointerType* pointerType = (BfPointerType*)derefTarget.mType;
BfPointerType* pointerType = (BfPointerType*)derefTarget.mType;
auto resolvedType = mModule->ResolveType(pointerType->mElementType);
if (resolvedType == NULL)
{