Navigation Menu

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

x/tools/go/types: compiles invalid program with overflow #11368

Closed
dvyukov opened this issue Jun 23, 2015 · 2 comments
Closed

x/tools/go/types: compiles invalid program with overflow #11368

dvyukov opened this issue Jun 23, 2015 · 2 comments

Comments

@dvyukov
Copy link
Member

dvyukov commented Jun 23, 2015

On the following program:

package main
func main() {
    var a = -("0"[0])
    println(a)
}

ssadump -run outputs:

208

The program is invalid and must not be compiled (type of "0"[0] is byte, -byte is an overflow).

on commit e9a746d

@griesemer
Copy link
Contributor

The program is valid and the result is correct. Per the spec:

For a of string type:
- a constant index must be in range if the string a is also constant
- if x is out of range at run time, a run-time panic occurs
- a[x] is the non-constant byte value at index x and the type of a[x] is byte

(http://tip.golang.org/ref/spec#Index_expressions)

That is, "0"[0] is not a constant, and the value is the byte value of '0' which is 48; with (-48) mod 256 = 208.

Note that gc rejects this code correctly: http://play.golang.org/p/6b4juoS9km

Filing a gc bug instead.

@dvyukov
Copy link
Member Author

dvyukov commented Jun 23, 2015

FTR, the gc issue is #11370

@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

3 participants