From: Richard Biener <richard.guenther@gmail.com>
To: SenthilKumar.Selvaraj@microchip.com,
"Joseph S. Myers" <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Update array address space in c_build_qualified_type
Date: Wed, 21 Jun 2023 10:15:31 +0200 [thread overview]
Message-ID: <CAFiYyc3ipw1Mfx25Q5Dqz4EQ8zvDS=91YG-bpQZFEextNjDcjQ@mail.gmail.com> (raw)
In-Reply-To: <df9f403f4e3c1f9ad620e8d5e38adaa59be2332b.camel@microchip.com>
On Wed, Jun 21, 2023 at 7:57 AM <SenthilKumar.Selvaraj@microchip.com> wrote:
>
> Hi,
>
> When c-typeck.cc:c_build_qualified_type builds an array type
> from its element type, it does not copy the address space of
> the element type to the array type itself. This is unlike
> tree.cc:build_array_type_1, which explicitly does
>
> TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type);
>
> This causes the ICE described in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86869.
>
> struct S {
> char y[2];
> };
>
> extern const __memx struct S *s;
>
> extern void bar(const __memx void*);
>
> void foo(void) {
> bar(&s->y);
> }
>
> build_component_ref calls c_build_qualified_type, passing in the
> array type and quals including the address space (ADDR_SPACE_MEMX
> in this case). Because of this missing address space copy, the
> returned array type remains in the generic address space. Later
> down the line, expand_expr_addr_expr detects the mismatch in
> address space/mode and tries to convert, and that leads to the
> ICE described in the bug.
>
> This patch sets the address space of the array type to that of the
> element type.
>
> Regression tests for avr look ok. Ok for trunk?
The patch looks OK to me but please let a C frontend maintainer
double-check (I've CCed Joseph for this).
Thanks,
Richard.
> Regards
> Senthil
>
> PR 86869
>
> gcc/c/ChangeLog:
>
> * c-typeck.cc (c_build_qualified_type): Set
> TYPE_ADDR_SPACE for ARRAY_TYPE.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/avr/pr86869.c: New test.
>
> diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
> index 22e240a3c2a..d4ab1d1bd46 100644
> --- a/gcc/c/c-typeck.cc
> +++ b/gcc/c/c-typeck.cc
> @@ -16284,6 +16284,7 @@ c_build_qualified_type (tree type, int type_quals, tree orig_qual_type,
>
> t = build_variant_type_copy (type);
> TREE_TYPE (t) = element_type;
> + TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type);
>
> if (TYPE_STRUCTURAL_EQUALITY_P (element_type)
> || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain)))
> diff --git a/gcc/testsuite/gcc.target/avr/pr86869.c b/gcc/testsuite/gcc.target/avr/pr86869.c
> new file mode 100644
> index 00000000000..54cd984276e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/avr/pr86869.c
> @@ -0,0 +1,13 @@
> +/* { dg-do compile } */
> +/* { dg-options "-std=gnu99" } */
> +
> +extern void bar(const __memx void* p);
> +
> +struct S {
> + char y[2];
> +};
> +extern const __memx struct S *s;
> +
> +void foo(void) {
> + bar(&s->y);
> +}
next prev parent reply other threads:[~2023-06-21 8:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 5:57 SenthilKumar.Selvaraj
2023-06-21 8:15 ` Richard Biener [this message]
2023-06-21 18:37 ` Joseph Myers
2023-06-22 9:55 ` SenthilKumar.Selvaraj
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='CAFiYyc3ipw1Mfx25Q5Dqz4EQ8zvDS=91YG-bpQZFEextNjDcjQ@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=SenthilKumar.Selvaraj@microchip.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=joseph@codesourcery.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).