2022-06-29 18:16:46 -06:00
|
|
|
// errorcheck -0 -m -l
|
|
|
|
//go:build goexperiment.unified
|
|
|
|
// +build goexperiment.unified
|
|
|
|
|
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
package escape
|
|
|
|
|
|
|
|
var sink interface{}
|
|
|
|
|
|
|
|
func dotTypeEscape2() { // #13805, #15796
|
|
|
|
{
|
|
|
|
i := 0
|
|
|
|
j := 0
|
|
|
|
var ok bool
|
|
|
|
var x interface{} = i // ERROR "i does not escape"
|
|
|
|
var y interface{} = j // ERROR "j does not escape"
|
|
|
|
|
[dev.unified] cmd/compile/internal/noder: implicit conversions for multi-valued expressions
This CL changes GOEXPERIMENT=unified to insert implicit conversions
for multi-valued expressions.
Unfortunately, IR doesn't have strong, first-class support for
multi-valued expressions, so this CL takes the approach of spilling
them to temporary variables, which can then be implicitly converted.
This is the same approach taken by walk, but doing it this early does
introduce some minor complications:
1. For select case clauses with comma-ok assignments (e.g., `case x,
ok := <-ch:`), the compiler middle end wants to see the OAS2RECV
assignment is the CommClause.Comm statement. So when constructing
select statements, we need to massage this around a little.
2. The extra temporary variables and assignments skew the existing
inlining heuristics. As mentioned, the temporaries/assignments will
eventually be added (and often optimized away again) anyway, but now
they're visible to the inliner. So this CL also kludges the inlining
heuristics in this case to keep things comparable.
Change-Id: I3e3ea756ad92472ebe28bae3963be61ed7684a75
Reviewed-on: https://go-review.googlesource.com/c/go/+/415244
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-28 17:31:29 -06:00
|
|
|
sink = x.(int) // ERROR "x.\(int\) escapes to heap"
|
|
|
|
sink, *(&ok) = y.(int) // ERROR "autotmp_.* escapes to heap"
|
2022-06-29 18:16:46 -06:00
|
|
|
}
|
|
|
|
}
|