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: bogus integer constant overflow #11525

Closed
dvyukov opened this issue Jul 2, 2015 · 5 comments
Closed

gccgo: bogus integer constant overflow #11525

dvyukov opened this issue Jul 2, 2015 · 5 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jul 2, 2015

gccgo rejects to compile the following program:

package a
var a = string(0xE000000000000000)
go.go:2:16: error: integer constant overflow

The spec says:

A constant value x can be converted to type T in any of these cases:
...
x is an integer constant and T is a string type. The same rule as for non-constant x applies in this case.
...
Converting a signed or unsigned integer value to a string type yields a string containing the UTF-8 representation of the integer. Values outside the range of valid Unicode code points are converted to "\uFFFD".

gcc version 6.0.0 2015070 (experimental) (GCC)

@dvyukov
Copy link
Member Author

dvyukov commented Jul 2, 2015

@paranoiacblack

@ianlancetaylor ianlancetaylor added this to the Gccgo milestone Jul 10, 2015
@paranoiacblack
Copy link
Contributor

I'm confused by this since it doesn't seem that (my versions of) either compiler accept this. The spec says this is valid if x is an integer constant and T is a string type, but x is not a valid integer constant; it overflows. I'm not sure why gccgo should compile the above program.

@ianlancetaylor
Copy link
Contributor

The gc compiler also rejects this program:

foo.go:2: overflow in int -> string

I agree with Chris: I don't see why gccgo has to do anything here.

@griesemer
Copy link
Contributor

@paranoiacblack This is an academic exercise at best, but the spec doesn't say that a constant argument must fit into an int (or int64). It just says that it must be an integer value, and that values outside the range result in the value "\uFFFD".

go/types accepts this without errors.

I don't think it matters much, but it seems easier to simply produce this constant string (at compile time) than reporting an error.

@gopherbot
Copy link

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

mydongistiny pushed a commit to mydongistiny/GCC_SaberMod that referenced this issue Sep 2, 2015
    
    When converting a signed or unsigned integer value into a constant
    string, if the integer does not fit into the Go "int" type, the string
    will become "\uFFFD."
    
    Fixes golang/go#11525.
    
    Reviewed-on: https://go-review.googlesource.com/13906


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@227395 138bc75d-0d04-0410-961f-82ee72b054a4
@golang golang locked and limited conversation to collaborators Sep 4, 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

5 participants