Skip to content

Commit beeab6a

Browse files
committed
cmd/compile: fix go:uintptrescapes tag for unnamed parameters
The tag was overwritten by the code for special handling unnamed parameters. Fixes #23045. Change-Id: Ie2e1db3e902a07a2bbbc2a3424cea300f0a42cc3 Reviewed-on: https://go-review.googlesource.com/82775 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 91a6a2a commit beeab6a

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/cmd/compile/internal/gc/esc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,6 +2260,13 @@ func (e *EscState) esctag(fn *Node) {
22602260
// (Unnamed parameters are not in the Dcl list in the loop above
22612261
// so we need to mark them separately.)
22622262
for _, f := range fn.Type.Params().Fields().Slice() {
2263+
if !types.Haspointers(f.Type) { // don't bother tagging for scalars
2264+
continue
2265+
}
2266+
if f.Note == uintptrEscapesTag {
2267+
// Note is already set in the loop above.
2268+
continue
2269+
}
22632270
if f.Sym == nil || f.Sym.IsBlank() {
22642271
f.Note = mktag(EscNone)
22652272
}

test/uintptrescapes2.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ func F1(a uintptr) {} // ERROR "escaping uintptr"
2020
//go:noinline
2121
func F2(a ...uintptr) {} // ERROR "escaping ...uintptr" "a does not escape"
2222

23+
//go:uintptrescapes
24+
//go:noinline
25+
func F3(uintptr) {} // ERROR "escaping uintptr"
26+
27+
//go:uintptrescapes
28+
//go:noinline
29+
func F4(...uintptr) {} // ERROR "escaping ...uintptr"
30+
2331
func G() {
24-
var t int // ERROR "moved to heap"
25-
F1(uintptr(unsafe.Pointer(&t))) // ERROR "live at call to F1: .?autotmp" "&t escapes to heap"
32+
var t int // ERROR "moved to heap"
33+
F1(uintptr(unsafe.Pointer(&t))) // ERROR "live at call to F1: .?autotmp" "&t escapes to heap"
34+
var t2 int // ERROR "moved to heap"
35+
F3(uintptr(unsafe.Pointer(&t2))) // ERROR "live at call to F3: .?autotmp" "&t2 escapes to heap"
2636
}
2737

2838
func H() {
29-
var v int // ERROR "moved to heap"
30-
F2(0, 1, uintptr(unsafe.Pointer(&v)), 2) // ERROR "live at call to newobject: .?autotmp" "live at call to F2: .?autotmp" "escapes to heap"
39+
var v int // ERROR "moved to heap"
40+
F2(0, 1, uintptr(unsafe.Pointer(&v)), 2) // ERROR "live at call to newobject: .?autotmp" "live at call to F2: .?autotmp" "escapes to heap"
41+
var v2 int // ERROR "moved to heap"
42+
F4(0, 1, uintptr(unsafe.Pointer(&v2)), 2) // ERROR "live at call to newobject: .?autotmp" "live at call to F4: .?autotmp" "escapes to heap"
3143
}

0 commit comments

Comments
 (0)