Commit b701dfc1 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: I91379a53752de322cee4541cf44fb65338a614e6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2081335Reviewed-by: 's avatarJunliang Yan <jyan@ca.ibm.com>
Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#66540}
parent 40406eb6
......@@ -7744,12 +7744,14 @@ EVALUATE(LPGR) {
// Load Positive (32)
DECODE_RRE_INSTRUCTION(r1, r2);
int64_t r2_val = get_register(r2);
r2_val = (r2_val < 0) ? -r2_val : r2_val; // If negative, then negate it.
set_register(r1, r2_val);
SetS390ConditionCode<int64_t>(r2_val, 0);
if (r2_val == (static_cast<int64_t>(1) << 63)) {
SetS390OverflowCode(true);
} else {
// If negative and not overflowing, then negate it.
r2_val = (r2_val < 0) ? -r2_val : r2_val;
}
set_register(r1, r2_val);
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