From c8befeeab0b8e06d1cc1d1aa295ee67c38d23eee Mon Sep 17 00:00:00 2001
From: clc5q <clc5q@git.zephyr-software.com>
Date: Fri, 25 Sep 2015 00:17:35 +0000
Subject: [PATCH] Bug fix: Retain original byte width for normalized stack
 operands.

Former-commit-id: 49e1dbbf61159acd2919f55c0198b38cb29493e9
---
 src/base/SMPInstr.cpp                                        | 5 +++++
 .../trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/base/SMPInstr.cpp b/src/base/SMPInstr.cpp
index 33d0030f..7b57dd24 100644
--- a/src/base/SMPInstr.cpp
+++ b/src/base/SMPInstr.cpp
@@ -4607,6 +4607,7 @@ bool SMPInstr::MDComputeNormalizedDataFlowOp(bool UseFP, STARS_sval_t FPDelta, S
 			// Now, we simply convert the memory operand from EBP to ESP and replace the SignedOffset with the
 			//  NormalizedDelta just computed.
 			DefOp->SetReg(MD_STACK_POINTER_REG);
+			DefOp->SetByteWidth(OldOp->GetByteWidth()); // undo possible width change in SetReg()
 			this->SetFPNormalizedToSP();
 			// Add the stack pointer to the USE set for the instruction.
 			this->MDAddRegUse(MD_STACK_POINTER_REG, false);
@@ -4869,6 +4870,7 @@ void SMPInstr::MDGetUnnormalizedOp(STARSOpndTypePtr &NormOp) {
 	bool UseFP = this->GetBlock()->GetFunc()->UsesFramePointer();
 	if (this->AreDefsNormalized() && (0 != this->GetStackPtrOffset()) && MDIsStackAccessOpnd(NormOp, UseFP)) {
 		if (this->HasFPNormalizedToSP()) {
+			size_t NormOpByteWidth = NormOp->GetByteWidth();
 			// Need to convert NormOp back to frame-pointer-relative address.
 			if (NormOp->HasSIBByte()) {
 				// Convert base register from stack pointer back to frame pointer.
@@ -4877,6 +4879,7 @@ void SMPInstr::MDGetUnnormalizedOp(STARSOpndTypePtr &NormOp) {
 			}
 			else {
 				NormOp->SetReg(MD_FRAME_POINTER_REG);
+				NormOp->SetByteWidth(NormOpByteWidth); // undo possible width change in SetReg()
 			}
 			SignedOffset = (STARS_sval_t) NormOp->GetAddr();
 			SignedOffset -= this->GetBlock()->GetFunc()->GetFramePtrStackDelta();
@@ -14059,9 +14062,11 @@ bool SMPInstr::BuildMultiplyDivideRTL(SMPoperator BinaryOp) {
 			SMPRegTransfer *EDXRightRT = new SMPRegTransfer;
 			EDXRightRT->SetParentInst(this);
 			STARSOpndTypePtr EDXOp = TempRT->GetLeftOperand()->clone();
+			size_t SourceByteWidth = EDXOp->GetByteWidth();
 			EDXRT->SetOperator(SMP_ASSIGN);
 			assert(EDXOp->MatchesReg(STARS_x86_R_ax));
 			EDXOp->SetReg(STARS_x86_R_dx);
+			EDXOp->SetByteWidth(SourceByteWidth); // undo possible width change in SetReg()
 			EDXRT->SetLeftOperand(EDXOp);
 			STARSOpndTypePtr SourceOp = RightRT->GetLeftOperand();
 			if ((STARS_NN_div == this->GetIDAOpcode()) || (STARS_NN_idiv == this->GetIDAOpcode())) {
diff --git a/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id b/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id
index 1f3b5cd7..888a0456 100644
--- a/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id
+++ b/tests/commit/trimmed-sorted-save-busybox.psexe.annot.REMOVED.git-id
@@ -1 +1 @@
-5ed023069117f30d8e40a0cd1e96c1918b2059cc
\ No newline at end of file
+cc0231bd87f595a3cbb8158cd581363bb6e25cff
\ No newline at end of file
-- 
GitLab