Commit 4d6df11f authored by bjaideep's avatar bjaideep Committed by Commit bot

s390x: Fix the logic to detect INT_MIN in simulator

Converting INT_MIN to positive should cause overflow,
which was not being captured. Fixed the logic to detect
if value is equal to INT_MIN and set the overflow code
accordingly.

R=joransiu@ca.ibm.com, jyan@ca.ibm.com, michael_dawson@ca.ibm.com, mbrandy@us.ibm.com

BUG=
LOG=N

Review-Url: https://codereview.chromium.org/2446113013
Cr-Commit-Position: refs/heads/master@{#40631}
parent c29c6a29
......@@ -6504,7 +6504,6 @@ EVALUATE(LCR) {
DCHECK_OPCODE(LCR);
DECODE_RR_INSTRUCTION(r1, r2);
int32_t r2_val = get_low_register<int32_t>(r2);
int32_t original_r2_val = r2_val;
r2_val = ~r2_val;
r2_val = r2_val + 1;
set_low_register(r1, r2_val);
......@@ -6513,7 +6512,7 @@ EVALUATE(LCR) {
// Cannot do int comparison due to GCC 4.8 bug on x86.
// Detect INT_MIN alternatively, as it is the only value where both
// original and result are negative due to overflow.
if (r2_val < 0 && original_r2_val < 0) {
if (r2_val == (static_cast<int32_t>(1) << 31)) {
SetS390OverflowCode(true);
}
return length;
......@@ -9837,7 +9836,7 @@ EVALUATE(LCGR) {
set_register(r1, r2_val);
SetS390ConditionCode<int64_t>(r2_val, 0);
// if the input is INT_MIN, loading its compliment would be overflowing
if (r2_val < 0 && (r2_val + 1) > 0) {
if (r2_val == (static_cast<int64_t>(1) << 63)) {
SetS390OverflowCode(true);
}
return length;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment