From f89ed411cf5222a777fed1921ff6cda15a2f049b Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Mon, 16 Aug 2021 13:29:05 -0700 Subject: [PATCH] updates for usage issues: support for -uu, maybe/definitely distinctions --- src/script_opt/GenIDDefs.cc | 2 +- src/script_opt/ScriptOpt.cc | 8 ++++++-- .../btest/Baseline/core.parse-only-usage-issues/out | 3 ++- testing/btest/core/parse-only-usage-issues.zeek | 12 ++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/script_opt/GenIDDefs.cc b/src/script_opt/GenIDDefs.cc index bbfc2cd97a..842a65dd36 100644 --- a/src/script_opt/GenIDDefs.cc +++ b/src/script_opt/GenIDDefs.cc @@ -413,7 +413,7 @@ bool GenIDDefs::IsAggr(const Expr* e) const 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 ) return; diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 421eac50a8..fd6f061353 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -78,7 +78,6 @@ static bool optimize_AST(ScriptFunc* f, std::shared_ptr& pf, { pf = std::make_shared(f, body, true); - // RD_Decorate reduced_rds(pf, f, scope, body); GenIDDefs ID_defs(pf, f, scope, body); if ( reporter->Errors() > 0 ) @@ -153,6 +152,12 @@ static void optimize_func(ScriptFunc* f, std::shared_ptr pf, f->ReplaceBody(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 && ! optimize_AST(f, pf, rc, scope, body) ) { @@ -164,7 +169,6 @@ static void optimize_func(ScriptFunc* f, std::shared_ptr pf, pf = std::make_shared(f, body, true); // Compute its reaching definitions. - // RD_Decorate reduced_rds(pf, f, scope, body); GenIDDefs ID_defs(pf, f, scope, body); rc->SetReadyToOptimize(); diff --git a/testing/btest/Baseline/core.parse-only-usage-issues/out b/testing/btest/Baseline/core.parse-only-usage-issues/out index c9408ea498..04498d7d06 100644 --- a/testing/btest/Baseline/core.parse-only-usage-issues/out +++ b/testing/btest/Baseline/core.parse-only-usage-issues/out @@ -1,2 +1,3 @@ ### 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) diff --git a/testing/btest/core/parse-only-usage-issues.zeek b/testing/btest/core/parse-only-usage-issues.zeek index 551d8ce3b6..9255746cd9 100644 --- a/testing/btest/core/parse-only-usage-issues.zeek +++ b/testing/btest/core/parse-only-usage-issues.zeek @@ -1,6 +1,5 @@ -# Skip this test when using ZAM, as it will generate a hard error (since it's -# certain that the variable is used w/o initialization) rather than just -# a warning. +# Skip this test when using ZAM, as it will generate a hard error in addition +# to the warning. # @TEST-REQUIRES: test "${ZEEK_ZAM}" != "1" # # @TEST-DOC: ``zeek -a -u`` should detect usage issues without executing code @@ -10,5 +9,10 @@ event zeek_init() { local a: count; - print a; + local b: count; + + if ( a > 3 ) + b = 5; + + print a, b; }