Skip to content

cmd/compile: evaluating range argument in cases we shouldn't #73476

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

Closed
randall77 opened this issue Apr 22, 2025 · 3 comments
Closed

cmd/compile: evaluating range argument in cases we shouldn't #73476

randall77 opened this issue Apr 22, 2025 · 3 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime.
Milestone

Comments

@randall77
Copy link
Contributor

randall77 commented Apr 22, 2025

After CL 659317 and 658097, we should no longer be evaluating the side-effects of array and ptr-to-array args to range statements. So code like this should not fault:

package main

//go:noinline
func f(p *[4]int) {
	for i := range *p {
		println(i)
	}
}
func main() {
	f(nil)
}

However, code like this does fault:

package main

//go:noinline
func f(p *[4]int) {
	for i := range (*p) {
		println(i)
	}
}
func main() {
	f(nil)
}

Note the extra parentheses. Normally those aren't there, as gofmt removes them. But cgo puts those parentheses there, which somehow confuses the detector that decides whether we need to evaluate the side-effects of the range statement argument or not.

@cuonglm This relates to the windows/race detector bug. That still I believe a real bug in the race detector, but the reason why it is calling racereadrange at all is this bug.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Apr 22, 2025
@randall77 randall77 self-assigned this Apr 22, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/667415 mentions this issue: cmd/compile: put constant value on node inside parentheses

@gabyhelp
Copy link

Related Code Changes

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

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 22, 2025
@mknyszek mknyszek moved this to In Progress in Go Compiler / Runtime Apr 23, 2025
@mknyszek mknyszek added this to the Go1.25 milestone Apr 23, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in Go Compiler / Runtime Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime.
Projects
Development

No branches or pull requests

5 participants
@mknyszek @randall77 @gopherbot @gabyhelp and others