Fix type check of pointers derived by address of operator
This commit is contained in:
parent
bfe6311ca4
commit
ec31b845b8
|
@ -588,7 +588,7 @@ Expression* Expression::ConstantFold(Errors * errors)
|
|||
Declaration::Declaration(const Location& loc, DecType type)
|
||||
: mLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0),
|
||||
mBase(nullptr), mParams(nullptr), mValue(nullptr), mNext(nullptr), mVarIndex(-1), mLinkerObject(nullptr), mCallers(nullptr), mCalled(nullptr), mAlignment(1),
|
||||
mInteger(0), mNumber(0), mMinValue(-0x80000000LL), mMaxValue(0x7fffffffLL), mFastCallBase(0), mFastCallSize(0), mStride(1), mStripe(1)
|
||||
mInteger(0), mNumber(0), mMinValue(-0x80000000LL), mMaxValue(0x7fffffffLL), mFastCallBase(0), mFastCallSize(0), mStride(0), mStripe(1)
|
||||
{}
|
||||
|
||||
Declaration::~Declaration(void)
|
||||
|
@ -597,6 +597,11 @@ Declaration::~Declaration(void)
|
|||
delete[] mData;
|
||||
}
|
||||
|
||||
int Declaration::Stride(void) const
|
||||
{
|
||||
return mStride > 0 ? mStride : mBase->mSize;
|
||||
}
|
||||
|
||||
Declaration* Declaration::Clone(void)
|
||||
{
|
||||
Declaration* ndec = new Declaration(mLocation, mType);
|
||||
|
@ -714,7 +719,7 @@ bool Declaration::IsSubType(const Declaration* dec) const
|
|||
if (mType == DT_TYPE_POINTER || mType == DT_TYPE_ARRAY)
|
||||
{
|
||||
if (dec->mType == DT_TYPE_POINTER)
|
||||
return mStride == dec->mStride && mBase->IsSubType(dec->mBase);
|
||||
return this->Stride() == dec->Stride() && mBase->IsSubType(dec->mBase);
|
||||
}
|
||||
|
||||
if (mType != dec->mType)
|
||||
|
@ -789,7 +794,7 @@ bool Declaration::IsConstSame(const Declaration* dec) const
|
|||
else if (mType == DT_TYPE_ENUM)
|
||||
return mIdent == dec->mIdent;
|
||||
else if (mType == DT_TYPE_POINTER || mType == DT_TYPE_ARRAY)
|
||||
return mStride == dec->mStride && mBase->IsSame(dec->mBase);
|
||||
return this->Stride() == dec->Stride() && mBase->IsSame(dec->mBase);
|
||||
else if (mType == DT_TYPE_STRUCT)
|
||||
return mScope == dec->mScope || (mIdent == dec->mIdent && mSize == dec->mSize);
|
||||
else if (mType == DT_TYPE_FUNCTION)
|
||||
|
@ -838,7 +843,7 @@ bool Declaration::IsSame(const Declaration* dec) const
|
|||
else if (mType == DT_TYPE_ENUM)
|
||||
return mIdent == dec->mIdent;
|
||||
else if (mType == DT_TYPE_POINTER || mType == DT_TYPE_ARRAY)
|
||||
return mStride == dec->mStride && mBase->IsSame(dec->mBase);
|
||||
return this->Stride() == dec->Stride() && mBase->IsSame(dec->mBase);
|
||||
else if (mType == DT_TYPE_STRUCT)
|
||||
return mScope == dec->mScope || (mIdent == dec->mIdent && mSize == dec->mSize);
|
||||
else if (mType == DT_TYPE_FUNCTION)
|
||||
|
|
|
@ -208,6 +208,8 @@ public:
|
|||
Declaration* ToStriped(int stripe);
|
||||
Declaration* ToStriped(void);
|
||||
Declaration* Clone(void);
|
||||
|
||||
int Stride(void) const;
|
||||
};
|
||||
|
||||
void InitDeclarations(void);
|
||||
|
|
|
@ -11289,8 +11289,10 @@ void InterCodeBasicBlock::CheckFinalLocal(void)
|
|||
const InterInstruction* ins(mInstructions[i]);
|
||||
for (int j = 0; j < ins->mNumOperands; j++)
|
||||
{
|
||||
if (ins->mSrc[j].mTemp >= 0)
|
||||
assert(provided[ins->mSrc[j].mTemp]);
|
||||
if (ins->mSrc[j].mTemp >= 0 && !provided[ins->mSrc[j].mTemp])
|
||||
{
|
||||
printf("Use of potentially undefined temp %d\n", ins->mSrc[j].mTemp);
|
||||
}
|
||||
}
|
||||
|
||||
if (ins->mDst.mTemp >= 0)
|
||||
|
@ -12311,16 +12313,16 @@ void InterCodeBasicBlock::WarnUsedUndefinedVariables(InterCodeProcedure* proc)
|
|||
if (potentialTemps[t])
|
||||
{
|
||||
if (k < proc->mLocalVars.Size() && proc->mLocalVars[k]->mIdent)
|
||||
proc->mModule->mErrors->Error(ins->mLocation, EWARN_USE_OF_UNINITIALIZED_VARIABLE, "Use of potentialy uninitialized variable", proc->mLocalVars[k]->mIdent);
|
||||
proc->mModule->mErrors->Error(ins->mLocation, EWARN_USE_OF_UNINITIALIZED_VARIABLE, "Use of potentially uninitialized variable", proc->mLocalVars[k]->mIdent);
|
||||
else
|
||||
proc->mModule->mErrors->Error(ins->mLocation, EWARN_USE_OF_UNINITIALIZED_VARIABLE, "Use of potentialy uninitialized expression");
|
||||
proc->mModule->mErrors->Error(ins->mLocation, EWARN_USE_OF_UNINITIALIZED_VARIABLE, "Use of potentially uninitialized expression");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (k < proc->mLocalVars.Size() && proc->mLocalVars[k]->mIdent)
|
||||
proc->mModule->mErrors->Error(ins->mLocation, ERRR_USE_OF_UNINITIALIZED_VARIABLE, "Use of uninitialized variable", proc->mLocalVars[k]->mIdent);
|
||||
proc->mModule->mErrors->Error(ins->mLocation, EWARN_USE_OF_UNINITIALIZED_VARIABLE, "Use of uninitialized variable", proc->mLocalVars[k]->mIdent);
|
||||
else
|
||||
proc->mModule->mErrors->Error(ins->mLocation, ERRR_USE_OF_UNINITIALIZED_VARIABLE, "Use of uninitialized expression");
|
||||
proc->mModule->mErrors->Error(ins->mLocation, EWARN_USE_OF_UNINITIALIZED_VARIABLE, "Use of uninitialized expression");
|
||||
|
||||
if (ins->mCode == IC_LOAD_TEMPORARY)
|
||||
{
|
||||
|
|
|
@ -1207,7 +1207,7 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
vl = TranslateExpression(procType, proc, block, exp->mLeft, breakBlock, continueBlock, inlineMapper);
|
||||
vr = TranslateExpression(procType, proc, block, exp->mRight, breakBlock, continueBlock, inlineMapper);
|
||||
|
||||
int stride = vl.mType->mStride;
|
||||
int stride = vl.mType->Stride();
|
||||
|
||||
if (vl.mType->mType == DT_TYPE_ARRAY && exp->mRight->mType == EX_CONSTANT && exp->mRight->mDecValue->mType == DT_CONST_INTEGER)
|
||||
{
|
||||
|
@ -2405,7 +2405,10 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration*
|
|||
if (pdec)
|
||||
{
|
||||
if (!pdec->mBase->CanAssign(vr.mType))
|
||||
{
|
||||
pdec->mBase->CanAssign(vr.mType);
|
||||
mErrors->Error(texp->mLocation, EERR_INCOMPATIBLE_TYPES, "Cannot assign incompatible types");
|
||||
}
|
||||
vr = CoerceType(proc, texp, block, vr, pdec->mBase);
|
||||
}
|
||||
else if (vr.mType->IsIntegerType() && vr.mType->mSize < 2)
|
||||
|
|
|
@ -553,12 +553,7 @@ Declaration* Parser::ReverseDeclaration(Declaration* odec, Declaration* bdec)
|
|||
if (bdec)
|
||||
{
|
||||
if (odec->mType == DT_TYPE_ARRAY)
|
||||
{
|
||||
odec->mStride = bdec->mSize;
|
||||
odec->mSize *= bdec->mSize;
|
||||
}
|
||||
else if (odec->mType == DT_TYPE_POINTER)
|
||||
odec->mStride = bdec->mSize;
|
||||
else if (odec->mType == DT_VARIABLE || odec->mType == DT_ARGUMENT || odec->mType == DT_ANON)
|
||||
odec->mSize = bdec->mSize;
|
||||
odec->mBase = bdec;
|
||||
|
@ -751,7 +746,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
|
||||
if (dtype->mType == DT_TYPE_ARRAY)
|
||||
{
|
||||
int index = 0, stride = dtype->mStride, size = 0;
|
||||
int index = 0, stride = dtype->Stride(), size = 0;
|
||||
|
||||
if (dtype->mFlags & DTF_STRIPED)
|
||||
dec->mStripe = dtype->mBase->mStripe;
|
||||
|
@ -913,6 +908,7 @@ Expression* Parser::ParseInitExpression(Declaration* dtype)
|
|||
nexp->mDecType = new Declaration(dec->mLocation, DT_TYPE_POINTER);
|
||||
nexp->mDecType->mBase = exp->mDecType->mBase;
|
||||
nexp->mDecType->mSize = 2;
|
||||
nexp->mDecType->mStride = exp->mDecType->mStride;
|
||||
nexp->mDecType->mFlags |= DTF_DEFINED;
|
||||
nexp->mDecValue = ndec;
|
||||
exp = nexp;
|
||||
|
@ -1824,6 +1820,8 @@ Expression* Parser::ParseAddExpression(void)
|
|||
Declaration* dec = new Declaration(nexp->mLocation, DT_TYPE_POINTER);
|
||||
dec->mSize = 2;
|
||||
dec->mBase = nexp->mLeft->mDecType->mBase;
|
||||
dec->mStride = nexp->mLeft->mDecType->mStride;
|
||||
dec->mStripe = nexp->mLeft->mDecType->mStripe;
|
||||
nexp->mDecType = dec;
|
||||
}
|
||||
else if (nexp->mRight->mDecType->mType == DT_TYPE_ARRAY && nexp->mLeft->mDecType->IsIntegerType())
|
||||
|
@ -1831,6 +1829,8 @@ Expression* Parser::ParseAddExpression(void)
|
|||
Declaration* dec = new Declaration(nexp->mLocation, DT_TYPE_POINTER);
|
||||
dec->mSize = 2;
|
||||
dec->mBase = nexp->mRight->mDecType->mBase;
|
||||
dec->mStride = nexp->mRight->mDecType->mStride;
|
||||
dec->mStripe = nexp->mRight->mDecType->mStripe;
|
||||
nexp->mDecType = dec;
|
||||
}
|
||||
else if (nexp->mLeft->mDecType->mType == DT_TYPE_FLOAT || nexp->mRight->mDecType->mType == DT_TYPE_FLOAT)
|
||||
|
|
Loading…
Reference in New Issue