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: cannot slice 2³²-element array on amd64 #7397

Closed
gopherbot opened this issue Feb 24, 2014 · 7 comments
Closed

cmd/compile: cannot slice 2³²-element array on amd64 #7397

gopherbot opened this issue Feb 24, 2014 · 7 comments

Comments

@gopherbot
Copy link

by john.souvestre:

I’m having trouble slicing a large array.  The slice is only 1 item.  The problem
happens when the array is 2**32 items or larger.  This works.

  var r [int64(0x0fffffff)]struct{}
  rr := r[:1]

This fails with “array len too large” on the second line.

  var r [int64(0x80000000)]struct{}
  rr := r[:1]

I can go all the way to 2**64 before hitting the expected array bounds error on the
first line.

I’m running Go 1.3, 64-bit, on Windows 7.  I'm told that the problem does not occur on
the 32-bit version, including the Playground.
@davecheney
Copy link
Contributor

Comment 1:

http://play.golang.org/p/U5-fzNJD0Z
The problem comes from gc/walk.c
        // static checks if possible
        bv = 1LL<<50;
        if(isconst(bound, CTINT)) {
                if(!smallintconst(bound))
                        yyerror("array len too large");
                else
                        bv = mpgetfix(bound->val.u.xval);
        }
smallintconst asserts that the constant can be expressed as a x86_64 immediate constant
which is only 31 bits wide (32 bits maybe, certainly not larger).

Labels changed: added release-go1.3maybe, repo-main, arch-x86-64.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Mar 3, 2014

Comment 2:

Labels changed: added release-go1.3, removed release-go1.3maybe.

@gopherbot
Copy link
Author

Comment 3 by mal.ware.is.fun:

d... is right, I've just successfully built go compiler with this check commented out
and everything seems to be working.

@rsc
Copy link
Contributor

rsc commented Apr 3, 2014

Comment 4:

This doesn't seem important enough to fix now. Note that it only occurs for the
fixed-length array. If you use make I believe everything is fine. This works on my
64-bit system:
package main
import "fmt"
func main() {
    // does not work in playground
    r := make([]struct{}, 0x80000000)
    rr := r[:1]
    fmt.Println(rr)
}

Labels changed: added release-go1.4, removed release-go1.3.

@rsc
Copy link
Contributor

rsc commented Sep 15, 2014

Comment 5:

Labels changed: added release-go1.5, removed release-go1.4.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@rsc rsc modified the milestones: Unplanned, Go1.5 Apr 26, 2015
@rsc rsc changed the title cmd/6g: cannot slice 2^32-element array cmd/compile: cannot slice 2³²-element array on amd64 Jun 8, 2015
@ALTree
Copy link
Member

ALTree commented Oct 27, 2016

Looks like this can be closed. The following:

package main

import "fmt"

func main() {
    var r [int64(0x80000000)]struct{}
    rr := r[:1]
    fmt.Println(rr)
}

now works (tested on 1.7 and on tip).

@bradfitz
Copy link
Contributor

@ALTree, thanks. Closing.

@golang golang locked and limited conversation to collaborators Oct 27, 2017
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