diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-31 19:45:37 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-05-31 19:45:37 +0000 |
commit | 2b5360d7477277e7e0f32a5bd5479afac819b5e1 (patch) | |
tree | 1aca42d25ab0d81d4d8e4f34c8d820152a3a2958 /gcc/go/gofrontend/expressions.cc | |
parent | f2c2c4e30200463abd0ff1677daf16d49ad4f122 (diff) | |
download | gcc-2b5360d7477277e7e0f32a5bd5479afac819b5e1.zip gcc-2b5360d7477277e7e0f32a5bd5479afac819b5e1.tar.gz gcc-2b5360d7477277e7e0f32a5bd5479afac819b5e1.tar.bz2 |
compiler: handle int-to-string conversion with large integer constant
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
From-SVN: r271821
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index e3a6627..f0c12f4 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -3842,11 +3842,20 @@ Type_conversion_expression::do_get_backend(Translate_context* context) mpz_t intval; Numeric_constant nc; if (this->expr_->numeric_constant_value(&nc) - && nc.to_int(&intval) - && mpz_fits_ushort_p(intval)) + && nc.to_int(&intval)) { std::string s; - Lex::append_char(mpz_get_ui(intval), true, &s, loc); + unsigned int x; + if (mpz_fits_uint_p(intval)) + x = mpz_get_ui(intval); + else + { + char* s = mpz_get_str(NULL, 16, intval); + go_warning_at(loc, 0, + "unicode code point 0x%s out of range in string", s); + x = 0xfffd; + } + Lex::append_char(x, true, &s, loc); mpz_clear(intval); Expression* se = Expression::make_string(s, loc); return se->get_backend(context); |