* C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
@ 2015-12-03 17:56 Marek Polacek
2015-12-03 18:11 ` Joseph Myers
0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2015-12-03 17:56 UTC (permalink / raw)
To: GCC Patches, Joseph Myers
This ought to fix the fallout from PR c/68162 fix. Here the problem is that
grokdeclarator created a wrong type for PARM_DECL "p". It created this decl
with type "const int[<unknown>] *" while it should be "const int *".
I think the problem is that we weren't using TREE_TYPE on orig_qual_type and
thus c_build_qualified_type and subsequent c_build_pointer_type might create
a bogus type. So when we're transfering const-ness of an array into that of
type pointed to, use TREE_TYPE not only of "type", but even of the orig qual
type.
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.
* gcc.dg/pr68668.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 9ad8219..0edff2a 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -6417,6 +6417,8 @@ 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)
+ orig_qual_type = TREE_TYPE (orig_qual_type);
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..d144fb6 100644
--- gcc/testsuite/gcc.dg/pr68668.c
+++ gcc/testsuite/gcc.dg/pr68668.c
@@ -0,0 +1,10 @@
+/* PR c/68668 */
+/* { dg-do compile } */
+
+typedef const int T[];
+
+int
+fn1 (T p)
+{
+ return p[0];
+}
Marek
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-03 17:56 C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL) Marek Polacek
@ 2015-12-03 18:11 ` Joseph Myers
2015-12-03 21:27 ` Marek Polacek
0 siblings, 1 reply; 8+ messages in thread
From: Joseph Myers @ 2015-12-03 18:11 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Thu, 3 Dec 2015, Marek Polacek wrote:
> This ought to fix the fallout from PR c/68162 fix. Here the problem is that
> grokdeclarator created a wrong type for PARM_DECL "p". It created this decl
> with type "const int[<unknown>] *" while it should be "const int *".
>
> I think the problem is that we weren't using TREE_TYPE on orig_qual_type and
> thus c_build_qualified_type and subsequent c_build_pointer_type might create
> a bogus type. So when we're transfering const-ness of an array into that of
> type pointed to, use TREE_TYPE not only of "type", but even of the orig qual
> type.
I think you also need to decrement orig_qual_indirect, which counts the
number of levels of array type derivation from orig_qual_type.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-03 18:11 ` Joseph Myers
@ 2015-12-03 21:27 ` Marek Polacek
2015-12-03 21:40 ` Joseph Myers
0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2015-12-03 21:27 UTC (permalink / raw)
To: Joseph Myers; +Cc: GCC Patches
On Thu, Dec 03, 2015 at 06:11:42PM +0000, Joseph Myers wrote:
> On Thu, 3 Dec 2015, Marek Polacek wrote:
>
> > This ought to fix the fallout from PR c/68162 fix. Here the problem is that
> > grokdeclarator created a wrong type for PARM_DECL "p". It created this decl
> > with type "const int[<unknown>] *" while it should be "const int *".
> >
> > I think the problem is that we weren't using TREE_TYPE on orig_qual_type and
> > thus c_build_qualified_type and subsequent c_build_pointer_type might create
> > a bogus type. So when we're transfering const-ness of an array into that of
> > type pointed to, use TREE_TYPE not only of "type", but even of the orig qual
> > type.
>
> 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.
* gcc.dg/pr68668.c: New test.
diff --git gcc/c/c-decl.c gcc/c/c-decl.c
index 9ad8219..25bd1e0 100644
--- gcc/c/c-decl.c
+++ gcc/c/c-decl.c
@@ -6417,6 +6417,11 @@ 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)
+ {
+ orig_qual_type = TREE_TYPE (orig_qual_type);
+ 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..d144fb6 100644
--- gcc/testsuite/gcc.dg/pr68668.c
+++ gcc/testsuite/gcc.dg/pr68668.c
@@ -0,0 +1,10 @@
+/* PR c/68668 */
+/* { dg-do compile } */
+
+typedef const int T[];
+
+int
+fn1 (T p)
+{
+ return p[0];
+}
Marek
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-03 21:27 ` Marek Polacek
@ 2015-12-03 21:40 ` Joseph Myers
2015-12-07 13:54 ` Marek Polacek
0 siblings, 1 reply; 8+ messages in thread
From: Joseph Myers @ 2015-12-03 21:40 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
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.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-03 21:40 ` Joseph Myers
@ 2015-12-07 13:54 ` Marek Polacek
2015-12-07 16:08 ` Joseph Myers
0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2015-12-07 13:54 UTC (permalink / raw)
To: Joseph Myers; +Cc: GCC Patches
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-07 13:54 ` Marek Polacek
@ 2015-12-07 16:08 ` Joseph Myers
2015-12-07 17:01 ` Marek Polacek
0 siblings, 1 reply; 8+ messages in thread
From: Joseph Myers @ 2015-12-07 16:08 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Mon, 7 Dec 2015, Marek Polacek wrote:
> + if (orig_qual_indirect != 0)
> + orig_qual_type = TREE_TYPE (orig_qual_type);
> + else
> + orig_qual_indirect--;
For optimal results for debug info, I think that should be == 0 (i.e.
preserve orig_qual_type, which may be a typedef, if possible - if the
parameter is an array of orig_qual_type), rather than != 0.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-07 16:08 ` Joseph Myers
@ 2015-12-07 17:01 ` Marek Polacek
2015-12-07 17:44 ` Joseph Myers
0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2015-12-07 17:01 UTC (permalink / raw)
To: Joseph Myers; +Cc: GCC Patches
On Mon, Dec 07, 2015 at 04:05:11PM +0000, Joseph Myers wrote:
> On Mon, 7 Dec 2015, Marek Polacek wrote:
>
> > + if (orig_qual_indirect != 0)
> > + orig_qual_type = TREE_TYPE (orig_qual_type);
> > + else
> > + orig_qual_indirect--;
>
> For optimal results for debug info, I think that should be == 0 (i.e.
> preserve orig_qual_type, which may be a typedef, if possible - if the
> parameter is an array of orig_qual_type), rather than != 0.
I'm confused now. If orig_qual_indirect != 0, it is indirect, right?
Earlier you said:
"if orig_qual_indirect is indirect, in that case you
may get better results from changing orig_qual_type without decrementing
orig_qual_indirect."
Isn't that something else than this version with == 0?
Anyway, here's the version with == 0. Thanks,
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL)
2015-12-07 17:01 ` Marek Polacek
@ 2015-12-07 17:44 ` Joseph Myers
0 siblings, 0 replies; 8+ messages in thread
From: Joseph Myers @ 2015-12-07 17:44 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On Mon, 7 Dec 2015, Marek Polacek wrote:
> Anyway, here's the version with == 0. Thanks,
>
> 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.
OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-12-07 17:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-03 17:56 C PATCH for c/68668 (grokdeclarator and wrong type of PARM_DECL) 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
2015-12-07 16:08 ` Joseph Myers
2015-12-07 17:01 ` Marek Polacek
2015-12-07 17:44 ` Joseph Myers
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).