Skip to content

Commit af8faf2

Browse files
authored
Merge pull request #1839 from zhouguangyuan0718/main-fix-defer-panic
ssa,test: lower builtin panic in defer paths
2 parents 1196550 + 7b18956 commit af8faf2

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run main
2+
panic in defer

cl/_testlibgo/deferpanic/in.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// LITTEST
2+
package main
3+
4+
// CHECK: define void @"{{.*}}/deferpanic.main"(){{.*}} {
5+
func main() {
6+
defer func() {
7+
e := recover()
8+
println(e.(string))
9+
}()
10+
// CHECK: call void @"{{.*}}/runtime/internal/runtime.Panic"
11+
defer panic("panic in defer")
12+
println("run main")
13+
}

ssa/expr.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,11 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
14731473
}
14741474
}
14751475
panic("invalid argument for unsafe.Offsetof: must be a selector expression")
1476+
case "panic":
1477+
b.Panic(args[0])
1478+
return
14761479
}
1480+
14771481
panic("todo: " + fn)
14781482
}
14791483

0 commit comments

Comments
 (0)