Commit 902fe5f0 authored by Milad Farazmand's avatar Milad Farazmand Committed by Commit Bot

s390: [simulator] Avoid negating if reg value overflows

Negating 1 << 31 as a signed integer overflows and
causes undefined behaviour hence SetS390OverflowCode
may never get set.

Change-Id: I4a479f0d3c71eaaa58ae0925d744e7779ecd833b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2031861Reviewed-by: 's avatarJoran Siu <joransiu@ca.ibm.com>
Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#66061}
parent 75f66c50
...@@ -4380,13 +4380,14 @@ EVALUATE(LPR) { ...@@ -4380,13 +4380,14 @@ EVALUATE(LPR) {
// Load Positive (32) // Load Positive (32)
DECODE_RR_INSTRUCTION(r1, r2); DECODE_RR_INSTRUCTION(r1, r2);
int32_t r2_val = get_low_register<int32_t>(r2); int32_t r2_val = get_low_register<int32_t>(r2);
// If negative, then negate it.
r2_val = (r2_val < 0) ? -r2_val : r2_val;
set_low_register(r1, r2_val);
SetS390ConditionCode<int32_t>(r2_val, 0); SetS390ConditionCode<int32_t>(r2_val, 0);
if (r2_val == (static_cast<int32_t>(1) << 31)) { if (r2_val == (static_cast<int32_t>(1) << 31)) {
SetS390OverflowCode(true); SetS390OverflowCode(true);
} else {
// If negative and not overflowing, then negate it.
r2_val = (r2_val < 0) ? -r2_val : r2_val;
} }
set_low_register(r1, r2_val);
return length; 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