mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/vern/script-opt-maint.Aug24'
* origin/topic/vern/script-opt-maint.Aug24: minor optimization of boolean comparisons fix & regression test for GH-3839 (spurious warnings for "when" constructs)
This commit is contained in:
commit
52bcc92e40
7 changed files with 45 additions and 7 deletions
6
CHANGES
6
CHANGES
|
@ -1,3 +1,9 @@
|
|||
7.1.0-dev.40 | 2024-07-24 11:18:03 +0200
|
||||
|
||||
* minor optimization of boolean comparisons (Vern Paxson, Corelight)
|
||||
|
||||
* GH-3839: fix & regression test for GH-3839 (spurious warnings for "when" constructs) (Vern Paxson, Corelight)
|
||||
|
||||
7.1.0-dev.37 | 2024-07-23 19:18:37 -0700
|
||||
|
||||
* Bump zeek-testing-cluster to reflect deprecation of prometheus.zeek (Christian Kreibich, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
7.1.0-dev.37
|
||||
7.1.0-dev.40
|
||||
|
|
|
@ -434,7 +434,7 @@ ValPtr ScriptFunc::Invoke(zeek::Args* args, Frame* parent) const {
|
|||
|
||||
// Warn if the function returns something, but we returned from
|
||||
// the function without an explicit return, or without a value.
|
||||
else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID &&
|
||||
else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID && ! GetType()->ExpressionlessReturnOkay() &&
|
||||
(flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) &&
|
||||
! f->HasDelayed() )
|
||||
reporter->Warning("non-void function returning without a value: %s", Name());
|
||||
|
|
|
@ -1238,10 +1238,28 @@ ExprPtr EqExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
if ( IsHasElementsTest() )
|
||||
return BuildHasElementsTest()->Reduce(c, red_stmt);
|
||||
|
||||
if ( GetType()->Tag() == TYPE_BOOL && same_singletons(op1, op2) ) {
|
||||
bool t = Tag() == EXPR_EQ;
|
||||
auto res = with_location_of(make_intrusive<ConstExpr>(val_mgr->Bool(t)), this);
|
||||
return res->Reduce(c, red_stmt);
|
||||
if ( GetType()->Tag() == TYPE_BOOL ) {
|
||||
if ( same_singletons(op1, op2) ) {
|
||||
bool t = Tag() == EXPR_EQ;
|
||||
auto res = with_location_of(make_intrusive<ConstExpr>(val_mgr->Bool(t)), this);
|
||||
return res->Reduce(c, red_stmt);
|
||||
}
|
||||
|
||||
if ( op1->GetType()->Tag() == TYPE_BOOL ) {
|
||||
if ( op1->Tag() == EXPR_CONST )
|
||||
std::swap(op1, op2);
|
||||
|
||||
if ( op2->Tag() == EXPR_CONST ) {
|
||||
bool t = Tag() == EXPR_EQ;
|
||||
if ( op2->AsConstExpr()->Value()->IsZero() )
|
||||
t = ! t;
|
||||
if ( t )
|
||||
return op1->Reduce(c, red_stmt);
|
||||
|
||||
auto res = with_location_of(make_intrusive<NotExpr>(op1), this);
|
||||
return res->Reduce(c, red_stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return BinaryExpr::Reduce(c, red_stmt);
|
||||
|
|
|
@ -245,6 +245,12 @@ StmtPtr IfStmt::DoReduce(Reducer* c) {
|
|||
red_e_stmt = cond_red_stmt;
|
||||
}
|
||||
|
||||
// Check again for negation given above reductions/replacements.
|
||||
if ( e->Tag() == EXPR_NOT ) {
|
||||
std::swap(s1, s2);
|
||||
e = e->GetOp1();
|
||||
}
|
||||
|
||||
StmtPtr sl;
|
||||
|
||||
if ( e->IsConst() ) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
done
|
||||
lookup successful
|
||||
received termination signal
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# @TEST-EXEC: btest-bg-run test1 zeek -b %INPUT
|
||||
# @TEST-EXEC: btest-bg-wait 10
|
||||
# @TEST-EXEC: mv test1/.stdout out
|
||||
# @TEST-EXEC: cat test1/.stdout test1/.stderr >> out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
@ -26,6 +26,13 @@ event zeek_init()
|
|||
when [h] ( local hname3 = lookup_addr(h) ) {}
|
||||
timeout to + 2sec {}
|
||||
|
||||
# The following used to generate a spurious warning, so it's here
|
||||
# as a regression test.
|
||||
when ( local res = lookup_addr(127.0.0.1) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
print "done";
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue