diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-08-02 16:27:02 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-08-03 16:36:20 -0700 |
commit | cbbd439a33e889a1a47b103951c53472fc8558eb (patch) | |
tree | 5accf4216504db9d9f0d269cac79d1427303ae4c /gcc/go | |
parent | 3a7794b469f897e0141817785738e2faa73119b5 (diff) | |
download | gcc-cbbd439a33e889a1a47b103951c53472fc8558eb.zip gcc-cbbd439a33e889a1a47b103951c53472fc8558eb.tar.gz gcc-cbbd439a33e889a1a47b103951c53472fc8558eb.tar.bz2 |
compiler: check slice to pointer-to-array conversion element type
When checking a slice to pointer-to-array conversion, I forgot to
verify that the elements types are identical.
For golang/go#395
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/339329
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 5 | ||||
-rw-r--r-- | gcc/go/gofrontend/types.cc | 4 |
3 files changed, 8 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 95b9340..801e039 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -0a4d612e6b211780b294717503fc739bbd1f509c +54361805bd611d896042b879ee7f6d2d4d088537 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/expressions.cc b/gcc/go/gofrontend/expressions.cc index 15c9eab..51a8b7e 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -3962,7 +3962,10 @@ Type_conversion_expression::do_lower(Gogo*, Named_object*, if (type->points_to() != NULL && type->points_to()->array_type() != NULL && !type->points_to()->is_slice_type() - && val->type()->is_slice_type()) + && val->type()->is_slice_type() + && Type::are_identical(type->points_to()->array_type()->element_type(), + val->type()->array_type()->element_type(), + 0, NULL)) { Temporary_statement* val_temp = NULL; if (!val->is_multi_eval_safe()) diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index 7c7b2eb..0c44186 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -846,7 +846,9 @@ Type::are_convertible(const Type* lhs, const Type* rhs, std::string* reason) if (rhs->is_slice_type() && lhs->points_to() != NULL && lhs->points_to()->array_type() != NULL - && !lhs->points_to()->is_slice_type()) + && !lhs->points_to()->is_slice_type() + && Type::are_identical(lhs->points_to()->array_type()->element_type(), + rhs->array_type()->element_type(), 0, reason)) return true; // An unsafe.Pointer type may be converted to any pointer type or to |