From e7f160c41d62462df1087966987d3382f4c721cd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 24 Feb 2011 05:08:26 +0000 Subject: [PATCH] Set type of array length expressions. From-SVN: r170460 --- gcc/go/gofrontend/types.cc | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index 806226f6f42..3e149b93734 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -4287,6 +4287,10 @@ Array_type::verify_length() { if (this->length_ == NULL) return true; + + Type_context context(Type::lookup_integer_type("int"), false); + this->length_->determine_type(&context); + if (!this->length_->is_constant()) { error_at(this->length_->location(), "array bound is not constant"); @@ -4294,30 +4298,23 @@ Array_type::verify_length() } mpz_t val; - - Type* t = this->length_->type(); - if (t->integer_type() != NULL) + mpz_init(val); + Type* vt; + if (!this->length_->integer_constant_value(true, val, &vt)) { - Type* vt; - mpz_init(val); - if (!this->length_->integer_constant_value(true, val, &vt)) - { - error_at(this->length_->location(), - "array bound is not constant"); - mpz_clear(val); - return false; - } - } - else if (t->float_type() != NULL) - { - Type* vt; mpfr_t fval; mpfr_init(fval); if (!this->length_->float_constant_value(fval, &vt)) { - error_at(this->length_->location(), - "array bound is not constant"); + if (this->length_->type()->integer_type() != NULL + || this->length_->type()->float_type() != NULL) + error_at(this->length_->location(), + "array bound is not constant"); + else + error_at(this->length_->location(), + "array bound is not numeric"); mpfr_clear(fval); + mpz_clear(val); return false; } if (!mpfr_integer_p(fval)) @@ -4325,18 +4322,13 @@ Array_type::verify_length() error_at(this->length_->location(), "array bound truncated to integer"); mpfr_clear(fval); + mpz_clear(val); return false; } mpz_init(val); mpfr_get_z(val, fval, GMP_RNDN); mpfr_clear(fval); } - else - { - if (!t->is_error_type()) - error_at(this->length_->location(), "array bound is not numeric"); - return false; - } if (mpz_sgn(val) < 0) { -- 2.30.2