This commit is contained in:
xushiwei
2024-06-13 13:51:36 +08:00
parent 64e96cc101
commit 4abcbb9b51
9 changed files with 75 additions and 21 deletions

View File

@@ -20,4 +20,5 @@ func main() {
return
}
fail()
println("unreachable")
}

29
cl/_testgo/defer4/in.go Normal file
View File

@@ -0,0 +1,29 @@
package main
func f(s string) bool {
return len(s) > 2
}
func fail() {
defer println("bye")
defer func() {
if e := recover(); e != nil {
println("recover:", e.(string))
}
}()
panic("panic message")
}
func main() {
defer func() {
println("hi")
}()
if s := "hello"; f(s) {
defer println(s)
} else {
defer println("world")
return
}
fail()
println("reachable")
}

1
cl/_testgo/defer4/out.ll Normal file
View File

@@ -0,0 +1 @@
;

View File

@@ -555,7 +555,11 @@ func isPhi(i ssa.Instruction) bool {
}
func (p *context) compilePhis(b llssa.Builder, block *ssa.BasicBlock) int {
ret := p.fn.Block(block.Index)
fn := p.fn
ret := fn.Block(block.Index)
if block.Comment == "recover" { // set recover block
fn.SetRecover(ret)
}
b.SetBlockEx(ret, llssa.AtEnd, false)
if ninstr := len(block.Instrs); ninstr > 0 {
if isPhi(block.Instrs[0]) {