-
Notifications
You must be signed in to change notification settings - Fork 911
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
(constant -4 of type uintptr) overflows uintptr #2806
Comments
This comment above it is relevant:
So it appears that That said, this is most certainly unsafe code so that throws away all promises of portability. But quickly looking at it, I don't see why it fails. |
I had a comment previously that I deleted, I did not read aykevl's comment closely enough. The MessageState struct embeds a few structs with 0 fields. My new guess is that these structs take space in TinyGo, but do not take space in "regular Go". |
Sorry about that. Here's the reproduction. go mod init github.com/tinygo-issues
go get google.golang.org/protobuf package main
import (
"fmt"
_ "google.golang.org/protobuf/runtime/protoimpl"
)
func main() {
fmt.Println("protoc")
} tinygo build -o example.wasm -gc=leaking -scheduler=none -wasm-abi=generic -target=wasi
# google.golang.org/protobuf/internal/impl
../../go/pkg/mod/google.golang.org/protobuf@v1.28.0/internal/impl/pointer_unsafe.go:142:16: unsafe.Sizeof(unsafe.Pointer(nil)) - unsafe.Sizeof((MessageState literal)) (constant -4 of type uintptr) overflows uintptr
make: *** [run] Error 1 |
I trimmed down the minimal repro - to be something even more minimal. I think the bug can be restated as "sizeof 0-length arrays of functions is greater than 0. package main
import (
"unsafe"
)
// DoNotCompare can be embedded in a struct to prevent comparability.
// This struct, when embedded takes non-zero space
type DoNotCompare [0]func()
type MessageState struct {
DoNotCompare
data *int32
}
// Static check that MessageState does not exceed the size of a pointer.
const _ = unsafe.Sizeof(unsafe.Pointer(nil)) - unsafe.Sizeof((MessageState{}))
func main() {
println("protoc minimal example")
} |
FYI @kyleconroy #2854 fixed this issue, it is merged into the dev branch. I think you can probably close this issue. |
I have tagged to close on next release. |
TinyGo can't compile the the pointer_unsafe.go file from https://github.com/protocolbuffers/protobuf-go. I get the following error message:
The text was updated successfully, but these errors were encountered: