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

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

Issue 17491003: Fix a bug in graph construction for for loops. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | « no previous file | tests/language/for_test.dart » ('j') | tests/language/for_test.dart » ('J')
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 "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/bit_vector.h" 9 #include "vm/bit_vector.h"
10 #include "vm/code_descriptors.h" 10 #include "vm/code_descriptors.h"
(...skipping 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 1704
1705 owner()->IncrementLoopDepth(); 1705 owner()->IncrementLoopDepth();
1706 // Compose body to set any jump labels. 1706 // Compose body to set any jump labels.
1707 EffectGraphVisitor for_body(owner(), temp_index()); 1707 EffectGraphVisitor for_body(owner(), temp_index());
1708 node->body()->Visit(&for_body); 1708 node->body()->Visit(&for_body);
1709 1709
1710 EffectGraphVisitor for_increment(owner(), temp_index()); 1710 EffectGraphVisitor for_increment(owner(), temp_index());
1711 node->increment()->Visit(&for_increment); 1711 node->increment()->Visit(&for_increment);
1712 1712
1713 // Join the loop body and increment and then tie the loop. 1713 // Join the loop body and increment and then tie the loop.
1714 JoinEntryInstr* join = node->label()->join_for_continue(); 1714 JoinEntryInstr* continue_join = node->label()->join_for_continue();
1715 if ((join != NULL) || for_body.is_open()) { 1715 if ((continue_join != NULL) || for_body.is_open()) {
1716 JoinEntryInstr* loop_start = 1716 JoinEntryInstr* loop_entry =
1717 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index()); 1717 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index());
1718 if (join != NULL) { 1718 if (continue_join != NULL) {
1719 if (for_body.is_open()) for_body.Goto(join); 1719 if (for_body.is_open()) for_body.Goto(continue_join);
1720 AppendFragment(join, for_increment); 1720 Instruction* current = AppendFragment(continue_join, for_increment);
1721 for_increment.Goto(loop_start); 1721 current->Goto(loop_entry);
Kevin Millikin (Google) 2013/06/20 09:44:24 The bug is in the order of side effects here. If
1722 } else { 1722 } else {
1723 for_body.Append(for_increment); 1723 for_body.Append(for_increment);
1724 for_body.Goto(loop_start); 1724 for_body.Goto(loop_entry);
1725 } 1725 }
1726 Goto(loop_start); 1726 Goto(loop_entry);
1727 exit_ = loop_start; 1727 exit_ = loop_entry;
1728 AddInstruction( 1728 AddInstruction(
1729 new CheckStackOverflowInstr(node->token_pos(), owner()->loop_depth())); 1729 new CheckStackOverflowInstr(node->token_pos(), owner()->loop_depth()));
1730 } 1730 }
1731 1731
1732 if (node->condition() == NULL) { 1732 if (node->condition() == NULL) {
1733 // Endless loop, no test. 1733 // Endless loop, no test.
1734 JoinEntryInstr* body_entry = 1734 Append(for_body);
1735 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index()); 1735 exit_ = node->label()->join_for_break(); // May be NULL.
1736 AppendFragment(body_entry, for_body);
1737 Goto(body_entry);
1738 if (node->label()->join_for_break() != NULL) {
1739 // Control flow of ForLoop continues into join_for_break.
1740 exit_ = node->label()->join_for_break();
1741 }
1742 } else { 1736 } else {
1743 TestGraphVisitor for_test(owner(), 1737 TestGraphVisitor for_test(owner(),
1744 temp_index(), 1738 temp_index(),
1745 node->condition()->token_pos()); 1739 node->condition()->token_pos());
1746 node->condition()->Visit(&for_test); 1740 node->condition()->Visit(&for_test);
1747 Append(for_test); 1741 Append(for_test);
1748 1742
1749 BlockEntryInstr* body_entry = for_test.CreateTrueSuccessor(); 1743 BlockEntryInstr* body_entry = for_test.CreateTrueSuccessor();
1750 AppendFragment(body_entry, for_body); 1744 AppendFragment(body_entry, for_body);
1751 1745
(...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after
3511 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; 3505 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1;
3512 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 3506 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
3513 OS::SNPrint(chars, len, kFormat, function_name, reason); 3507 OS::SNPrint(chars, len, kFormat, function_name, reason);
3514 const Error& error = Error::Handle( 3508 const Error& error = Error::Handle(
3515 LanguageError::New(String::Handle(String::New(chars)))); 3509 LanguageError::New(String::Handle(String::New(chars))));
3516 Isolate::Current()->long_jump_base()->Jump(1, error); 3510 Isolate::Current()->long_jump_base()->Jump(1, error);
3517 } 3511 }
3518 3512
3519 3513
3520 } // namespace dart 3514 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/for_test.dart » ('j') | tests/language/for_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698