You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a problem with gccgo regarding how it handles exported inlinable methods that are marked with the //go:nointerface flag. Here are a couple of packages that will reproduce the problem:
In $GOPATH/src/noitfimp:
package noitfimp
var pl int
type NoitfStruct struct {
F int
G int
}
//go:nointerface
func (t *NoitfStruct) GMethod() int {
return t.G
}
func (t *NoitfStruct) FMethod() int {
return t.F
}
//go:nointerface
func (t *NoitfStruct) NoInterfaceMethod() {}
and then in $GOPATH/src/noitfmain:
package noitfmain
import (
"noitfimp"
)
type EmbedImported struct {
noitfimp.NoitfStruct
}
func Test() []string {
bad := []string{}
x := interface{}(new(noitfimp.NoitfStruct))
if _, ok := x.(interface {
NoInterfaceMethod()
}); ok {
bad = append(bad, "fail 1")
}
x = interface{}(new(EmbedImported))
if _, ok := x.(interface {
NoInterfaceMethod()
}); ok {
bad = append(bad, "fail 2")
}
return bad
}
and then finally a driver program in $GOPATH/src/noitfdriver:
package main
import (
"fmt"
"noitfmain"
"os"
)
func main() {
bad := noitfmain.Test()
if len(bad) > 0 {
for _, s := range bad {
fmt.Fprintf(os.Stderr, "test failed: %s\n", s)
}
os.Exit(1)
}
}
Then compiler and run the final package (e.g. "go run -compiler gccgo itfdriver").
What did you expect to see?
Empty result from itfmain.Test
What did you see instead?
When executed, prints "test failed: fail 2".
It appears that the 'go:nointerface' property is being lost somehow when the imported type noitfimp.NoitfStruct is embedded into the itfmain type EmbedImported. If I look at the generated assembly, I can see that an additional method NoInterfaceMethod is being incorrectly attached to the type (other than FMethod).
The problem appears to be related to inlining -- in package noitfimp the method in question is empty, meaning that the body gets written out to the export data. If I modify the method body to include more complex statement (for example, a defer) then the problem goes away.
The text was updated successfully, but these errors were encountered:
When an inline function (with body) is imported from another package,
make that the "nointerface" property (if set) is preserved.
Fixesgolang/go#30862.
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/167742
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269713 138bc75d-0d04-0410-961f-82ee72b054a4
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
go env
OutputWhat did you do?
There is a problem with gccgo regarding how it handles exported inlinable methods that are marked with the //go:nointerface flag. Here are a couple of packages that will reproduce the problem:
In $GOPATH/src/noitfimp:
and then in $GOPATH/src/noitfmain:
and then finally a driver program in $GOPATH/src/noitfdriver:
Then compiler and run the final package (e.g. "go run -compiler gccgo itfdriver").
What did you expect to see?
Empty result from itfmain.Test
What did you see instead?
When executed, prints "test failed: fail 2".
It appears that the 'go:nointerface' property is being lost somehow when the imported type
noitfimp.NoitfStruct
is embedded into the itfmain typeEmbedImported
. If I look at the generated assembly, I can see that an additional method NoInterfaceMethod is being incorrectly attached to the type (other thanFMethod
).The problem appears to be related to inlining -- in package noitfimp the method in question is empty, meaning that the body gets written out to the export data. If I modify the method body to include more complex statement (for example, a defer) then the problem goes away.
The text was updated successfully, but these errors were encountered: