From 5f8797b4bee4c072889a0e2c5ca1a13475302c08 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sun, 10 Jul 2022 10:07:33 +0200 Subject: [PATCH] Fix regression with open array index by byte generated by a subtract --- oscar64/InterCode.cpp | 2 +- oscar64/NativeCodeGenerator.cpp | 43 ++++++++++++++++++++++++++++---- oscar64/oscar64.cpp | 2 +- oscar64/oscar64.rc | 8 +++--- oscar64setup/oscar64setup.vdproj | 6 ++--- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index e20f4f3..8e665cf 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -5302,7 +5302,7 @@ void InterCodeBasicBlock::UpdateLocalIntegerRangeSets(const GrowingVariableArray case IA_EXT8TO16U: vr = ins->mSrc[0].mRange; - if (vr.mMaxState != IntegerValueRange::S_BOUND || vr.mMaxValue < 0 || vr.mMaxValue > 255) + if (vr.mMaxState != IntegerValueRange::S_BOUND || vr.mMaxValue < 0 || vr.mMaxValue > 255 || vr.mMinValue < 0) { vr.mMaxState = IntegerValueRange::S_BOUND; vr.mMaxValue = 255; diff --git a/oscar64/NativeCodeGenerator.cpp b/oscar64/NativeCodeGenerator.cpp index 1369624..157b932 100644 --- a/oscar64/NativeCodeGenerator.cpp +++ b/oscar64/NativeCodeGenerator.cpp @@ -7829,14 +7829,20 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p if (sins0) { insl = NativeCodeInstruction(ASMIT_SBC, ASMIM_ZERO_PAGE, BC_REG_WORK + 0); - insh = NativeCodeInstruction(ASMIT_SBC, ASMIM_ZERO_PAGE, BC_REG_WORK + 1); + if (ins->mDst.IsUByte()) + insh = NativeCodeInstruction(ASMIT_AND, ASMIM_IMMEDIATE, 0); + else + insh = NativeCodeInstruction(ASMIT_SBC, ASMIM_ZERO_PAGE, BC_REG_WORK + 1); LoadValueToReg(proc, sins0, BC_REG_WORK, nullptr, nullptr); } else { insl = NativeCodeInstruction(ASMIT_SBC, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[0].mTemp]); - insh = NativeCodeInstruction(ASMIT_SBC, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[0].mTemp] + 1); + if (ins->mDst.IsUByte()) + insh = NativeCodeInstruction(ASMIT_AND, ASMIM_IMMEDIATE, 0); + else + insh = NativeCodeInstruction(ASMIT_SBC, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[0].mTemp] + 1); } if (sins1) @@ -7851,9 +7857,17 @@ NativeCodeBasicBlock* NativeCodeBasicBlock::BinaryOperator(InterCodeProcedure* p mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg)); if (InterTypeSize[ins->mDst.mType] > 1) { - mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[1].mTemp] + 1)); - mIns.Push(insh); - mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1)); + if (ins->mDst.IsUByte()) + { + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_IMMEDIATE, 0)); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1)); + } + else + { + mIns.Push(NativeCodeInstruction(ASMIT_LDA, ASMIM_ZERO_PAGE, BC_REG_TMP + proc->mTempOffset[ins->mSrc[1].mTemp] + 1)); + mIns.Push(insh); + mIns.Push(NativeCodeInstruction(ASMIT_STA, ASMIM_ZERO_PAGE, treg + 1)); + } } } } @@ -13929,7 +13943,16 @@ bool NativeCodeBasicBlock::CheckSingleUseGlobalLoad(const NativeCodeBasicBlock* mPatched = true; if (!mEntryRequiredRegs[reg]) + { + if (mExitRequiredRegs[reg]) + { + if (mTrueJump && !mTrueJump->CheckPatchFail(block, reg)) + return false; + if (mFalseJump && !mFalseJump->CheckPatchFail(block, reg)) + return false; + } return true; + } assert(mNumEntries == mEntryBlocks.Size()); @@ -13976,7 +13999,17 @@ bool NativeCodeBasicBlock::CheckSingleUseGlobalLoad(const NativeCodeBasicBlock* } } else + { + if (mExitRequiredRegs[reg]) + { + if (mTrueJump && !mTrueJump->CheckPatchFail(block, reg)) + return false; + if (mFalseJump && !mFalseJump->CheckPatchFail(block, reg)) + return false; + } + return true; + } } else if (ins.mType == ASMIT_JSR) { diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index c182380..72e2d24 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -74,7 +74,7 @@ int main2(int argc, const char** argv) #else strcpy(strProductName, "oscar64"); - strcpy(strProductVersion, "1.7.142"); + strcpy(strProductVersion, "1.7.143"); #ifdef __APPLE__ uint32_t length = sizeof(basePath); diff --git a/oscar64/oscar64.rc b/oscar64/oscar64.rc index 639849e..2bcf665 100644 --- a/oscar64/oscar64.rc +++ b/oscar64/oscar64.rc @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,7,142,0 - PRODUCTVERSION 1,7,142,0 + FILEVERSION 1,7,143,0 + PRODUCTVERSION 1,7,143,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -43,12 +43,12 @@ BEGIN BEGIN VALUE "CompanyName", "oscar64" VALUE "FileDescription", "oscar64 compiler" - VALUE "FileVersion", "1.7.142.0" + VALUE "FileVersion", "1.7.143.0" VALUE "InternalName", "oscar64.exe" VALUE "LegalCopyright", "Copyright (C) 2021" VALUE "OriginalFilename", "oscar64.exe" VALUE "ProductName", "oscar64" - VALUE "ProductVersion", "1.7.142.0" + VALUE "ProductVersion", "1.7.143.0" END END BLOCK "VarFileInfo" diff --git a/oscar64setup/oscar64setup.vdproj b/oscar64setup/oscar64setup.vdproj index c9a98c6..85817c2 100644 --- a/oscar64setup/oscar64setup.vdproj +++ b/oscar64setup/oscar64setup.vdproj @@ -4153,15 +4153,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:oscar64" - "ProductCode" = "8:{54C9EB87-4154-49FD-B146-2408492EDE3B}" - "PackageCode" = "8:{A90AA9BF-452A-4C37-B592-CAF52893124A}" + "ProductCode" = "8:{18D1362C-EAD7-45F4-85FD-9D9963D9795D}" + "PackageCode" = "8:{561C0763-7D5B-4666-9DE0-2326AF7DA4CF}" "UpgradeCode" = "8:{9AB61EFF-ACAC-4079-9950-8D96615CD4EF}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:1.7.142" + "ProductVersion" = "8:1.7.143" "Manufacturer" = "8:oscar64" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:"