From 88ef6cb5b6e68cedab83220487da756cabb05aea Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Mon, 8 Apr 2024 17:33:52 -0400 Subject: [PATCH] record field initialization optimization: do coercions at compile-time if applicable --- src/Type.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Type.cc b/src/Type.cc index c2966cbef6..923a71c23f 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1071,6 +1071,12 @@ void RecordType::AddField(unsigned int field, const TypeDecl* td) { init = std::make_shared(zv); } + else if ( def_expr->Tag() == detail::EXPR_ARITH_COERCE && + (def_expr->GetOp1()->IsZero() || def_expr->GetOp1()->IsOne()) ) { + auto zv = ZVal(def_expr->Eval(nullptr), type); + init = std::make_shared(zv); + } + else { auto efi = std::make_shared(def_expr, type); creation_inits.emplace_back(field, std::move(efi));