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: incorrect boolean value passed to function #18725

Closed
toolateforteddy opened this issue Jan 20, 2017 · 9 comments
Closed

cmd/compile: incorrect boolean value passed to function #18725

toolateforteddy opened this issue Jan 20, 2017 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@toolateforteddy
Copy link

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

go version go1.8rc2 darwin/amd64

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

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

https://play.golang.org/p/hebuAYQ6eo
Take the program above, that on go 1.7.4 prints out "The right thing.", and run that with a go compiler of version 1.8rc2. You now find that it prints out "The wrong thing." Additionally interesting, if you comment out line 15, the second call to "panicWhen", then the first call behaves correctly.

What did you expect to see?

I expect the program to panic with "The right thing."

What did you see instead?

The first call to panicWhen gets the argument cond as false, and panics with "The wrong thing."

@dsnet dsnet added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 20, 2017
@dsnet dsnet added this to the Go1.8 milestone Jan 20, 2017
@robpike
Copy link
Contributor

robpike commented Jan 20, 2017

Confirmed. This is a bug that appeared in 1.8.

@bradfitz
Copy link
Contributor

bradfitz commented Jan 20, 2017

/cc @randall77 @mdempsky @griesemer

@bradfitz bradfitz changed the title Incorrect boolean value passed to function cmd/compile: incorrect boolean value passed to function Jan 20, 2017
@cherrymui
Copy link
Member

The bug is in nilcheck phase, where there is a NilCheck Op in the same block as IsNonNil and happened to be stored before it (since values are not stored in order, until the scheduling phase). But logically NilCheck is after the IsNonNil.

@cherrymui
Copy link
Member

I think we should explicitly check the memory to set/clear nonNilValues.

@dsnet
Copy link
Member

dsnet commented Jan 20, 2017

If it helps, git-bisect shows the offending commit as: 3134ab3, which is a trivial change of only a thousand or so lines ;)

@cherrymui
Copy link
Member

@dsnet, yes, that is it. Before that commit, NilCheck always introduces a new block (BlockCheck) which enforces the value ordering. After that, it no longer introduces new block, so NilCheck could affect values in the same block but logically before it.

@tzneal
Copy link
Member

tzneal commented Jan 20, 2017

Not sure where gopherbot is, there's a CL at http://golang.org/cl/35495

@randall77
Copy link
Contributor

Also proposed CLs at https://golang.org/cl/35496 (Cherry's) and https://golang.org/cl/35485 (mine).

@gopherbot
Copy link

CL https://golang.org/cl/35496 mentions this issue.

gopherbot pushed a commit that referenced this issue Feb 17, 2017
Nil check removal in the same block is disabled due to issue 18725:
because the values are not ordered, a nilcheck may influence a
value that is logically before it. This CL re-enables same-block
nilcheck removal by ordering values in store order first.

Updates #18725.

Change-Id: I287a38525230c14c5412cbcdbc422547dabd54f6
Reviewed-on: https://go-review.googlesource.com/35496
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
@golang golang locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

10 participants