From 47ab3d4a42e9ab51c465c4322d2ec233f6324e6b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 15:16:40 +0200 Subject: Adding upstream version 1.18.10. Signed-off-by: Daniel Baumann --- test/escape_goto.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/escape_goto.go (limited to 'test/escape_goto.go') diff --git a/test/escape_goto.go b/test/escape_goto.go new file mode 100644 index 0000000..90da5a2 --- /dev/null +++ b/test/escape_goto.go @@ -0,0 +1,44 @@ +// errorcheck -0 -m -l + +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test escape analysis for goto statements. + +package escape + +var x bool + +func f1() { + var p *int +loop: + if x { + goto loop + } + // BAD: We should be able to recognize that there + // aren't any more "goto loop" after here. + p = new(int) // ERROR "escapes to heap" + _ = p +} + +func f2() { + var p *int + if x { + loop: + goto loop + } else { + p = new(int) // ERROR "does not escape" + } + _ = p +} + +func f3() { + var p *int + if x { + loop: + goto loop + } + p = new(int) // ERROR "does not escape" + _ = p +} -- cgit v1.2.3