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

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 24239003: Fix range checks for typed data in native code and the optimizer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months 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 | Annotate | Revision Log
« no previous file with comments | « runtime/lib/typed_data.cc ('k') | tests/standalone/typed_data_test.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/flow_graph_optimizer.h" 5 #include "vm/flow_graph_optimizer.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/cha.h" 8 #include "vm/cha.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 2631 matching lines...) Expand 10 before | Expand all | Expand 10 after
2642 intptr_t element_size = FlowGraphCompiler::ElementSizeFor(receiver_cid); 2642 intptr_t element_size = FlowGraphCompiler::ElementSizeFor(receiver_cid);
2643 ConstantInstr* bytes_per_element = 2643 ConstantInstr* bytes_per_element =
2644 flow_graph()->GetConstant(Smi::Handle(Smi::New(element_size))); 2644 flow_graph()->GetConstant(Smi::Handle(Smi::New(element_size)));
2645 BinarySmiOpInstr* len_in_bytes = 2645 BinarySmiOpInstr* len_in_bytes =
2646 new BinarySmiOpInstr(Token::kMUL, 2646 new BinarySmiOpInstr(Token::kMUL,
2647 new Value(length), 2647 new Value(length),
2648 new Value(bytes_per_element), 2648 new Value(bytes_per_element),
2649 call->deopt_id()); 2649 call->deopt_id());
2650 InsertBefore(call, len_in_bytes, call->env(), Definition::kValue); 2650 InsertBefore(call, len_in_bytes, call->env(), Definition::kValue);
2651 2651
2652 // Check byte_index < len_in_bytes. 2652 ConstantInstr* length_adjustment =
2653 flow_graph()->GetConstant(Smi::Handle(Smi::New(
2654 FlowGraphCompiler::ElementSizeFor(view_cid) - 1)));
2655 // adjusted_length = len_in_bytes - (element_size - 1).
2656 BinarySmiOpInstr* adjusted_length =
2657 new BinarySmiOpInstr(Token::kSUB,
2658 new Value(len_in_bytes),
2659 new Value(length_adjustment),
2660 call->deopt_id());
2661 InsertBefore(call, adjusted_length, call->env(), Definition::kValue);
2662 // Check adjusted_length > 0.
2663 ConstantInstr* zero = flow_graph()->GetConstant(Smi::Handle(Smi::New(0)));
2653 InsertBefore(call, 2664 InsertBefore(call,
2654 new CheckArrayBoundInstr(new Value(len_in_bytes), 2665 new CheckArrayBoundInstr(new Value(adjusted_length),
2666 new Value(zero),
2667 call->deopt_id()),
2668 call->env(),
2669 Definition::kEffect);
2670 // Check 0 <= byte_index < adjusted_length.
2671 InsertBefore(call,
2672 new CheckArrayBoundInstr(new Value(adjusted_length),
2655 new Value(byte_index), 2673 new Value(byte_index),
2656 call->deopt_id()), 2674 call->deopt_id()),
2657 call->env(), 2675 call->env(),
2658 Definition::kEffect); 2676 Definition::kEffect);
2659 2677
2660 // Insert load of elements for external typed arrays. 2678 // Insert load of elements for external typed arrays.
2661 if (RawObject::IsExternalTypedDataClassId(receiver_cid)) { 2679 if (RawObject::IsExternalTypedDataClassId(receiver_cid)) {
2662 LoadUntaggedInstr* elements = 2680 LoadUntaggedInstr* elements =
2663 new LoadUntaggedInstr(new Value(*array), 2681 new LoadUntaggedInstr(new Value(*array),
2664 ExternalTypedData::data_offset()); 2682 ExternalTypedData::data_offset());
(...skipping 5006 matching lines...) Expand 10 before | Expand all | Expand 10 after
7671 } 7689 }
7672 7690
7673 // Insert materializations at environment uses. 7691 // Insert materializations at environment uses.
7674 for (intptr_t i = 0; i < exits.length(); i++) { 7692 for (intptr_t i = 0; i < exits.length(); i++) {
7675 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields); 7693 CreateMaterializationAt(exits[i], alloc, alloc->cls(), *fields);
7676 } 7694 }
7677 } 7695 }
7678 7696
7679 7697
7680 } // namespace dart 7698 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/typed_data.cc ('k') | tests/standalone/typed_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698