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) if (vl.mType->mType == DT_TYPE_POINTER || vr.mType->mType == DT_TYPE_POINTER)
{ {
dtype = vl.mType; 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)) 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) 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) if (from == this)
return; return;
@ -12360,25 +12360,26 @@ void NativeCodeBasicBlock::BuildDominatorTree(NativeCodeBasicBlock* from)
return; return;
else else
{ {
ExpandingArray< NativeCodeBasicBlock * > d1, d2; stacks.d1.SetSize(0);
stacks.d2.SetSize(0);
NativeCodeBasicBlock* b = mDominator; NativeCodeBasicBlock* b = mDominator;
while (b) while (b)
{ {
d1.Push(b); stacks.d1.Push(b);
b = b->mDominator; b = b->mDominator;
} }
b = from; b = from;
while (b) while (b)
{ {
d2.Push(b); stacks.d2.Push(b);
b = b->mDominator; b = b->mDominator;
} }
b = nullptr; 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) if (mDominator == b)
@ -12388,9 +12389,9 @@ void NativeCodeBasicBlock::BuildDominatorTree(NativeCodeBasicBlock* from)
} }
if (mTrueJump) if (mTrueJump)
mTrueJump->BuildDominatorTree(this); mTrueJump->BuildDominatorTree(this, stacks);
if (mFalseJump) if (mFalseJump)
mFalseJump->BuildDominatorTree(this); mFalseJump->BuildDominatorTree(this, stacks);
} }
@ -40657,8 +40658,9 @@ void NativeCodeProcedure::RebuildEntry(void)
ResetVisited(); ResetVisited();
mEntryBlock->CollectEntryBlocks(nullptr); mEntryBlock->CollectEntryBlocks(nullptr);
NativeCodeBasicBlock::DominatorStacks stacks;
mEntryBlock->BuildDominatorTree(nullptr); mEntryBlock->BuildDominatorTree(nullptr, stacks);
} }
void NativeCodeProcedure::Optimize(void) void NativeCodeProcedure::Optimize(void)
@ -41523,13 +41525,14 @@ void NativeCodeProcedure::ResetPatched(void)
{ {
for (int i = 0; i < mBlocks.Size(); i++) for (int i = 0; i < mBlocks.Size(); i++)
{ {
mBlocks[i]->mPatched = false; NativeCodeBasicBlock* b = mBlocks[i];
mBlocks[i]->mPatchFail = false; b->mPatched = false;
mBlocks[i]->mPatchChecked = false; b->mPatchFail = false;
mBlocks[i]->mPatchStart = false; b->mPatchChecked = false;
mBlocks[i]->mPatchLoop = false; b->mPatchStart = false;
mBlocks[i]->mPatchLoopChanged = false; b->mPatchLoop = false;
mBlocks[i]->mPatchExit = 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); NativeCodeBasicBlock * ForwardAccuBranch(bool eq, bool ne, bool pl, bool mi, int limit);
bool MergeBasicBlocks(void); bool MergeBasicBlocks(void);
void MarkLoopHead(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 MoveLoadStoreUp(int at);
bool MoveLoadStoreXUp(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); Expression* pthisexp = new Expression(pthis->mLocation, EX_VARIABLE);
pthisexp->mDecType = pthis; pthisexp->mDecType = pthis;
pthisexp->mDecValue = pthis->mBase->mDestructor->mBase->mParams; pthisexp->mDecValue = cfunc->mBase->mParams;
Expression* thisexp = new Expression(mScanner->mLocation, EX_PREFIX); Expression* thisexp = new Expression(mScanner->mLocation, EX_PREFIX);
thisexp->mToken = TK_MUL; thisexp->mToken = TK_MUL;

Binary file not shown.