Skip to content

total size of object (1 << 30) * 4 == 0 on 64bit architecture causes index is zero width error #1774

@kortschak

Description

@kortschak
What steps will reproduce the problem?

The following code fails to build with 6g despite len() for bodySlice fitting within the
int type:

package p
type bodySlice [1 << 30]int32
type BigI32Array struct {
        body []bodySlice
}

func (self *BigI32Array) At(hi, lo int) int32 {
        return self.body[hi][lo]

}

What is the expected output?

Either a successful build or something to indicate that the array type length is out of
range (note that the acceptable size differs for different underlying types - replacing
int32 with interface{} will not build for sizes > 1<<27.

What do you see instead?

$ gb
(in pkg/bio/bigarray) building pkg "bio/bigarray"
bigarray.go:35: internal compiler error: index is zero width
1 broken target 


Which compiler are you using (5g, 6g, 8g, gccgo)?

6g


Which operating system are you using?

Ubuntu 10.04 amd64


Which revision are you using?  (hg identify)

982b40af24fb+ tip

Please provide any additional information below.
Discussion leading to this at golang-nuts:
http://groups.google.com/group/golang-nuts/browse_thread/thread/3a61fbaaebd8f9b7/

Relevant comment from Ian Taylor:
"I think this is a compiler bug in 6g.  It's happening because the total
size of the object is (1 << 30) * 4 == 0 (when computed using a 32-bit
type).  But I think 6g ought to permit this, since the index will always
fit in an int.  At the very least it should give a different error
message."

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions