From: Ian Lance Taylor <iant@golang.org>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
gofrontend-dev <gofrontend-dev@googlegroups.com>
Subject: Re: Go patch committed: Allow converting from slice to pointer-to-array
Date: Tue, 3 Aug 2021 16:36:29 -0700 [thread overview]
Message-ID: <CAOyqgcVRQpNc9vn0OPHK6xQjhLiOsgsee82z8eBahjQz9yzhbQ@mail.gmail.com> (raw)
In-Reply-To: <CAOyqgcV3=kAKbFYCeqGm6cyYLKTha14bruYKrzHH9UL7q47UnA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 615 bytes --]
On Mon, Aug 2, 2021 at 3:53 PM Ian Lance Taylor <iant@golang.org> wrote:
>
> The upcoming Go 1.17 release has a new language feature: it permits
> conversions from slice types to pointer-to-array types. If the slice
> is too short, the conversion panics. This patch implements this new
> feature in gccgo. Bootstrapped and ran Go testsuite on
> x86_64-pc-linux-gnu. Committed to mainline.
I didn't get the type checking right: I forgot to check that the
element types of the slice and array are identical. Fixed with this
patches. Bootstrapped and tested on x86_64-pc-linux-gnu. Committed
to mainline.
Ian
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1846 bytes --]
7ff2742eacee93c7e7d9262d07c2496f87d801a7
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 95b9340b42d..801e039a155 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 15c9eabc6bf..51a8b7e4322 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 7c7b2eb8271..0c44186f507 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
prev parent reply other threads:[~2021-08-03 23:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-02 22:53 Ian Lance Taylor
2021-08-03 23:36 ` Ian Lance Taylor [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOyqgcVRQpNc9vn0OPHK6xQjhLiOsgsee82z8eBahjQz9yzhbQ@mail.gmail.com \
--to=iant@golang.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=gofrontend-dev@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).