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

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

Issue 10280007: Check upper bounds of type arguments when allocating objects of a generic type (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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/vm/code_generator_x64.cc ('k') | runtime/vm/flow_graph_compiler_x64.cc » ('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) 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/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "vm/ast_printer.h" 7 #include "vm/ast_printer.h"
8 #include "vm/code_descriptors.h" 8 #include "vm/code_descriptors.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/flags.h" 10 #include "vm/flags.h"
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 Definition* EffectGraphVisitor::BuildObjectAllocation( 1618 Definition* EffectGraphVisitor::BuildObjectAllocation(
1619 ConstructorCallNode* node) { 1619 ConstructorCallNode* node) {
1620 const Class& cls = Class::ZoneHandle(node->constructor().owner()); 1620 const Class& cls = Class::ZoneHandle(node->constructor().owner());
1621 const bool requires_type_arguments = cls.HasTypeArguments(); 1621 const bool requires_type_arguments = cls.HasTypeArguments();
1622 1622
1623 ZoneGrowableArray<Value*>* allocate_arguments = 1623 ZoneGrowableArray<Value*>* allocate_arguments =
1624 new ZoneGrowableArray<Value*>(); 1624 new ZoneGrowableArray<Value*>();
1625 if (requires_type_arguments) { 1625 if (requires_type_arguments) {
1626 BuildConstructorTypeArguments(node, allocate_arguments); 1626 BuildConstructorTypeArguments(node, allocate_arguments);
1627 } 1627 }
1628 BindInstr* allocate = 1628 // In checked mode, if the type arguments are uninstantiated, they may need to
1629 new BindInstr(temp_index(), 1629 // be checked against declared bounds at run time.
1630 new AllocateObjectComp(node, 1630 Computation* allocate_comp = NULL;
1631 Error& malformed_error = Error::Handle();
1632 if (FLAG_enable_type_checks &&
1633 requires_type_arguments &&
1634 !node->type_arguments().IsNull() &&
1635 !node->type_arguments().IsInstantiated() &&
1636 !node->type_arguments().IsWithinBoundsOf(cls,
1637 node->type_arguments(),
1638 &malformed_error)) {
1639 // The uninstantiated type arguments cannot be verified to be within their
1640 // bounds at compile time, so verify them at runtime.
1641 // Although the type arguments may be uninstantiated at compile time, they
1642 // may represent the identity vector and may be replaced by the instantiated
1643 // type arguments of the instantiator at run time.
1644 allocate_comp = new AllocateObjectWithBoundsCheckComp(node,
1645 owner()->try_index(),
1646 allocate_arguments);
1647 } else {
1648 allocate_comp = new AllocateObjectComp(node,
1631 owner()->try_index(), 1649 owner()->try_index(),
1632 allocate_arguments)); 1650 allocate_arguments);
1651 }
1652 BindInstr* allocate = new BindInstr(temp_index(), allocate_comp);
1633 AddInstruction(allocate); 1653 AddInstruction(allocate);
1634 AllocateTempIndex(); 1654 AllocateTempIndex();
1635 return allocate; 1655 return allocate;
1636 } 1656 }
1637 1657
1638 1658
1639 void EffectGraphVisitor::BuildConstructorCall(ConstructorCallNode* node, 1659 void EffectGraphVisitor::BuildConstructorCall(ConstructorCallNode* node,
1640 Value* alloc_value) { 1660 Value* alloc_value) {
1641 BindInstr* ctor_arg = 1661 BindInstr* ctor_arg =
1642 new BindInstr(temp_index(), 1662 new BindInstr(temp_index(),
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 OS::Print("AllocateObject(%s", 2619 OS::Print("AllocateObject(%s",
2600 Class::Handle(comp->constructor().owner()).ToCString()); 2620 Class::Handle(comp->constructor().owner()).ToCString());
2601 for (intptr_t i = 0; i < comp->arguments().length(); i++) { 2621 for (intptr_t i = 0; i < comp->arguments().length(); i++) {
2602 OS::Print(", "); 2622 OS::Print(", ");
2603 comp->arguments()[i]->Accept(this); 2623 comp->arguments()[i]->Accept(this);
2604 } 2624 }
2605 OS::Print(")"); 2625 OS::Print(")");
2606 } 2626 }
2607 2627
2608 2628
2629 void FlowGraphPrinter::VisitAllocateObjectWithBoundsCheck(
2630 AllocateObjectWithBoundsCheckComp* comp) {
2631 OS::Print("AllocateObjectWithBoundsCheck(%s",
2632 Class::Handle(comp->constructor().owner()).ToCString());
2633 for (intptr_t i = 0; i < comp->arguments().length(); i++) {
2634 OS::Print(", ");
2635 comp->arguments()[i]->Accept(this);
2636 }
2637 OS::Print(")");
2638 }
2639
2640
2609 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) { 2641 void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) {
2610 OS::Print("CreateArray("); 2642 OS::Print("CreateArray(");
2611 for (int i = 0; i < comp->ElementCount(); ++i) { 2643 for (int i = 0; i < comp->ElementCount(); ++i) {
2612 if (i != 0) OS::Print(", "); 2644 if (i != 0) OS::Print(", ");
2613 comp->ElementAt(i)->Accept(this); 2645 comp->ElementAt(i)->Accept(this);
2614 } 2646 }
2615 OS::Print(")"); 2647 OS::Print(")");
2616 } 2648 }
2617 2649
2618 2650
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2896 char* chars = reinterpret_cast<char*>( 2928 char* chars = reinterpret_cast<char*>(
2897 Isolate::Current()->current_zone()->Allocate(len)); 2929 Isolate::Current()->current_zone()->Allocate(len));
2898 OS::SNPrint(chars, len, kFormat, function_name, reason); 2930 OS::SNPrint(chars, len, kFormat, function_name, reason);
2899 const Error& error = Error::Handle( 2931 const Error& error = Error::Handle(
2900 LanguageError::New(String::Handle(String::New(chars)))); 2932 LanguageError::New(String::Handle(String::New(chars))));
2901 Isolate::Current()->long_jump_base()->Jump(1, error); 2933 Isolate::Current()->long_jump_base()->Jump(1, error);
2902 } 2934 }
2903 2935
2904 2936
2905 } // namespace dart 2937 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator_x64.cc ('k') | runtime/vm/flow_graph_compiler_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698