diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 2772d84..c1b1f35 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -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) diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 1c8ab25..b390d2c 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -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; diff --git a/oscar64/GlobalOptimizer.cpp b/oscar64/GlobalOptimizer.cpp index d934d35..1f7034f 100644 --- a/oscar64/GlobalOptimizer.cpp +++ b/oscar64/GlobalOptimizer.cpp @@ -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))