mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
fix for script optimization of constants of type "opaque"
This commit is contained in:
parent
03347e235b
commit
5a3b519fb4
2 changed files with 14 additions and 3 deletions
11
src/Expr.h
11
src/Expr.h
|
@ -474,7 +474,16 @@ public:
|
||||||
|
|
||||||
// Optimization-related:
|
// Optimization-related:
|
||||||
ExprPtr Duplicate() override;
|
ExprPtr Duplicate() override;
|
||||||
ValPtr FoldVal() const override { return val; }
|
|
||||||
|
ValPtr FoldVal() const override {
|
||||||
|
if ( type->Tag() == TYPE_OPAQUE )
|
||||||
|
// Aggressive constant propagation can lead to the appearance of
|
||||||
|
// opaque "constants". Don't consider these as foldable because
|
||||||
|
// they're problematic to generate independently.
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ExprDescribe(ODesc* d) const override;
|
void ExprDescribe(ODesc* d) const override;
|
||||||
|
|
|
@ -475,7 +475,8 @@ ExprPtr UnaryExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||||
auto op_val = op->FoldVal();
|
auto op_val = op->FoldVal();
|
||||||
if ( op_val ) {
|
if ( op_val ) {
|
||||||
auto fold = Fold(op_val.get());
|
auto fold = Fold(op_val.get());
|
||||||
return TransformMe(make_intrusive<ConstExpr>(fold), c, red_stmt);
|
if ( fold->GetType()->Tag() != TYPE_OPAQUE )
|
||||||
|
return TransformMe(make_intrusive<ConstExpr>(fold), c, red_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c->Optimizing() )
|
if ( c->Optimizing() )
|
||||||
|
@ -523,7 +524,8 @@ ExprPtr BinaryExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||||
auto op2_fold_val = op2->FoldVal();
|
auto op2_fold_val = op2->FoldVal();
|
||||||
if ( op1_fold_val && op2_fold_val ) {
|
if ( op1_fold_val && op2_fold_val ) {
|
||||||
auto fold = Fold(op1_fold_val.get(), op2_fold_val.get());
|
auto fold = Fold(op1_fold_val.get(), op2_fold_val.get());
|
||||||
return TransformMe(make_intrusive<ConstExpr>(fold), c, red_stmt);
|
if ( fold->GetType()->Tag() != TYPE_OPAQUE )
|
||||||
|
return TransformMe(make_intrusive<ConstExpr>(fold), c, red_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c->Optimizing() )
|
if ( c->Optimizing() )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue