From 9cd7c7f0babd5264a7a17e44ca8a2f3aa562c8eb Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 13 Sep 2018 20:42:04 +0200 Subject: [PATCH] compiler: fix phi nodes for type asserts Type asserts insert more basic block, causing phi node values to be invalid. Fix this by remembering the outgoing LLVM basic block. --- compiler.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler.go b/compiler.go index 61685628..c92f5509 100644 --- a/compiler.go +++ b/compiler.go @@ -63,6 +63,7 @@ type Frame struct { params map[*ssa.Parameter]int // arguments to the function locals map[ssa.Value]llvm.Value // local variables blocks map[*ssa.BasicBlock]llvm.BasicBlock + currentBlock *ssa.BasicBlock phis []Phi blocking bool taskHandle llvm.Value @@ -1316,6 +1317,7 @@ func (c *Compiler) parseFunc(frame *Frame) error { fmt.Printf("%s:\n", block.Comment) } c.builder.SetInsertPointAtEnd(frame.blocks[block]) + frame.currentBlock = block for _, instr := range block.Instrs { if c.dumpSSA { if val, ok := instr.(ssa.Value); ok && val.Name() != "" { @@ -2369,6 +2371,7 @@ func (c *Compiler) parseExpr(frame *Frame, expr ssa.Value) (llvm.Value, error) { prevBlock := c.builder.GetInsertBlock() okBlock := c.ctx.AddBasicBlock(frame.fn.llvmFn, "typeassert.ok") nextBlock := c.ctx.AddBasicBlock(frame.fn.llvmFn, "typeassert.next") + frame.blocks[frame.currentBlock] = nextBlock // adjust outgoing block for phi nodes c.builder.CreateCondBr(commaOk, okBlock, nextBlock) // Retrieve the value from the interface if the type assert was