From e165e64fa5b56bd905d6c676abd743d6b3e7361e Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Sat, 31 May 2025 12:49:37 -0700 Subject: [PATCH] fix for -O gen-C++ dealing with type constants of unnamed compound types --- src/script_opt/CPP/InitsInfo.cc | 9 ++++++--- src/script_opt/CPP/InitsInfo.h | 7 +------ src/script_opt/CPP/RuntimeInits.cc | 3 +-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/script_opt/CPP/InitsInfo.cc b/src/script_opt/CPP/InitsInfo.cc index d63e1a45de..3954a39b13 100644 --- a/src/script_opt/CPP/InitsInfo.cc +++ b/src/script_opt/CPP/InitsInfo.cc @@ -299,9 +299,12 @@ void FuncConstInfo::InitializerVals(std::vector& ivs) const { } } -void TypeConstInfo::InitializerVals(std::vector& ivs) const { - auto& t = tv->GetType()->AsTypeType()->GetType(); - ivs.emplace_back(Fmt(t->Tag())); +TypeConstInfo::TypeConstInfo(CPPCompile* _c, ValPtr v) : CompoundItemInfo(_c, v) { + auto tv = v->AsTypeVal(); + auto t = tv->GetType()->AsTypeType()->GetType(); + auto gi = c->RegisterType(t); + type = c->TypeOffset(t); + init_cohort = max(init_cohort, gi->InitCohort() + 1); } AttrInfo::AttrInfo(CPPCompile* _c, const AttrPtr& attr) : CompoundItemInfo(_c) { diff --git a/src/script_opt/CPP/InitsInfo.h b/src/script_opt/CPP/InitsInfo.h index 54c4600af1..a86da4e822 100644 --- a/src/script_opt/CPP/InitsInfo.h +++ b/src/script_opt/CPP/InitsInfo.h @@ -469,12 +469,7 @@ private: class TypeConstInfo : public CompoundItemInfo { public: - TypeConstInfo(CPPCompile* _c, ValPtr v) : CompoundItemInfo(_c, v), tv(v->AsTypeVal()) {} - - void InitializerVals(std::vector& ivs) const override; - -private: - TypeVal* tv; + TypeConstInfo(CPPCompile* _c, ValPtr v); }; // Initialization information for single attributes and sets of attributes. diff --git a/src/script_opt/CPP/RuntimeInits.cc b/src/script_opt/CPP/RuntimeInits.cc index 6efdad27f4..6bd6a1011e 100644 --- a/src/script_opt/CPP/RuntimeInits.cc +++ b/src/script_opt/CPP/RuntimeInits.cc @@ -154,8 +154,7 @@ void CPP_IndexedInits::Generate(InitsManager* im, std::vector& iv template void CPP_IndexedInits::Generate(InitsManager* im, std::vector& ivec, int offset, ValElemVec& init_vals) const { - auto bt = base_type(static_cast(init_vals[0])); - auto t = make_intrusive(bt); + auto t = make_intrusive(im->Types(init_vals[0])); ivec[offset] = make_intrusive(t); }