updates for usage issues: support for -uu, maybe/definitely distinctions

This commit is contained in:
Vern Paxson 2021-08-16 13:29:05 -07:00
parent 6726eaa0a9
commit f89ed411cf
4 changed files with 17 additions and 8 deletions

View file

@ -413,7 +413,7 @@ bool GenIDDefs::IsAggr(const Expr* e) const
void GenIDDefs::CheckVarUsage(const Expr* e, const ID* id) void GenIDDefs::CheckVarUsage(const Expr* e, const ID* id)
{ {
if ( analysis_options.usage_issues == 0 || id->IsGlobal() || if ( analysis_options.usage_issues != 1 || id->IsGlobal() ||
suppress_usage > 0 ) suppress_usage > 0 )
return; return;

View file

@ -78,7 +78,6 @@ static bool optimize_AST(ScriptFunc* f, std::shared_ptr<ProfileFunc>& pf,
{ {
pf = std::make_shared<ProfileFunc>(f, body, true); pf = std::make_shared<ProfileFunc>(f, body, true);
// RD_Decorate reduced_rds(pf, f, scope, body);
GenIDDefs ID_defs(pf, f, scope, body); GenIDDefs ID_defs(pf, f, scope, body);
if ( reporter->Errors() > 0 ) if ( reporter->Errors() > 0 )
@ -153,6 +152,12 @@ static void optimize_func(ScriptFunc* f, std::shared_ptr<ProfileFunc> pf,
f->ReplaceBody(body, new_body); f->ReplaceBody(body, new_body);
body = new_body; body = new_body;
if ( analysis_options.usage_issues > 1 )
{
// Use the old-school approach for this.
RD_Decorate reduced_rds(pf, f, scope, body);
}
if ( analysis_options.optimize_AST && if ( analysis_options.optimize_AST &&
! optimize_AST(f, pf, rc, scope, body) ) ! optimize_AST(f, pf, rc, scope, body) )
{ {
@ -164,7 +169,6 @@ static void optimize_func(ScriptFunc* f, std::shared_ptr<ProfileFunc> pf,
pf = std::make_shared<ProfileFunc>(f, body, true); pf = std::make_shared<ProfileFunc>(f, body, true);
// Compute its reaching definitions. // Compute its reaching definitions.
// RD_Decorate reduced_rds(pf, f, scope, body);
GenIDDefs ID_defs(pf, f, scope, body); GenIDDefs ID_defs(pf, f, scope, body);
rc->SetReadyToOptimize(); rc->SetReadyToOptimize();

View file

@ -1,2 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
warning in <...>/parse-only-usage-issues.zeek, line 13: possibly used without definition (a) warning in <...>/parse-only-usage-issues.zeek, line 14: used without definition (a)
warning in <...>/parse-only-usage-issues.zeek, line 17: possibly used without definition (b)

View file

@ -1,6 +1,5 @@
# Skip this test when using ZAM, as it will generate a hard error (since it's # Skip this test when using ZAM, as it will generate a hard error in addition
# certain that the variable is used w/o initialization) rather than just # to the warning.
# a warning.
# @TEST-REQUIRES: test "${ZEEK_ZAM}" != "1" # @TEST-REQUIRES: test "${ZEEK_ZAM}" != "1"
# #
# @TEST-DOC: ``zeek -a -u`` should detect usage issues without executing code # @TEST-DOC: ``zeek -a -u`` should detect usage issues without executing code
@ -10,5 +9,10 @@
event zeek_init() event zeek_init()
{ {
local a: count; local a: count;
print a; local b: count;
if ( a > 3 )
b = 5;
print a, b;
} }