From f0deef1d79db272fa80ef0323b4382ee1936a3e4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 26 Nov 2021 23:17:01 -0700 Subject: Sema: fix analyzeBlockBody logic Previously, when a coercion needed to be inserted into a break instruction, the `br` AIR instruction would be rewritten so that the block operand was a sub-block that did the coercion. The problem is that the sub-block itself was never added to the parent block, resulting in the `br` instruction operand being a bad reference. Now, the `br` AIR instruction that needs to have coercion instructions added is replaced with the sub-block itself with type `noreturn`, and then the sub-block has the coercion instructions and a new `br` instruction that breaks from the original block. LLVM backend needed to be fixed to lower `noreturn` blocks without emitting an unused LLVM basic block. --- src/codegen/llvm.zig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index b75cc52856..21fa0187e3 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2063,8 +2063,14 @@ pub const FuncGen = struct { const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; const extra = self.air.extraData(Air.Block, ty_pl.payload); const body = self.air.extra[extra.end..][0..extra.data.body_len]; + const inst_ty = self.air.typeOfIndex(inst); const parent_bb = self.context.createBasicBlock("Block"); + if (inst_ty.isNoReturn()) { + try self.genBody(body); + return null; + } + var break_bbs: BreakBasicBlocks = .{}; defer break_bbs.deinit(self.gpa); @@ -2084,7 +2090,6 @@ pub const FuncGen = struct { self.builder.positionBuilderAtEnd(parent_bb); // If the block does not return a value, we dont have to create a phi node. - const inst_ty = self.air.typeOfIndex(inst); if (!inst_ty.hasCodeGenBits()) return null; const raw_llvm_ty = try self.dg.llvmType(inst_ty); -- cgit v1.2.3