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: ICE when converting large integer constant to string #32347

Closed
cherrymui opened this issue May 31, 2019 · 2 comments
Closed

gccgo: ICE when converting large integer constant to string #32347

cherrymui opened this issue May 31, 2019 · 2 comments
Milestone

Comments

@cherrymui
Copy link
Member

cherrymui commented May 31, 2019

What version of Go are you using (go version)?

gccgo (GCC) 10.0.0 20190531 (experimental)

What operating system and processor architecture are you using (go env)?

Linux/AMD64

What did you do?

Compiling the following program
https://play.golang.org/p/7r8MnMRjv9B

package main

const X = string(128049)

var S = X

func main() {}

What did you expect to see?

Success.

What did you see instead?

go1: internal compiler error: in global_variable_set_init, at go/go-gcc.cc:2714
0x64330a Gcc_backend::global_variable_set_init(Bvariable*, Bexpression*)
	/usr/local/google/home/cherryyz/src/gccgo3/gcc/go/go-gcc.cc:2714
0x8aea4d Gogo::write_globals()
	/usr/local/google/home/cherryyz/src/gccgo3/gcc/go/gofrontend/gogo.cc:1519

It appears to me that Type_conversion_expression::do_is_constant thinks the int-to-string conversion is constant, but Type_conversion_expression::do_get_backend actually generates a call to runtime.intstring if the integer does not fit in a "ushort" (https://go.googlesource.com/gofrontend/+/4dc60d989293d070702024e7dea52b9849f74775/go/expressions.cc#3846).

Changing ushort to uint fixes this, albeit that it prints a warning if the integer is not valid unicode, e.g. string(0x110000),

c1.go:3:11: warning: unicode code point 0x110000 out of range in string
    3 | const X = string(0x110000)
      |           ^
@gopherbot gopherbot added this to the Gccgo milestone May 31, 2019
@gopherbot
Copy link

Change https://golang.org/cl/179777 mentions this issue: compiler: handle int-to-string conversion with large integer constant

@gopherbot
Copy link

Change https://golang.org/cl/179797 mentions this issue: test: add a test for gccgo bug #32347

gopherbot pushed a commit that referenced this issue May 31, 2019
The gccgo compiler crashes with int-to-string conversion with
large integer constant operand. CL 179777 is the fix. This CL
adds a test.

Updates #32347.

Change-Id: Id1d9dbbcdd3addca4636f1b9c5fdbc450cc48c1d
Reviewed-on: https://go-review.googlesource.com/c/go/+/179797
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
kraj pushed a commit to kraj/gcc that referenced this issue May 31, 2019
    
    Currently, Type_conversion_expression::do_is_constant thinks the
    int-to-string conversion is constant if the integer operand is
    constant, but Type_conversion_expression::do_get_backend actually
    generates a call to runtime.intstring if the integer does not fit
    in a "ushort", which makes it not suitable in constant context,
    such as static initializer.
    
    This CL makes it handle all constant integer input as constant,
    generating constant string.
    
    Fixes golang/go#32347.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/179777


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

2 participants