From ae15eca0ef55b5df037bed07a214e7c5a3494831 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 29 Oct 2023 20:00:38 +0100 Subject: [PATCH] Fix array to pointer cast in const initializer --- oscar64/Declaration.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 19ab071..e06286d 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -599,6 +599,19 @@ Expression* Expression::ConstantFold(Errors * errors, LinkerSection * dataSectio } } } + else if (mType == EX_TYPECAST && mLeft->mType == EX_VARIABLE) + { + if (mDecType->mType == DT_TYPE_POINTER && (mLeft->mDecValue->mFlags & (DTF_STATIC | DTF_GLOBAL)) && mLeft->mDecType->mType == DT_TYPE_ARRAY) + { + Expression* ex = new Expression(mLocation, EX_CONSTANT); + Declaration* dec = new Declaration(mLocation, DT_CONST_POINTER); + dec->mValue = mLeft; + dec->mBase = mDecType; + ex->mDecValue = dec; + ex->mDecType = mDecType; + return ex; + } + } else if (mType == EX_BINARY && mLeft->mType == EX_CONSTANT && mRight->mType == EX_CONSTANT) { if (mLeft->mDecValue->mType == DT_CONST_INTEGER && mRight->mDecValue->mType == DT_CONST_INTEGER)