Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Unified Diff: runtime/vm/object.cc

Issue 1490853002: Correct overflow check; signed integer overflow is undefined (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index a0e5ccad6ab86b51695b00d14d19e32f8f042380..9e68eccf9c5d44b97966289bc9f8b489f47dd4fb 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -17293,24 +17293,13 @@ RawInteger* Integer::ArithmeticOp(Token::Kind operation,
const int64_t right_value = other.AsInt64Value();
switch (operation) {
case Token::kADD: {
- if (((left_value < 0) != (right_value < 0)) ||
- ((left_value + right_value) < 0) == (left_value < 0)) {
+ if (!Utils::WillAddOverflow(left_value, right_value)) {
return Integer::New(left_value + right_value, space);
}
break;
}
case Token::kSUB: {
- // TODO(srdjan): XCode 7 produces different code in -O0 than in -O2 for
- // following code when 'left_value - right_value' overflows into a
- // positive number (left negative, right positive):
- // if (((left_value < 0) == (right_value < 0)) ||
- // ((left_value - right_value) < 0) == (left_value < 0)) {
- //
- // Restructuring code using temporary variables is a workaround.
- const bool both_same_sign = (left_value < 0) == (right_value < 0);
- const bool result_same_sign_as_left =
- ((left_value - right_value) < 0) == (left_value < 0);
- if (both_same_sign || result_same_sign_as_left) {
+ if (!Utils::WillSubOverflow(left_value, right_value)) {
return Integer::New(left_value - right_value, space);
}
break;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698