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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 17275 matching lines...) Expand 10 before | Expand all | Expand 10 after
17286 } 17286 }
17287 default: 17287 default:
17288 UNIMPLEMENTED(); 17288 UNIMPLEMENTED();
17289 } 17289 }
17290 } 17290 }
17291 if (!IsBigint() && !other.IsBigint()) { 17291 if (!IsBigint() && !other.IsBigint()) {
17292 const int64_t left_value = AsInt64Value(); 17292 const int64_t left_value = AsInt64Value();
17293 const int64_t right_value = other.AsInt64Value(); 17293 const int64_t right_value = other.AsInt64Value();
17294 switch (operation) { 17294 switch (operation) {
17295 case Token::kADD: { 17295 case Token::kADD: {
17296 if (((left_value < 0) != (right_value < 0)) || 17296 if (!Utils::WillAddOverflow(left_value, right_value)) {
17297 ((left_value + right_value) < 0) == (left_value < 0)) {
17298 return Integer::New(left_value + right_value, space); 17297 return Integer::New(left_value + right_value, space);
17299 } 17298 }
17300 break; 17299 break;
17301 } 17300 }
17302 case Token::kSUB: { 17301 case Token::kSUB: {
17303 // TODO(srdjan): XCode 7 produces different code in -O0 than in -O2 for 17302 if (!Utils::WillSubOverflow(left_value, right_value)) {
17304 // following code when 'left_value - right_value' overflows into a
17305 // positive number (left negative, right positive):
17306 // if (((left_value < 0) == (right_value < 0)) ||
17307 // ((left_value - right_value) < 0) == (left_value < 0)) {
17308 //
17309 // Restructuring code using temporary variables is a workaround.
17310 const bool both_same_sign = (left_value < 0) == (right_value < 0);
17311 const bool result_same_sign_as_left =
17312 ((left_value - right_value) < 0) == (left_value < 0);
17313 if (both_same_sign || result_same_sign_as_left) {
17314 return Integer::New(left_value - right_value, space); 17303 return Integer::New(left_value - right_value, space);
17315 } 17304 }
17316 break; 17305 break;
17317 } 17306 }
17318 case Token::kMUL: { 17307 case Token::kMUL: {
17319 if ((Utils::HighestBit(left_value) + 17308 if ((Utils::HighestBit(left_value) +
17320 Utils::HighestBit(right_value)) < 62) { 17309 Utils::HighestBit(right_value)) < 62) {
17321 return Integer::New(left_value * right_value, space); 17310 return Integer::New(left_value * right_value, space);
17322 } 17311 }
17323 break; 17312 break;
(...skipping 4598 matching lines...) Expand 10 before | Expand all | Expand 10 after
21922 return tag_label.ToCString(); 21911 return tag_label.ToCString();
21923 } 21912 }
21924 21913
21925 21914
21926 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21915 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21927 Instance::PrintJSONImpl(stream, ref); 21916 Instance::PrintJSONImpl(stream, ref);
21928 } 21917 }
21929 21918
21930 21919
21931 } // namespace dart 21920 } // namespace dart
OLDNEW
« 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