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: Initializing an empty map causes divide by zero panic at init! #11354

Closed
mpvl opened this issue Jun 23, 2015 · 4 comments
Closed

Comments

@mpvl
Copy link
Contributor

mpvl commented Jun 23, 2015

Seems to be fixed in 1.5, but for the record.

http://play.golang.org/p/5R2CZTLcB5 causes a divide by zero panic.

package main

type X int // any type of size > 0 seems to cause the bug.

// Use X in a map type.
// - Using X in a slice type does not trigger the bug.
// - Variable needs to be initialized to trigger the bug.
var foo = map[int]X{}

// Use X as follows:
// - Only an array size of 8 seems to cause the bug.
var bar = map[int][8]X{
        // adding fields here doesn't fix it.
} // DIVIDE BY ZERO PANIC AT THIS LINE.

func main() {}
@randall77
Copy link
Contributor

Yes, this is definitely a bug in 1.4. Some types come out of the compiler with a nonzero size but a zero alignment. At least one of the culprits was the types used for map buckets, they were assigned a width but no alignment as map buckets don't need alignment info. But somehow those types are getting shared with other types that do need alignment info. This is why [8]X triggers the bug but not [7]X or [9]X.

This is fixed in 1.5 because we use dowidth() on the map types to compute their size (Dmitry made this change for other reasons, if I remember correctly).

I'm going to add a check to 1.5 to make sure it really is fixed and stays fixed.

@randall77 randall77 added this to the Go1.4.3 milestone Jun 24, 2015
@randall77 randall77 self-assigned this Jun 24, 2015
@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Jun 25, 2015
… alignment

See issue #11354.

Change-Id: I6817d499e6c02e4a9c83f80bc66a2bee368a69ec
Reviewed-on: https://go-review.googlesource.com/11406
Reviewed-by: Russ Cox <rsc@golang.org>
@ianlancetaylor
Copy link
Contributor

Closing because fixed in 1.5.

@mikioh mikioh changed the title Initializing an empty map causes divide by zero panic at init! cmd/compile: Initializing an empty map causes divide by zero panic at init! Jul 14, 2015
@adg adg removed this from the Go1.4.3 milestone Sep 3, 2015
@golang golang locked and limited conversation to collaborators Sep 4, 2016
@gopherbot
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants