diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2009-10-19 11:33:24 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2009-10-19 13:11:30 -0400 |
commit | 2e526dabcf4b15fb102e295b282df3af54d5c9d3 (patch) | |
tree | 026750014ab7bbbd046ac555ee44fb06d29b010d /elaborate.cxx | |
parent | a34babfa5246b1f8393c18fde450ec684f11bc21 (diff) | |
download | systemtap-steved-2e526dabcf4b15fb102e295b282df3af54d5c9d3.tar.gz systemtap-steved-2e526dabcf4b15fb102e295b282df3af54d5c9d3.tar.xz systemtap-steved-2e526dabcf4b15fb102e295b282df3af54d5c9d3.zip |
PR10799: warn on possibly uintended local-vs-global namespace collision
* elaborate.cxx (find_var): Take extra token parameter.
Look for cross-file global variable resolution, signal
a warning.
* testsuite/systemtap.examples/io/traceio2.stp: Fix it.
* testsuite/systemtap.syscall/sys.stp: Fix it.
* NEWS: Document it.
Diffstat (limited to 'elaborate.cxx')
-rw-r--r-- | elaborate.cxx | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/elaborate.cxx b/elaborate.cxx index 2446e4f8..c3f29603 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1711,7 +1711,7 @@ symresolution_info::visit_foreach_loop (foreach_loop* e) { if (!array->referent) { - vardecl* d = find_var (array->name, e->indexes.size ()); + vardecl* d = find_var (array->name, e->indexes.size (), array->tok); if (d) array->referent = d; else @@ -1760,7 +1760,7 @@ delete_statement_symresolution_info: if (e->referent) return; - vardecl* d = parent->find_var (e->name, -1); + vardecl* d = parent->find_var (e->name, -1, e->tok); if (d) e->referent = d; else @@ -1782,7 +1782,7 @@ symresolution_info::visit_symbol (symbol* e) if (e->referent) return; - vardecl* d = find_var (e->name, 0); + vardecl* d = find_var (e->name, 0, e->tok); if (d) e->referent = d; else @@ -1818,7 +1818,7 @@ symresolution_info::visit_arrayindex (arrayindex* e) if (array->referent) return; - vardecl* d = find_var (array->name, e->indexes.size ()); + vardecl* d = find_var (array->name, e->indexes.size (), array->tok); if (d) array->referent = d; else @@ -1877,7 +1877,7 @@ symresolution_info::visit_functioncall (functioncall* e) vardecl* -symresolution_info::find_var (const string& name, int arity) +symresolution_info::find_var (const string& name, int arity, const token* tok) { if (current_function || current_probe) { @@ -1912,6 +1912,16 @@ symresolution_info::find_var (const string& name, int arity) && session.globals[i]->compatible_arity(arity)) { session.globals[i]->set_arity (arity); + if (! session.suppress_warnings) + { + vardecl* v = session.globals[i]; + // clog << "resolved " << *tok << " to global " << *v->tok << endl; + if (v->tok->location.file != tok->location.file) + { + session.print_warning ("cross-file global variable reference to " + lex_cast (*v->tok) + " from", + tok); + } + } return session.globals[i]; } |