From 345e3d419eafb0e234aecb4a33f37efe2afbbf53 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sun, 18 Oct 2026 08:07:50 +0000 Subject: feat(classes): add copy constructors and statement-scoped temporaries Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/ControlFlowGen.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/CodeGen/ControlFlowGen.cc') diff --git a/lib/CodeGen/ControlFlowGen.cc b/lib/CodeGen/ControlFlowGen.cc index 0cf0c34..414fe19 100644 --- a/lib/CodeGen/ControlFlowGen.cc +++ b/lib/CodeGen/ControlFlowGen.cc @@ -29,6 +29,7 @@ void CodeGen::emitTryStmt(TryStmtAST *Stmt) { void CodeGen::emitIfStmt(IfStmtAST *Stmt) { Value *CondV = emitCoercedExpr(Stmt->getCond(), resolveType("BOOLEAN")); if (!CondV) return; + cleanupTemporaries(); Function *TheFunction = Builder->GetInsertBlock()->getParent(); BasicBlock *ThenBB = BasicBlock::Create(*TheContext, "then", TheFunction); @@ -65,6 +66,7 @@ void CodeGen::emitWhileStmt(WhileStmtAST *Stmt) { Builder->SetInsertPoint(CondBB); Value *CondV = emitCoercedExpr(Stmt->getCond(), resolveType("BOOLEAN")); if (!CondV) return; + cleanupTemporaries(); Builder->CreateCondBr(CondV, LoopBB, AfterBB); @@ -100,6 +102,7 @@ void CodeGen::emitRepeatStmt(RepeatStmtAST *Stmt) { Builder->SetInsertPoint(CondBB); Value *CondV = emitCoercedExpr(Stmt->getCond(), resolveType("BOOLEAN")); if (!CondV) return; + cleanupTemporaries(); Builder->CreateCondBr(CondV, AfterBB, LoopBB); @@ -127,6 +130,8 @@ void CodeGen::emitForStmt(ForStmtAST *Stmt) { Value *Alloca = Symbol->Storage; Builder->CreateStore(StartVal, Alloca); + cleanupTemporaries(); + // STEP is evaluated exactly once, before the loop. Value *StepVal = nullptr; if (Stmt->getStep()) { @@ -136,6 +141,7 @@ void CodeGen::emitForStmt(ForStmtAST *Stmt) { StepVal = ConstantInt::get(*TheContext, APInt(64, 1)); } + cleanupTemporaries(); BasicBlock *CondBB = BasicBlock::Create(*TheContext, "forcond", TheFunction); BasicBlock *LoopBB = BasicBlock::Create(*TheContext, "forloop", TheFunction); BasicBlock *IncBB = BasicBlock::Create(*TheContext, "forinc", TheFunction); @@ -147,6 +153,7 @@ void CodeGen::emitForStmt(ForStmtAST *Stmt) { Value *CurVar = Builder->CreateLoad(Type::getInt64Ty(*TheContext), Alloca, VarName.c_str()); Value *EndVal = emitCoercedExpr(Stmt->getEnd(), resolveType("INTEGER")); if (!EndVal) return; + cleanupTemporaries(); // The loop direction depends on the STEP value at run time. Value *StepNonNeg = Builder->CreateICmpSGE(StepVal, -- cgit v1.3.1-4-g156e