-
Notifications
You must be signed in to change notification settings - Fork 49
ssa,test: lower builtin panic in defer paths #1839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| run main | ||
| panic in defer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // LITTEST | ||
| package main | ||
|
|
||
| // CHECK: define void @"{{.*}}/deferpanic.main"(){{.*}} { | ||
| func main() { | ||
| defer func() { | ||
| e := recover() | ||
| println(e.(string)) | ||
| }() | ||
| // CHECK: call void @"{{.*}}/runtime/internal/runtime.Panic" | ||
| defer panic("panic in defer") | ||
| println("run main") | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1473,7 +1473,11 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) { | |
| } | ||
| } | ||
| panic("invalid argument for unsafe.Offsetof: must be a selector expression") | ||
| case "panic": | ||
| b.Panic(args[0]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For robustness, it's good practice to validate the number of arguments for built-in functions. The if len(args) != 1 {
panic("ssa: builtin panic expects 1 argument")
}
b.Panic(args[0]) |
||
| return | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This blank line was not present before and is inconsistent with the original formatting (the closing |
||
|
|
||
| panic("todo: " + fn) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This accesses
args[0]without a length guard. Other void-returning builtins in this switch (delete,close,clear) use guards likeif len(args) == 1. Since the Go type checker guaranteespanicalways has exactly one argument, this is safe — and other fixed-arity builtins (complex,real,imag) also skip the guard. Still, addingif len(args) == 1 {would be defensive and self-documenting about the expected arity.Not a bug, just a consistency observation.