Fix const node polution in const param optimization
This commit is contained in:
parent
cda66f3ec4
commit
bba8931860
|
@ -967,6 +967,16 @@ Declaration* Declaration::BuildArrayPointer(void)
|
|||
return this;
|
||||
}
|
||||
|
||||
bool Declaration::IsNullConst(void) const
|
||||
{
|
||||
if (mType == DT_CONST_INTEGER || mType == DT_CONST_ADDRESS)
|
||||
return mInteger == 0;
|
||||
else if (mType == DT_CONST_FLOAT)
|
||||
return mNumber == 0;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
Declaration* Declaration::ConstCast(Declaration* ntype)
|
||||
{
|
||||
if (ntype == mBase)
|
||||
|
|
|
@ -325,6 +325,7 @@ public:
|
|||
Declaration* BuildArrayPointer(void);
|
||||
Declaration* DeduceAuto(Declaration* dec);
|
||||
Declaration* ConstCast(Declaration* ntype);
|
||||
bool IsNullConst(void) const;
|
||||
bool IsAuto(void) const;
|
||||
|
||||
DecType ValueType(void) const;
|
||||
|
|
|
@ -696,17 +696,15 @@ Declaration* GlobalOptimizer::Analyze(Expression* exp, Declaration* procDec, uin
|
|||
Declaration* pdec = ldec->mBase->mParams;
|
||||
while (rex)
|
||||
{
|
||||
Expression* pex = rex->mType == EX_LIST ? rex->mLeft : rex;
|
||||
Expression *& pex(rex->mType == EX_LIST ? rex->mLeft : rex);
|
||||
|
||||
if (pdec)
|
||||
{
|
||||
if ((pdec->mFlags & DTF_FPARAM_UNUSED) && !pex->HasSideEffects())// && pex->mType != EX_CONSTANT)
|
||||
if ((pdec->mFlags & DTF_FPARAM_UNUSED) && !pex->HasSideEffects() && (pex->mType != EX_CONSTANT || !pex->mDecValue->IsNullConst()))
|
||||
{
|
||||
if (pdec->mBase->IsSimpleType())
|
||||
{
|
||||
pex->mType = EX_CONSTANT;
|
||||
pex->mLeft = nullptr;
|
||||
pex->mRight = nullptr;
|
||||
pex = new Expression(pex->mLocation, EX_CONSTANT);
|
||||
switch (pdec->mBase->mType)
|
||||
{
|
||||
case DT_TYPE_INTEGER:
|
||||
|
@ -720,8 +718,9 @@ Declaration* GlobalOptimizer::Analyze(Expression* exp, Declaration* procDec, uin
|
|||
case DT_TYPE_POINTER:
|
||||
case DT_TYPE_FUNCTION:
|
||||
pex->mDecValue = TheNullptrConstDeclaration;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
pex->mDecType = pdec->mBase;
|
||||
}
|
||||
}
|
||||
if (!(pdec->mFlags & DTF_FPARAM_UNUSED) && !(pdec->mOptFlags & OPTF_VAR_NOCONST))
|
||||
|
|
Loading…
Reference in New Issue