1
0
mirror of https://github.com/golang/go synced 2024-11-15 02:20:32 -07:00
go/test/linkname3.go
Cherry Mui 849770dec9 cmd/compile: disallow linkname referring to instantiations
Linknaming an instantiated generic symbol isn't particularly
useful: it doesn't guarantee the instantiation exists, and the
instantiated symbol name may be subject to change. Checked with a
large code corpus, currently there is no occurrance of linkname
to an instantiated generic symbol (or symbol with a bracket in its
name). This also suggests that it is not very useful. Linkname is
already an unsafe mechanism. We don't need to allow it to do more
unsafe things without justification.

Change-Id: Ifaa20c98166b28a9d7dc3290c013c2b5bb7682e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/585458
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2024-05-15 19:27:25 +00:00

30 lines
720 B
Go

// errorcheck
// Copyright 2020 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.
// Tests that errors are reported for misuse of linkname.
package p
import _ "unsafe"
type t int
var x, y int
func F[T any](T) {}
//go:linkname x ok
// ERROR "//go:linkname must refer to declared function or variable"
// ERROR "//go:linkname must refer to declared function or variable"
// ERROR "duplicate //go:linkname for x"
// ERROR "//go:linkname reference of an instantiation is not allowed"
//line linkname3.go:20
//go:linkname nonexist nonexist
//go:linkname t notvarfunc
//go:linkname x duplicate
//go:linkname i F[go.shape.int]