mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +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:
|
||||
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:
|
||||
void ExprDescribe(ODesc* d) const override;
|
||||
|
|
|
@ -475,6 +475,7 @@ ExprPtr UnaryExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
auto op_val = op->FoldVal();
|
||||
if ( op_val ) {
|
||||
auto fold = Fold(op_val.get());
|
||||
if ( fold->GetType()->Tag() != TYPE_OPAQUE )
|
||||
return TransformMe(make_intrusive<ConstExpr>(fold), c, red_stmt);
|
||||
}
|
||||
|
||||
|
@ -523,6 +524,7 @@ ExprPtr BinaryExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
|||
auto op2_fold_val = op2->FoldVal();
|
||||
if ( op1_fold_val && op2_fold_val ) {
|
||||
auto fold = Fold(op1_fold_val.get(), op2_fold_val.get());
|
||||
if ( fold->GetType()->Tag() != TYPE_OPAQUE )
|
||||
return TransformMe(make_intrusive<ConstExpr>(fold), c, red_stmt);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue