Skip to content

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

Closed
@cherrymui

Description

@cherrymui

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)
      |           ^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions