From 5fdea7e2edd534d15eff95efb33336430d7b4872 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 03:49:08 +0000 Subject: refactor(codegen): share record field default construction copyClassValue, emitConstruct and emitStringFromCString each walked the record fields and default-constructed those that need it. Move the loop into a private emitFieldDefaults helper; each caller passes the same line as before. Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/StringValueGen.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'lib/CodeGen/StringValueGen.cc') diff --git a/lib/CodeGen/StringValueGen.cc b/lib/CodeGen/StringValueGen.cc index ce9694c..c07f9a9 100644 --- a/lib/CodeGen/StringValueGen.cc +++ b/lib/CodeGen/StringValueGen.cc @@ -29,11 +29,7 @@ Value *CodeGen::emitStringFromCString(Value *Text) { auto *Storage = CreateEntryBlockAlloca(Builder->GetInsertBlock()->getParent(), Type->LLVMType, "string_value"); Builder->CreateStore(Types->getZeroValue(Type->Name), Storage); - for (const auto &[Name, Field] : Type->Record.Fields) - if (typeNeedsConstruction(Field.TypeName) && - !emitDefaultConstruct(Field.TypeName, - Builder->CreateStructGEP(Type->LLVMType, Storage, Field.Index), DiagnosticLine)) - return nullptr; + if (!emitFieldDefaults(Type, Storage, DiagnosticLine)) return nullptr; if (!FuncGen->emitCall(*Constructor, {Storage, Text})) return nullptr; // The consumer takes ownership, just as with an ordinary class result. return Builder->CreateLoad(Type->LLVMType, Storage, "string"); -- cgit v1.3.1-4-g156e