Skip to content
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

go/types: uncommon pointer sizes result in an assertion failure #61249

Closed
aykevl opened this issue Jul 9, 2023 · 5 comments
Closed

go/types: uncommon pointer sizes result in an assertion failure #61249

aykevl opened this issue Jul 9, 2023 · 5 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@aykevl
Copy link

aykevl commented Jul 9, 2023

What version of Go are you using (go version)?

$ go version
go version devel go1.21-5c15498609 Fri Jul 7 22:02:26 2023 +0000 linux/arm64

Does this issue reproduce with the latest release?

Yes, both on the master branch and on the latest release candidate (Go 1.21-rc2).

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/ayke/.cache/go-build'
GOENV='/home/ayke/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/ayke/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ayke'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/ayke/src/tinygo/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/ayke/src/tinygo/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='devel go1.21-5c15498609 Fri Jul 7 22:02:26 2023 +0000'
GCCGO='gccgo'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/ayke/src/ayke/sandbox/types2-avr/go.mod'
GOWORK='/home/ayke/src/ayke/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2438539757=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I made a standalone reproducer here: https://github.com/aykevl/sandbox/tree/main/types2-avr
Simply pull the repository and run it using go run ..

(The code is a quick-n-dirty modification of an example in go/types with the Sizes implementation copied from TinyGo - just enough for a standalone demonstration of the bug).

What did you expect to see?

It should parse the file correctly, like it did in Go 1.20.

What did you see instead?

While typechecking, the program crashes with the following stack trace:

stack trace
~/src/ayke/sandbox/types2-avr$ ~/src/tinygo/go/bin/go run .
panic: /home/ayke/src/tinygo/go/src/go/types/const.go:77: assertion failed [recovered]
        panic: /home/ayke/src/tinygo/go/src/go/types/const.go:77: assertion failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0x4000148000, 0x4000147dc8)
        /home/ayke/src/tinygo/go/src/go/types/check.go:336 +0x9c
panic({0x1f6960?, 0x4000010310?})
        /home/ayke/src/tinygo/go/src/runtime/panic.go:914 +0x218
go/types.assert(0x70?)
        /home/ayke/src/tinygo/go/src/go/types/errors.go:28 +0x60
go/types.representableConst.func1({0x28ea70?, 0x3c36a0?})
        /home/ayke/src/tinygo/go/src/go/types/const.go:77 +0xc0
go/types.representableConst({0x2904f0, 0x400000e7c0}, 0x4000148000, 0x3c36a0, 0x40001043e8)
        /home/ayke/src/tinygo/go/src/go/types/const.go:107 +0x2b0
go/types.(*Checker).conversion.func1({0x28ea70?, 0x3c36a0?}, 0x40001043e8)
        /home/ayke/src/tinygo/go/src/go/types/conversions.go:24 +0x74
go/types.(*Checker).conversion(0x4000148000, 0x40001043c0, {0x28ea70, 0x3c36a0})
        /home/ayke/src/tinygo/go/src/go/types/conversions.go:44 +0x15c
go/types.(*Checker).callExpr(0x4000148000, 0x40001043c0, 0x4000104240)
        /home/ayke/src/tinygo/go/src/go/types/call.go:222 +0xcf0
go/types.(*Checker).exprInternal(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70, 0x4000104240?}, {0x0?, 0x0?})
        /home/ayke/src/tinygo/go/src/go/types/expr.go:1359 +0x12dc
go/types.(*Checker).rawExpr(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70?, 0x4000104240?}, {0x0?, 0x0?}, 0x0)
        /home/ayke/src/tinygo/go/src/go/types/expr.go:965 +0x134
go/types.(*Checker).expr(0x4000146a58?, {0x0?, 0x0?}, 0x40001043c0?, {0x28fc70?, 0x4000104240?})
        /home/ayke/src/tinygo/go/src/go/types/expr.go:1498 +0x40
go/types.(*Checker).callExpr(0x4000148000, 0x40001043c0, 0x4000104280)
        /home/ayke/src/tinygo/go/src/go/types/call.go:210 +0xa98
go/types.(*Checker).exprInternal(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70, 0x4000104280?}, {0x0?, 0x0?})
        /home/ayke/src/tinygo/go/src/go/types/expr.go:1359 +0x12dc
go/types.(*Checker).rawExpr(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70?, 0x4000104280?}, {0x0?, 0x0?}, 0x0)
        /home/ayke/src/tinygo/go/src/go/types/expr.go:965 +0x134
go/types.(*Checker).expr(0x40001479e8?, {0x0?, 0x0?}, 0x169270?, {0x28fc70?, 0x4000104280?})
        /home/ayke/src/tinygo/go/src/go/types/expr.go:1498 +0x40
go/types.(*Checker).varDecl(0x200b20?, 0x400006aae0, {0x400004a0e0?, 0x1, 0x1}, {0x0, 0x0}, {0x28fc70, 0x4000104280})
        /home/ayke/src/tinygo/go/src/go/types/decl.go:513 +0x130
go/types.(*Checker).objDecl(0x4000148000, {0x291718, 0x400006aae0}, 0x1636e8?)
        /home/ayke/src/tinygo/go/src/go/types/decl.go:194 +0x7ac
go/types.(*Checker).packageObjects(0x4000148000)
        /home/ayke/src/tinygo/go/src/go/types/resolver.go:687 +0x3fc
go/types.(*Checker).checkFiles(0x4000148000, {0x4000147ef8, 0x1, 0x1})
        /home/ayke/src/tinygo/go/src/go/types/check.go:380 +0x1d8
go/types.(*Checker).Files(...)
        /home/ayke/src/tinygo/go/src/go/types/check.go:341
go/types.(*Config).Check(0x400006a5a0, {0x23b344?, 0xa?}, 0x40001041c0, {0x4000147ef8, 0x1, 0x1}, 0x0)
        /home/ayke/src/tinygo/go/src/go/types/api.go:425 +0x148
main.main()
        /home/ayke/src/ayke/sandbox/types2-avr/main.go:38 +0x1c4
exit status 2

Apparently the following assert is being hit:

assert(s == 4 || s == 8)

I'd guess that the code assumes that pointers must always be either 4 or 8 bytes in size, while I'm compiling Go code for a system with 2-byte pointers (as crazy as that may sound, it does in fact work - in Go 1.20 at least). Specifically, this is for AVR microcontrollers which are mostly 8-bit but have 16-bit pointers.

Some more context: I'm in the process of making TinyGo work with Go 1.21 but this is one of various issues I'm hitting: tinygo-org/tinygo#3824

@bcmills
Copy link
Contributor

bcmills commented Jul 10, 2023

Looks like that assertion was added in CL 478919 (attn @griesemer @findleyr).

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 10, 2023
@bcmills bcmills added this to the Go1.21 milestone Jul 10, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/508821 mentions this issue: go/types, types2: remove unnecessary assert on pointer size

@findleyr
Copy link
Contributor

I think we can just remove this assertion. I grepped and believe this is the only such assertion, but @aykevl is that easy for you to confirm, by re-running your program without the problematic assertion?

@aykevl
Copy link
Author

aykevl commented Jul 12, 2023

Yes, this appears to be the only assert. My tests pass after I remove that assert.

@griesemer
Copy link
Contributor

Agreed that it's ok to remove this assert.

bradfitz pushed a commit to tailscale/go that referenced this issue Aug 2, 2023
As described in golang#61249, uncommon pointer sizes do exist. Remove an
unnecessary assertion.

Fixes golang#61249

Change-Id: Ib15857bd6bcd42ec530817a132bb8db036236c3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/508821
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants