Constant pointer arithmetic for pointer initializers

This commit is contained in:
drmortalwombat 2022-04-18 22:23:13 +02:00
parent ecb9bbee8a
commit 253be26335
2 changed files with 6 additions and 1 deletions

View File

@ -464,6 +464,11 @@ Expression* Expression::ConstantFold(Errors * errors)
ex->mDecType = mLeft->mDecType;
return ex;
}
else if (mType == EX_BINARY && mToken == TK_ADD && mLeft->mType == EX_VARIABLE && mLeft->mDecValue->mType == DT_VARIABLE && (mLeft->mDecValue->mFlags & DTF_CONST) && mLeft->mDecType->mType == DT_TYPE_POINTER && mRight->mType == EX_CONSTANT && mRight->mDecValue->mType == DT_CONST_INTEGER)
{
mLeft = mLeft->mDecValue->mValue;
return this->ConstantFold(errors);
}
else if (mType == EX_QUALIFY && mLeft->mType == EX_VARIABLE && mLeft->mDecValue->mType == DT_VARIABLE && (mLeft->mDecValue->mFlags & DTF_GLOBAL) && mLeft->mDecType->mType == DT_TYPE_STRUCT)
{
Expression* ex = new Expression(mLocation, EX_VARIABLE);

View File

@ -5653,7 +5653,7 @@ int NativeCodeBasicBlock::ShortMultiply(InterCodeProcedure* proc, NativeCodeProc
lshift++;
}
if (mul > 1 && (lshift > 3 || lmul != 1) && ins->mSrc[index].IsUByte() && ins->mSrc[index].mRange.mMaxValue < 16)
if (mul > 1 && ((lshift & 7) > 3 || lmul != 1) && ins->mSrc[index].IsUByte() && ins->mSrc[index].mRange.mMaxValue < 16)
{
int dreg = BC_REG_TMP + proc->mTempOffset[ins->mDst.mTemp];