From da9b8f2a42f43e13260e3e4fb9b09da5b820eca3 Mon Sep 17 00:00:00 2001 From: drmortalwombat Date: Thu, 31 Aug 2023 14:13:43 +0200 Subject: [PATCH] Fix return of const array as pointer --- oscar64/InterCodeGenerator.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 16aafc4..2622fd3 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -3733,7 +3733,14 @@ InterCodeGenerator::ExValue InterCodeGenerator::TranslateExpression(Declaration* { vr = TranslateExpression(procType, proc, block, exp->mLeft, destack, breakBlock, continueBlock, inlineMapper); - vr = Dereference(proc, exp, block, vr); + if (procType->mBase->mType == DT_TYPE_POINTER && (vr.mType->mType == DT_TYPE_ARRAY || vr.mType->mType == DT_TYPE_FUNCTION)) + { + vr = Dereference(proc, exp, block, vr, 1); + vr.mReference = 0; + vr.mType = procType->mBase; + } + else + vr = Dereference(proc, exp, block, vr); if (!procType->mBase || procType->mBase->mType == DT_TYPE_VOID) mErrors->Error(exp->mLocation, EERR_INVALID_RETURN, "Function has void return type"); @@ -4725,7 +4732,7 @@ InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE, dec->mAlignment)); #if 0 - if (proc->mIdent && !strcmp(proc->mIdent->mString, "dividers")) + if (proc->mIdent && !strcmp(proc->mIdent->mString, "test")) exp->Dump(0); #endif #if 0