-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: function-to-interface conversion leads to miscompilation and segfault #48645
Comments
@randall77 Keith, do you want to look at this? I think this may be a problem with doing CONVIDATA on a function pointer which happens at line 47, when the program converts 'it' from an IteratorFunc[R] to an Iterator[R]. Do you know of any probably there might be with CONVIDATA in this case? |
I have a theory. It looks like there are 2 instantiations of Pipe, I think the code ends up using the dictionary designed from the 0/1 version, but passes it to the 0/0 version. Why does the 0/0 version exist at all? I'm not sure about that.
Note that 0/1 has 14 entries, whereas 0/0 has 11 entries. This is the only dictionary for Pipe in the assembly output, having 14 entries (so it's for the 0/1 instantiation):
But the only call in the binary is to the 0/0 version:
Which seems to be using the dictionary appropriate for the 0/1 implementation (reading it out of |
package main
import (
"fmt"
"reflect"
)
type Stream[T any] struct {
}
func (s Stream[T]) DropWhile() Stream[T] {
return Pipe[T, T](s)
}
func Pipe[T, R any](s Stream[T]) Stream[R] {
it := func(fn func(R) bool) {
}
fmt.Println(reflect.TypeOf(it).String())
return Stream[R]{}
}
func main() {
s := Stream[int]{}
s = s.DropWhile()
} Output:
|
@korzhao Yes, I believe that misbehavior is the same issue. It's trying to load the derived type |
Change https://golang.org/cl/353030 mentions this issue: |
OK, thanks @randall77 and @korzhao for point out the behavior with the multiple InstInfo & dictionaries. I figured out that problem and fixed it with this change: https://go-review.googlesource.com/c/go/+/353030 However, it looks like there is another bug, possibly related to converting a closure with captured variables to an interface using a dictionary. (so this could next bug could possible be related to OCONVIDATA). In the CL above, I comment out the closure body so that the test would pass. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No
What operating system and processor architecture are you using (
go env
)?windows/amd64
linux/amd64
(godbolt)What did you do?
https://play.golang.org/p/JxrNfegu__C
https://go.godbolt.org/z/1E6Kx3aoT
What did you expect to see?
Successful compilation.
What did you see instead?
Stack trace (with -l flag)
The text was updated successfully, but these errors were encountered: