This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
- From: Marek Polacek <polacek at redhat dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 7 Dec 2015 14:54:09 +0100
- Subject: Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
- Authentication-results: sourceware.org; auth=none
- References: <20151203175646 dot GI3175 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1512031809290 dot 16579 at digraph dot polyomino dot org dot uk> <20151203212656 dot GJ3175 at redhat dot com> <alpine dot DEB dot 2 dot 10 dot 1512032137040 dot 1888 at digraph dot polyomino dot org dot 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