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: unnecessary bounds check #29872

Open
marigonzes opened this Issue Jan 22, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@marigonzes
Copy link

marigonzes commented Jan 22, 2019

What did you do?

I compiled the following program to see its assembly code: https://godbolt.org/z/OcRvPE

What did you expect to see?

I expected the access to the slice to not be bounds checked

What did you see instead?

A bounds check was generated by the Go compiler

@bradfitz

This comment has been minimized.

Copy link
Member

bradfitz commented Jan 22, 2019

Please use the issue template.

You don't specify what version of Go, for one, or which compiler.

@bradfitz

This comment has been minimized.

Copy link
Member

bradfitz commented Jan 22, 2019

Oh, I see your link goes to a site where "gc (tip)" is selected. But it's faster for us if you put all the relevant information in the bug. And conventionally we share play.golang.org code snippets. But in this case you can just inline the code:

package test

func test(slc []byte, i uint) {
	if len(slc) >= 3 {
		_ = slc[i%3]
	}
}

/cc @randall77 @aclements

@marigonzes

This comment has been minimized.

Copy link
Author

marigonzes commented Jan 22, 2019

Sorry, @bradfitz. I just assumed that you were familiar with Godbolt and, as you found out, the version is displayed there. But I'll take note for future reference.

@randall77

This comment has been minimized.

Copy link
Contributor

randall77 commented Jan 22, 2019

I think this would just involve adding a new case for unsigned remainder to the prove pass.

@josharian

This comment has been minimized.

Copy link
Contributor

josharian commented Jan 22, 2019

cc @rasky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment