This patch to the Go frontend by Than McIntosh tweaks 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. This fixes https://golang.org/issue/13486.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed
to mainline.
Ian
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE (revision 259875)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -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.
Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc (revision 259805)
+++ gcc/go/gofrontend/types.cc (working copy)
@@ -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))
{