Error on pointer/integer compare

This commit is contained in:
drmortalwombat 2023-06-27 18:16:13 +02:00
parent a41c3d445b
commit 478f93922d
5 changed files with 37 additions and 20 deletions

View File

@ -2452,8 +2452,16 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
if (vl.mType->mType == DT_TYPE_POINTER || vr.mType->mType == DT_TYPE_POINTER)
{
dtype = vl.mType;
if (vl.mType->IsIntegerType() || vr.mType->IsIntegerType())
;
if (vl.mType->IsIntegerType())
{
if ((mCompilerOptions & COPT_CPLUSPLUS) || exp->mLeft->mType != EX_CONSTANT || exp->mLeft->mDecValue->mInteger != 0)
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot compare integer and pointer");
}
else if (vr.mType->IsIntegerType())
{
if ((mCompilerOptions & COPT_CPLUSPLUS) || exp->mRight->mType != EX_CONSTANT || exp->mRight->mDecValue->mInteger != 0)
mErrors->Error(exp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot compare integer and pointer");
}
else if ((vl.mType->mType == DT_TYPE_POINTER || vl.mType->mType == DT_TYPE_ARRAY) && (vr.mType->mType == DT_TYPE_POINTER || vr.mType->mType == DT_TYPE_ARRAY))
{
if (vl.mType->mBase->mType == DT_TYPE_VOID || vr.mType->mBase->mType == DT_TYPE_VOID)

View File

@ -12350,7 +12350,7 @@ void NativeCodeBasicBlock::BuildCollisionTable(NumberSet* collisionSets)
}
}
void NativeCodeBasicBlock::BuildDominatorTree(NativeCodeBasicBlock* from)
void NativeCodeBasicBlock::BuildDominatorTree(NativeCodeBasicBlock* from, DominatorStacks& stacks)
{
if (from == this)
return;
@ -12360,25 +12360,26 @@ void NativeCodeBasicBlock::BuildDominatorTree(NativeCodeBasicBlock* from)
return;
else
{
ExpandingArray< NativeCodeBasicBlock * > d1, d2;
stacks.d1.SetSize(0);
stacks.d2.SetSize(0);
NativeCodeBasicBlock* b = mDominator;
while (b)
{
d1.Push(b);
stacks.d1.Push(b);
b = b->mDominator;
}
b = from;
while (b)
{
d2.Push(b);
stacks.d2.Push(b);
b = b->mDominator;
}
b = nullptr;
while (d1.Size() > 0 && d2.Size() > 0 && d1.Last() == d2.Last())
while (stacks.d1.Size() > 0 && stacks.d2.Size() > 0 && stacks.d1.Last() == stacks.d2.Last())
{
b = d1.Pop(); d2.Pop();
b = stacks.d1.Pop(); stacks.d2.Pop();
}
if (mDominator == b)
@ -12388,9 +12389,9 @@ void NativeCodeBasicBlock::BuildDominatorTree(NativeCodeBasicBlock* from)
}
if (mTrueJump)
mTrueJump->BuildDominatorTree(this);
mTrueJump->BuildDominatorTree(this, stacks);
if (mFalseJump)
mFalseJump->BuildDominatorTree(this);
mFalseJump->BuildDominatorTree(this, stacks);
}
@ -40657,8 +40658,9 @@ void NativeCodeProcedure::RebuildEntry(void)
ResetVisited();
mEntryBlock->CollectEntryBlocks(nullptr);
NativeCodeBasicBlock::DominatorStacks stacks;
mEntryBlock->BuildDominatorTree(nullptr);
mEntryBlock->BuildDominatorTree(nullptr, stacks);
}
void NativeCodeProcedure::Optimize(void)
@ -41523,13 +41525,14 @@ void NativeCodeProcedure::ResetPatched(void)
{
for (int i = 0; i < mBlocks.Size(); i++)
{
mBlocks[i]->mPatched = false;
mBlocks[i]->mPatchFail = false;
mBlocks[i]->mPatchChecked = false;
mBlocks[i]->mPatchStart = false;
mBlocks[i]->mPatchLoop = false;
mBlocks[i]->mPatchLoopChanged = false;
mBlocks[i]->mPatchExit = false;
NativeCodeBasicBlock* b = mBlocks[i];
b->mPatched = false;
b->mPatchFail = false;
b->mPatchChecked = false;
b->mPatchStart = false;
b->mPatchLoop = false;
b->mPatchLoopChanged = false;
b->mPatchExit = false;
}
}

View File

@ -370,7 +370,13 @@ public:
NativeCodeBasicBlock * ForwardAccuBranch(bool eq, bool ne, bool pl, bool mi, int limit);
bool MergeBasicBlocks(void);
void MarkLoopHead(void);
void BuildDominatorTree(NativeCodeBasicBlock * from);
struct DominatorStacks
{
ExpandingArray< NativeCodeBasicBlock* > d1, d2;
};
void BuildDominatorTree(NativeCodeBasicBlock * from, DominatorStacks & stacks);
bool MoveLoadStoreUp(int at);
bool MoveLoadStoreXUp(int at);

View File

@ -1253,7 +1253,7 @@ void Parser::PrependMemberConstructor(Declaration* pthis, Declaration* cfunc)
{
Expression* pthisexp = new Expression(pthis->mLocation, EX_VARIABLE);
pthisexp->mDecType = pthis;
pthisexp->mDecValue = pthis->mBase->mDestructor->mBase->mParams;
pthisexp->mDecValue = cfunc->mBase->mParams;
Expression* thisexp = new Expression(mScanner->mLocation, EX_PREFIX);
thisexp->mToken = TK_MUL;

Binary file not shown.