diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-05-03 17:20:44 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-05-03 17:20:44 +0000 |
commit | d18734b5adea54ddd004e51b8d2593752133596c (patch) | |
tree | ba9e4b659a522fbb2b33848a593ea9f541faf4bc /gcc/go | |
parent | 4e0c5f944ebf4110ddb7ed8352f5bc80fcf0016e (diff) | |
download | gcc-d18734b5adea54ddd004e51b8d2593752133596c.zip gcc-d18734b5adea54ddd004e51b8d2593752133596c.tar.gz gcc-d18734b5adea54ddd004e51b8d2593752133596c.tar.bz2 |
compiler: avoid crashing on invalid non-integer array length
Tweak the array type checking code to avoid crashing on array types
whose length expressions are explicit non-integer types (for example,
"float64(10)"). If such constructs are seen, issue an "invalid array
bound" error.
Fixes golang/go#13486.
Reviewed-on: https://go-review.googlesource.com/91975
From-SVN: r259900
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.cc | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index bb1f4eb..614333d 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -e367bffce3d2c49b456fdf41ab097bded2bcbc3b +85ca682349af2cb1aa6b1eecac794aeb73d24f15 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index 11924e6..e5f84c5 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -7016,6 +7016,16 @@ Array_type::verify_length() return false; } + // For array types, the length expression can be an untyped constant + // representable as an int, but we don't allow explicitly non-integer + // values such as "float64(10)". See issues #13485 and #13486. + if (this->length_->type()->integer_type() == NULL + && !this->length_->type()->is_error_type()) + { + go_error_at(this->length_->location(), "invalid array bound"); + return false; + } + Numeric_constant nc; if (!this->length_->numeric_constant_value(&nc)) { |