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

cmd/compile: degradation in static detection of string out-of-bounds in go1.23rc2 #68644

Closed
PPYSC opened this issue Jul 30, 2024 · 3 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.

Comments

@PPYSC
Copy link

PPYSC commented Jul 30, 2024

Go version

go version go1.23rc2 linux/amd64

Output of go env in your module/workspace:

N/A

What did you do?

package main

import (
	"unsafe"
)

func f[T byte](t T) {
	const str = "a"
	_ = str[unsafe.Sizeof(t)]
}

func main() {
	f(0)
}

I compiled the above code using Go 1.22.5 and Go 1.23rc2 respectively, and their compilation results were different: Go 1.22.5 failed to compile, while Go 1.23rc2 succeeded.

What did you see happen?

For go1.22.5(and go1.21.12), the compiler detects string out-of-bounds issues at compile time and fails to compile.
https://go.dev/play/p/XjprxSMgyNe
https://go.dev/play/p/XjprxSMgyNe?v=goprev

For go1.23rc2, the compiler does not detect string out-of-bounds issues at compile time and successfully compiles the code. (Of course, the program will panic at runtime.)
https://go.dev/play/p/XjprxSMgyNe?v=gotip

What did you expect to see?

Some string out-of-bounds issues that can be detected by the go1.22.5(and go1.21.12) compiler are no longer detected by go1.23rc2. I am unsure whether this is due to changes in static analysis or other reasons, but it appears to be a degradation of capability.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 30, 2024
@gabyhelp
Copy link

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@PPYSC PPYSC closed this as completed Jul 30, 2024
@PPYSC PPYSC reopened this Jul 30, 2024
@PPYSC
Copy link
Author

PPYSC commented Jul 30, 2024

After reading the issue above, I realize that this is exactly what we expect.

@cuonglm
Copy link
Member

cuonglm commented Jul 30, 2024

Duplicated of #65417

@cuonglm cuonglm closed this as completed Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
None yet
Development

No branches or pull requests

4 participants