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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_builder.cc
===================================================================
--- runtime/vm/flow_graph_builder.cc (revision 7210)
+++ runtime/vm/flow_graph_builder.cc (working copy)
@@ -1625,11 +1625,31 @@
if (requires_type_arguments) {
BuildConstructorTypeArguments(node, allocate_arguments);
}
- BindInstr* allocate =
- new BindInstr(temp_index(),
- new AllocateObjectComp(node,
+ // In checked mode, if the type arguments are uninstantiated, they may need to
+ // be checked against declared bounds at run time.
+ Computation* allocate_comp = NULL;
+ Error& malformed_error = Error::Handle();
+ if (FLAG_enable_type_checks &&
+ requires_type_arguments &&
+ !node->type_arguments().IsNull() &&
+ !node->type_arguments().IsInstantiated() &&
+ !node->type_arguments().IsWithinBoundsOf(cls,
+ node->type_arguments(),
+ &malformed_error)) {
+ // The uninstantiated type arguments cannot be verified to be within their
+ // bounds at compile time, so verify them at runtime.
+ // Although the type arguments may be uninstantiated at compile time, they
+ // may represent the identity vector and may be replaced by the instantiated
+ // type arguments of the instantiator at run time.
+ allocate_comp = new AllocateObjectWithBoundsCheckComp(node,
+ owner()->try_index(),
+ allocate_arguments);
+ } else {
+ allocate_comp = new AllocateObjectComp(node,
owner()->try_index(),
- allocate_arguments));
+ allocate_arguments);
+ }
+ BindInstr* allocate = new BindInstr(temp_index(), allocate_comp);
AddInstruction(allocate);
AllocateTempIndex();
return allocate;
@@ -2606,6 +2626,18 @@
}
+void FlowGraphPrinter::VisitAllocateObjectWithBoundsCheck(
+ AllocateObjectWithBoundsCheckComp* comp) {
+ OS::Print("AllocateObjectWithBoundsCheck(%s",
+ Class::Handle(comp->constructor().owner()).ToCString());
+ for (intptr_t i = 0; i < comp->arguments().length(); i++) {
+ OS::Print(", ");
+ comp->arguments()[i]->Accept(this);
+ }
+ OS::Print(")");
+}
+
+
void FlowGraphPrinter::VisitCreateArray(CreateArrayComp* comp) {
OS::Print("CreateArray(");
for (int i = 0; i < comp->ElementCount(); ++i) {
« 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