From d7c9f155930fc6ac5012de28726cb382ff97190e Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Sat, 21 Sep 2024 12:49:29 +0200 Subject: [PATCH] Fix constant fold of byte right shift --- oscar64/InterCode.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/oscar64/InterCode.cpp b/oscar64/InterCode.cpp index bb0db2a..4458184 100644 --- a/oscar64/InterCode.cpp +++ b/oscar64/InterCode.cpp @@ -1201,25 +1201,11 @@ static int64 ConstantFolding(InterOperator oper, InterType type, int64 val1, int } break; case IA_SHL: - return val1 << val2; - break; + return ToTypedUnsigned(val1 << val2, type); case IA_SHR: - return (uint64)val1 >> (uint64)val2; - break; + return ToTypedUnsigned(val1, type) >> val2; case IA_SAR: - - switch (type) - { - case IT_INT8: - return int8(val1) >> val2; - case IT_INT16: - return int16(val1) >> val2; - case IT_INT32: - return int32(val1) >> val2; - default: - return val1 >> val2; - } - break; + return ToTypedSigned(val1, type) >> val2; case IA_CMPEQ: return ToTypedUnsigned(val1, type) == ToTypedUnsigned(val2, type) ? 1 : 0; break; @@ -1686,7 +1672,7 @@ static InterOperand OperandConstantFolding(InterOperator oper, InterOperand op1, break; case IA_SHL: dop.mType = op1.mType; - dop.mIntConst = op1.mIntConst << op2.mIntConst; + dop.mIntConst = ToTypedUnsigned(op1.mIntConst << op2.mIntConst, op1.mType); break; case IA_SHR: dop.mType = op1.mType; @@ -22238,7 +22224,7 @@ void InterCodeProcedure::Close(void) { GrowingTypeArray tstack(IT_NONE); - CheckFunc = !strcmp(mIdent->mString, "VLine"); + CheckFunc = !strcmp(mIdent->mString, "main"); CheckCase = false; mEntryBlock = mBlocks[0];