From 225f484c880a840046129f16102216ee29271e66 Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Mon, 23 Sep 2019 17:46:38 -0700 Subject: misc, runtime, test: extra tests and benchmarks for defer Add a bunch of extra tests and benchmarks for defer, in preparation for new low-cost (open-coded) implementation of defers (see #34481), - New file defer_test.go that tests a bunch more unusual defer scenarios, including things that might have problems for open-coded defers. - Additions to callers_test.go actually verifying what the stack trace looks like for various panic or panic-recover scenarios. - Additions to crash_test.go testing several more crash scenarios involving recursive panics. - New benchmark in runtime_test.go measuring speed of panic-recover - New CGo benchmark in cgo_test.go calling from Go to C back to Go that shows defer overhead Updates #34481 Change-Id: I423523f3e05fc0229d4277dd00073289a5526188 Reviewed-on: https://go-review.googlesource.com/c/go/+/197017 Run-TryBot: Dan Scales TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall Reviewed-by: Austin Clements --- test/codegen/stack.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/codegen/stack.go') diff --git a/test/codegen/stack.go b/test/codegen/stack.go index 37d378aa78..7d70024cdd 100644 --- a/test/codegen/stack.go +++ b/test/codegen/stack.go @@ -110,7 +110,11 @@ func MightPanic(a []int, i, j, k, s int) { _ = i / j // panicDivide } +// Put a defer in a loop, so second defer is not open-coded func Defer() { + for i := 0; i < 2; i++ { + defer func() {}() + } // amd64:`CALL\truntime\.deferprocStack` defer func() {}() } -- cgit v1.3-5-g9baa