Skip to content

Commit

Permalink
compiler: check slice to pointer-to-array conversion element type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ianlancetaylor committed Aug 3, 2021
1 parent 3a7794b commit cbbd439
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gcc/go/gofrontend/MERGE
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion gcc/go/gofrontend/expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion gcc/go/gofrontend/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cbbd439

Please sign in to comment.