diff --git a/src/script_opt/FuncInfo.cc b/src/script_opt/FuncInfo.cc index e27dc8282c..6b89e4c3a6 100644 --- a/src/script_opt/FuncInfo.cc +++ b/src/script_opt/FuncInfo.cc @@ -550,22 +550,23 @@ static std::unordered_map func_attrs = { // Some of these have side effects that could be checked for in a specific // context, but the gains from doing so likely aren't worth the complexity. -bool is_special_script_func(std::string func_name) { +bool is_special_script_func(const std::string& func_name) { auto f_attr = func_attrs.find(func_name); return f_attr != func_attrs.end() && (f_attr->second & ATTR_SPECIAL_SCRIPT_FUNC) != 0; } -bool is_idempotent(std::string func_name) { +bool is_idempotent(const std::string& func_name) { auto f_attr = func_attrs.find(func_name); return f_attr != func_attrs.end() && (f_attr->second & ATTR_IDEMPOTENT) != 0; } -bool has_no_script_side_effects(std::string func_name) { +bool has_script_side_effects(const std::string& func_name) { auto f_attr = func_attrs.find(func_name); if ( f_attr == func_attrs.end() ) - return false; + // We don't know about it, so be conservative. + return true; - return (f_attr->second & (ATTR_NO_SCRIPT_SIDE_EFFECTS | ATTR_NO_ZEEK_SIDE_EFFECTS | ATTR_IDEMPOTENT)) != 0; + return (f_attr->second & (ATTR_NO_SCRIPT_SIDE_EFFECTS | ATTR_NO_ZEEK_SIDE_EFFECTS | ATTR_IDEMPOTENT)) == 0; } } // namespace zeek::detail diff --git a/src/script_opt/FuncInfo.h b/src/script_opt/FuncInfo.h index f4bf333cc0..53095d227d 100644 --- a/src/script_opt/FuncInfo.h +++ b/src/script_opt/FuncInfo.h @@ -10,15 +10,15 @@ namespace zeek::detail { // A "special script function" is one that the event engine explicitly // knows about. -extern bool is_special_script_func(std::string func_name); +extern bool is_special_script_func(const std::string& func_name); // An idempotent function returns the same value when called with the // same arguments (and has no meaningful side effects in terms of script-level // or Zeek-internal state). -extern bool is_idempotent(std::string func_name); +extern bool is_idempotent(const std::string& func_name); -// Whether the given function (currently, just BiFs) has no Zeek-script-level +// Whether the given function (currently, just BiFs) has Zeek-script-level // side effects. -extern bool has_no_script_side_effects(std::string func_name); +extern bool has_script_side_effects(const std::string& func_name); } // namespace zeek::detail diff --git a/src/script_opt/ProfileFunc.cc b/src/script_opt/ProfileFunc.cc index 0457482703..df83fe1dd8 100644 --- a/src/script_opt/ProfileFunc.cc +++ b/src/script_opt/ProfileFunc.cc @@ -635,7 +635,7 @@ bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, T auto func = fv->AsFunc(); if ( func->GetKind() == Func::BUILTIN_FUNC ) { - if ( ! has_no_script_side_effects(func->Name()) ) + if ( has_script_side_effects(func->Name()) ) is_unknown = true; return true; } @@ -1168,7 +1168,7 @@ bool ProfileFuncs::DefinitelyHasNoSideEffects(const ExprPtr& e) const { return false; for ( auto& b : pf->BiFGlobals() ) - if ( ! has_no_script_side_effects(b->Name()) ) + if ( has_script_side_effects(b->Name()) ) return false; return true; @@ -1259,7 +1259,7 @@ bool ProfileFuncs::AssessSideEffects(const ProfileFunc* pf, IDSet& non_local_ids } for ( auto& b : pf->BiFGlobals() ) - if ( ! has_no_script_side_effects(b->Name()) ) { + if ( has_script_side_effects(b->Name()) ) { is_unknown = true; return true; }