From 21432e8965403975a3f8e9175a46430b7b818241 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 9 Mar 2025 09:52:54 +0100 Subject: Codegen: Fix bug with if statements inside while loops --- src/codegen.zig | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/codegen.zig b/src/codegen.zig index 98b7c16..45ebde6 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -203,7 +203,7 @@ pub const CodeGen = struct { for (if_statement.statements) |stmt| { try self.generate_statement(stmt); } - const merge_block = core.LLVMAppendBasicBlock(core.LLVMGetLastFunction(self.llvm_module), "else_block"); + const merge_block = core.LLVMAppendBasicBlock(core.LLVMGetLastFunction(self.llvm_module), "merge_block"); const last_instr = core.LLVMGetLastInstruction(then_block); if (core.LLVMIsATerminatorInst(last_instr) == null) { _ = core.LLVMBuildBr(self.builder, merge_block); @@ -233,10 +233,8 @@ pub const CodeGen = struct { for (while_statement.statements) |stmt| { try self.generate_statement(stmt); } - const last_instr = core.LLVMGetLastInstruction(inner_block); - if (core.LLVMIsATerminatorInst(last_instr) == null) { - _ = core.LLVMBuildBr(self.builder, while_block); - } + + _ = core.LLVMBuildBr(self.builder, while_block); core.LLVMPositionBuilderAtEnd(self.builder, outer_block); } -- cgit 1.4.1