diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-18 08:07:50 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-18 08:07:50 +0000 |
| commit | 345e3d419eafb0e234aecb4a33f37efe2afbbf53 (patch) | |
| tree | 9330322103f26f15c6df91cbbd62bf5a1f6e72da /lib/CodeGen/ControlFlowGen.cc | |
| parent | 927e3fc0384c941f9ad313a28768660c3cdb1777 (diff) | |
feat(classes): add copy constructors and statement-scoped temporaries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/ControlFlowGen.cc')
| -rw-r--r-- | lib/CodeGen/ControlFlowGen.cc | 7 |
1 files changed, 7 insertions, 0 deletions
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, |
