From: Marek Polacek <polacek@redhat.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
Date: Mon, 07 Dec 2015 13:54:00 -0000 [thread overview]
Message-ID: <20151207135409.GM3175@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1512032137040.1888@digraph.polyomino.org.uk>
On Thu, Dec 03, 2015 at 09:40:29PM +0000, Joseph Myers wrote:
> On Thu, 3 Dec 2015, Marek Polacek wrote:
>
> > > I think you also need to decrement orig_qual_indirect, which counts the
> > > number of levels of array type derivation from orig_qual_type.
> >
> > Thus:
> >
> > Bootstrapped/regtested on x86_64-linux, ok for trunk?
> >
> > 2015-12-03 Marek Polacek <polacek@redhat.com>
> >
> > PR c/68668
> > * c-decl.c (grokdeclarator): When creating a PARM_DECL of ARRAY_TYPE,
> > use TREE_TYPE of orig_qual_type. Decrement ORIG_QUAL_INDIRECT.
>
> On further consideration:
>
> Removing one level of array type derivation from type means it is one
> fewer levels indirect from the original version of orig_qual_type. So I
> think you should actually decrement orig_qual_indirect without changing
> orig_qual_type. But, if orig_qual_indirect is indirect, in that case you
> may get better results from changing orig_qual_type without decrementing
> orig_qual_indirect.
I think I don't quite understand the last part of this, but here's the patch
anyway. Having added more testcases, I noticed that my last version indeed
wasn't really correct -- thanks for spotting that.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2015-12-07 Marek Polacek <polacek@redhat.com>
PR c/68668
* c-decl.c (grokdeclarator): If ORIG_QUAL_INDIRECT is indirect, use
TREE_TYPE of ORIG_QUAL_TYPE, otherwise decrement ORIG_QUAL_INDIRECT.
* gcc.dg/pr68668.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 9ad8219..6a85514 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -6417,6 +6417,13 @@ grokdeclarator (const struct c_declarator *declarator,
{
/* Transfer const-ness of array into that of type pointed to. */
type = TREE_TYPE (type);
+ if (orig_qual_type != NULL_TREE)
+ {
+ if (orig_qual_indirect != 0)
+ orig_qual_type = TREE_TYPE (orig_qual_type);
+ else
+ orig_qual_indirect--;
+ }
if (type_quals)
type = c_build_qualified_type (type, type_quals, orig_qual_type,
orig_qual_indirect);
diff --git gcc/testsuite/gcc.dg/pr68668.c gcc/testsuite/gcc.dg/pr68668.c
index e69de29..d013aa9 100644
--- gcc/testsuite/gcc.dg/pr68668.c
+++ gcc/testsuite/gcc.dg/pr68668.c
@@ -0,0 +1,53 @@
+/* PR c/68668 */
+/* { dg-do compile } */
+
+typedef const int T[];
+typedef const int U[1];
+
+int
+fn1 (T p)
+{
+ return p[0];
+}
+
+int
+fn2 (U p[2])
+{
+ return p[0][0];
+}
+
+int
+fn3 (U p[2][3])
+{
+ return p[0][0][0];
+}
+
+int
+fn4 (U *p)
+{
+ return p[0][0];
+}
+
+int
+fn5 (U (*p)[1])
+{
+ return (*p)[0][0];
+}
+
+int
+fn6 (U (*p)[1][2])
+{
+ return (*p)[0][0][0];
+}
+
+int
+fn7 (U **p)
+{
+ return p[0][0][0];
+}
+
+int
+fn8 (U (**p)[1])
+{
+ return (*p)[0][0][0];
+}
Marek
next prev parent reply other threads:[~2015-12-07 13:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-03 17:56 Marek Polacek
2015-12-03 18:11 ` Joseph Myers
2015-12-03 21:27 ` Marek Polacek
2015-12-03 21:40 ` Joseph Myers
2015-12-07 13:54 ` Marek Polacek [this message]
2015-12-07 16:08 ` Joseph Myers
2015-12-07 17:01 ` Marek Polacek
2015-12-07 17:44 ` Joseph Myers
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=20151207135409.GM3175@redhat.com \
--to=polacek@redhat.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).