Skip to content

Commit

Permalink
[vm/compiler] Avoid undefined behavior in range analysis shift operation
Browse files Browse the repository at this point in the history
Change-Id: I232f86b58c71746ea6ccb479f28d812c29027938
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127141
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
  • Loading branch information
mkustermann authored and commit-bot@chromium.org committed Dec 4, 2019
1 parent 413867d commit a9c7722
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions runtime/vm/compiler/backend/range_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1814,10 +1814,12 @@ RangeBoundary RangeBoundary::Shl(const RangeBoundary& value_boundary,
int64_t limit = 64 - shift_count;
int64_t value = value_boundary.ConstantValue();

if ((value == 0) || (shift_count == 0) ||
((limit > 0) && Utils::IsInt(static_cast<int>(limit), value))) {
if (value == 0) {
return RangeBoundary(0);
} else if (shift_count == 0 ||
(limit > 0 && Utils::IsInt(static_cast<int>(limit), value))) {
// Result stays in 64 bit range.
int64_t result = value << shift_count;
const int64_t result = value << shift_count;
return RangeBoundary(result);
}

Expand Down

0 comments on commit a9c7722

Please sign in to comment.