summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2010-05-14 13:34:43 -0700
committerIan Romanick <ian.d.romanick@intel.com>2010-05-17 12:03:13 -0700
commit458d5c61ef9740cf589807c85d95e9ea4d04c03b (patch)
tree03884987858507cd93da0c8d73c83cb319d1f752
parent671e4f6321ce173b97fdbb459778df0bc9625b9b (diff)
Make visit_list_elements safe against node removals
-rw-r--r--ir_hv_accept.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/ir_hv_accept.cpp b/ir_hv_accept.cpp
index 7249bdb49a..43422e84aa 100644
--- a/ir_hv_accept.cpp
+++ b/ir_hv_accept.cpp
@@ -31,11 +31,20 @@
/**
* Process a list of nodes using a hierarchical vistor
+ *
+ * \warning
+ * This function will operate correctly if a node being processed is removed
+ * from list. However, if nodes are added to the list after the node being
+ * processed, some of the added noded may not be processed.
*/
static ir_visitor_status
visit_list_elements(ir_hierarchical_visitor *v, exec_list *l)
{
- foreach_list (n, l) {
+ exec_node *next;
+
+ for (exec_node *n = l->head; n->next != NULL; n = next) {
+ next = n->next;
+
ir_instruction *const ir = (ir_instruction *) n;
ir_visitor_status s = ir->accept(v);
@@ -112,9 +121,12 @@ ir_function_signature::accept(ir_hierarchical_visitor *v)
ir_visitor_status
ir_function::accept(ir_hierarchical_visitor *v)
{
- /* FINISHME: Do we want to walk into functions? */
- (void) v;
- return visit_continue;
+ ir_visitor_status s = v->visit_enter(this);
+ if (s != visit_continue)
+ return (s == visit_continue_with_parent) ? visit_continue : s;
+
+ s = visit_list_elements(v, &this->signatures);
+ return (s == visit_stop) ? s : v->visit_leave(this);
}