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

gccgo: reject typed non-int len/cap arguments to make #16949

Closed
martisch opened this issue Sep 1, 2016 · 6 comments
Closed

gccgo: reject typed non-int len/cap arguments to make #16949

martisch opened this issue Sep 1, 2016 · 6 comments
Milestone

Comments

@martisch
Copy link
Contributor

martisch commented Sep 1, 2016

while writing test cases in https://go-review.googlesource.com/#/c/28301/ for #16940
this inconsistency turned up:

gc (tip f8555ea and playground 1.7) accept it but the go/types test does not:

type    TCOMPLEX64  complex64

_ = make([]byte, TCOMPLEX64(1+0i))

trybot error:

stdlib_test.go:123: /tmp/workdir/go/test/fixedbugs/issue16940.go:49:22: invalid argument: index TCOMPLEX64(1 + 0i) (constant (1 + 0i) of type TCOMPLEX64) must be integer

\cc @josharian @dsnet @griesemer @randall77 @ianlancetaylor

@bradfitz bradfitz added this to the Go1.8 milestone Sep 1, 2016
@griesemer
Copy link
Contributor

This is a compiler bug. The spec says very clearly: "The size arguments n and m must be of integer type or untyped." (https://tip.golang.org/ref/spec#Making_slices_maps_and_channels).

go/types reports the correct error.

@griesemer
Copy link
Contributor

@ianlancetaylor gccgo appears to have the same problem. It accepts this code silently.

@martisch
Copy link
Contributor Author

martisch commented Sep 1, 2016

thanks. In that case i will prepare a CL to fix checkmake in typecheck.go to reject these cases.

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Sep 1, 2016
…uments

make(T, n, m) returns a slice of type T with length n and capacity m
where "The size arguments n and m must be of integer type or untyped."
https://tip.golang.org/ref/spec#Making_slices_maps_and_channels

The failure to reject typed non-integer size arguments in make
during compile time was uncovered after https://golang.org/cl/27851
changed the generation of makeslice calls.

Fixes   #16940
Updates #16949

Change-Id: Ib1e3576f0e6ad199c9b16b7a50c2db81290c63b4
Reviewed-on: https://go-review.googlesource.com/28301
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
@josharian
Copy link
Contributor

CL 28301 fixed cmd/compile. Changing the issue to be able gccgo.

@josharian josharian changed the title go/types,cmd/compile: constant typed complex argument to make handled inconsistently gccgo: reject typed non-int len/cap arguments to make Sep 1, 2016
@josharian josharian modified the milestones: Unreleased, Go1.8 Sep 1, 2016
@josharian josharian assigned ianlancetaylor and unassigned mdempsky Sep 1, 2016
@ALTree ALTree modified the milestones: Gccgo, Unreleased Feb 2, 2017
@gopherbot
Copy link

Change https://golang.org/cl/91697 mentions this issue: compiler: give error for non-int arguments to make

hubot pushed a commit to gcc-mirror/gcc that referenced this issue Feb 5, 2018
    
    This implements a requirement of the language spec.
    
    While we're here fix the value returned by the type method of a
    builtin call expression to make, although this doesn't seem to make
    any difference anywhere since we lower this to a runtime call before
    the determine_types pass anyhow.
    
    There is already a test for this error in the master repository:
    test/fixedbugs/issue16949.go. It just hasn't made it into the gccgo
    testsuite yet.
    
    Fixes golang/go#16949
    
    Reviewed-on: https://go-review.googlesource.com/91697


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@257376 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Feb 5, 2019
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
    
    This implements a requirement of the language spec.
    
    While we're here fix the value returned by the type method of a
    builtin call expression to make, although this doesn't seem to make
    any difference anywhere since we lower this to a runtime call before
    the determine_types pass anyhow.
    
    There is already a test for this error in the master repository:
    test/fixedbugs/issue16949.go. It just hasn't made it into the gccgo
    testsuite yet.
    
    Fixes golang/go#16949
    
    Reviewed-on: https://go-review.googlesource.com/91697

From-SVN: r257376
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

8 participants