diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2008-05-20 17:34:07 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2008-05-20 17:34:07 -0400 |
commit | 27d24ae2a4beddefc1aace0baf25f17ff92e22eb (patch) | |
tree | ec3b5dfaaff82dc6aa53f8b4b484bba5b103878c /staptree.cxx | |
parent | d15495ebff9e91135ae0923f4a36b2d2538bab54 (diff) | |
download | systemtap-steved-27d24ae2a4beddefc1aace0baf25f17ff92e22eb.tar.gz systemtap-steved-27d24ae2a4beddefc1aace0baf25f17ff92e22eb.tar.xz systemtap-steved-27d24ae2a4beddefc1aace0baf25f17ff92e22eb.zip |
PR6538: warn about read-only variables
Diffstat (limited to 'staptree.cxx')
-rw-r--r-- | staptree.cxx | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/staptree.cxx b/staptree.cxx index 02a6c8dc..b5cbd5c9 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -1713,6 +1713,10 @@ varuse_collecting_visitor::visit_symbol (symbol *e) if (e->referent == 0) throw semantic_error ("symbol without referent", e->tok); + // handle initialized globals + if (e->referent->init) + written.insert (e->referent); + if (current_lvalue == e || current_lrvalue == e) { written.insert (e->referent); @@ -1789,10 +1793,19 @@ varuse_collecting_visitor::visit_post_crement (post_crement *e) void varuse_collecting_visitor::visit_foreach_loop (foreach_loop* s) { - functioncall_traversing_visitor::visit_foreach_loop (s); + // NB: we duplicate so don't bother call + // functioncall_traversing_visitor::visit_foreach_loop (s); + + symbol *array = NULL; + hist_op *hist = NULL; + classify_indexable (s->base, array, hist); + if (array) + array->visit(this); + else + hist->visit(this); + // If the collection is sorted, imply a "write" access to the - // array in addition to the "read" one already noted in the - // base class call above. + // array in addition to the "read" one already noted above. if (s->sort_direction) { symbol *array = NULL; @@ -1801,6 +1814,20 @@ varuse_collecting_visitor::visit_foreach_loop (foreach_loop* s) if (array) this->written.insert (array->referent); // XXX: Can hist_op iterations be sorted? } + + // NB: don't forget to visit the index expressions, which are lvalues. + for (unsigned i=0; i<s->indexes.size(); i++) + { + expression* last_lvalue = current_lvalue; + current_lvalue = s->indexes[i]; // leave a mark for ::visit_symbol + s->indexes[i]->visit (this); + current_lvalue = last_lvalue; + } + + if (s->limit) + s->limit->visit (this); + + s->block->visit (this); } |