* [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)
@ 2016-08-06 19:09 Jakub Jelinek
2016-08-07 7:14 ` Richard Biener
2016-08-08 11:04 ` Joseph Myers
0 siblings, 2 replies; 6+ messages in thread
From: Jakub Jelinek @ 2016-08-06 19:09 UTC (permalink / raw)
To: Joseph S. Myers, Marek Polacek, Richard Biener; +Cc: gcc-patches
Hi!
As the testcase shows, the C FE can call relayout_decl even on FIELD_DECLs
in certain cases. Trying to call only layout_decl on FIELD_DECL and
relayout_decl on other decls would be insufficient, we'd need to repeat
there most of the relayout_decl code (except for SET_DECL_RTL, which
FIELD_DECLs don't have).
So I think it is better to allow relayout_decl also on FIELD_DECLs.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2016-08-06 Jakub Jelinek <jakub@redhat.com>
PR c/72816
* stor-layout.c (layout_decl): Fix up formatting.
(relayout_decl): Allow DECL to be FIELD_DECL.
* gcc.dg/pr72816.c: New test.
--- gcc/stor-layout.c.jj 2016-08-06 12:11:56.000000000 +0200
+++ gcc/stor-layout.c 2016-08-06 13:04:43.662532852 +0200
@@ -596,7 +596,7 @@ layout_decl (tree decl, unsigned int kno
return;
gcc_assert (code == VAR_DECL || code == PARM_DECL || code == RESULT_DECL
- || code == TYPE_DECL ||code == FIELD_DECL);
+ || code == TYPE_DECL || code == FIELD_DECL);
rtl = DECL_RTL_IF_SET (decl);
@@ -768,8 +768,8 @@ layout_decl (tree decl, unsigned int kno
}
}
-/* Given a VAR_DECL, PARM_DECL or RESULT_DECL, clears the results of
- a previous call to layout_decl and calls it again. */
+/* Given a VAR_DECL, PARM_DECL, RESULT_DECL, or FIELD_DECL, clears the
+ results of a previous call to layout_decl and calls it again. */
void
relayout_decl (tree decl)
@@ -778,7 +778,8 @@ relayout_decl (tree decl)
DECL_MODE (decl) = VOIDmode;
if (!DECL_USER_ALIGN (decl))
SET_DECL_ALIGN (decl, 0);
- SET_DECL_RTL (decl, 0);
+ if (DECL_RTL_SET_P (decl))
+ SET_DECL_RTL (decl, 0);
layout_decl (decl, 0);
}
--- gcc/testsuite/gcc.dg/pr72816.c.jj 2016-08-06 13:06:45.046003282 +0200
+++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-06 13:07:57.217093845 +0200
@@ -0,0 +1,9 @@
+/* PR c/72816 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu11" } */
+
+typedef const int A[];
+struct S {
+ int a;
+ A b; /* { dg-error "array size missing" } */
+};
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)
2016-08-06 19:09 [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816) Jakub Jelinek
@ 2016-08-07 7:14 ` Richard Biener
2016-08-08 11:04 ` Joseph Myers
1 sibling, 0 replies; 6+ messages in thread
From: Richard Biener @ 2016-08-07 7:14 UTC (permalink / raw)
To: Jakub Jelinek, Joseph S. Myers, Marek Polacek; +Cc: gcc-patches
On August 6, 2016 9:09:08 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>As the testcase shows, the C FE can call relayout_decl even on
>FIELD_DECLs
>in certain cases. Trying to call only layout_decl on FIELD_DECL and
>relayout_decl on other decls would be insufficient, we'd need to repeat
>there most of the relayout_decl code (except for SET_DECL_RTL, which
>FIELD_DECLs don't have).
>
>So I think it is better to allow relayout_decl also on FIELD_DECLs.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
Thanks,
Richard.
>2016-08-06 Jakub Jelinek <jakub@redhat.com>
>
> PR c/72816
> * stor-layout.c (layout_decl): Fix up formatting.
> (relayout_decl): Allow DECL to be FIELD_DECL.
>
> * gcc.dg/pr72816.c: New test.
>
>--- gcc/stor-layout.c.jj 2016-08-06 12:11:56.000000000 +0200
>+++ gcc/stor-layout.c 2016-08-06 13:04:43.662532852 +0200
>@@ -596,7 +596,7 @@ layout_decl (tree decl, unsigned int kno
> return;
>
>gcc_assert (code == VAR_DECL || code == PARM_DECL || code ==
>RESULT_DECL
>- || code == TYPE_DECL ||code == FIELD_DECL);
>+ || code == TYPE_DECL || code == FIELD_DECL);
>
> rtl = DECL_RTL_IF_SET (decl);
>
>@@ -768,8 +768,8 @@ layout_decl (tree decl, unsigned int kno
> }
> }
>
>-/* Given a VAR_DECL, PARM_DECL or RESULT_DECL, clears the results of
>- a previous call to layout_decl and calls it again. */
>+/* Given a VAR_DECL, PARM_DECL, RESULT_DECL, or FIELD_DECL, clears the
>+ results of a previous call to layout_decl and calls it again. */
>
> void
> relayout_decl (tree decl)
>@@ -778,7 +778,8 @@ relayout_decl (tree decl)
> DECL_MODE (decl) = VOIDmode;
> if (!DECL_USER_ALIGN (decl))
> SET_DECL_ALIGN (decl, 0);
>- SET_DECL_RTL (decl, 0);
>+ if (DECL_RTL_SET_P (decl))
>+ SET_DECL_RTL (decl, 0);
>
> layout_decl (decl, 0);
> }
>--- gcc/testsuite/gcc.dg/pr72816.c.jj 2016-08-06 13:06:45.046003282
>+0200
>+++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-06 13:07:57.217093845 +0200
>@@ -0,0 +1,9 @@
>+/* PR c/72816 */
>+/* { dg-do compile } */
>+/* { dg-options "-std=gnu11" } */
>+
>+typedef const int A[];
>+struct S {
>+ int a;
>+ A b; /* { dg-error "array size missing" } */
>+};
>
> Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)
2016-08-06 19:09 [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816) Jakub Jelinek
2016-08-07 7:14 ` Richard Biener
@ 2016-08-08 11:04 ` Joseph Myers
2016-08-08 11:53 ` Marek Polacek
2016-08-10 15:19 ` Jakub Jelinek
1 sibling, 2 replies; 6+ messages in thread
From: Joseph Myers @ 2016-08-08 11:04 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Marek Polacek, Richard Biener, gcc-patches
On Sat, 6 Aug 2016, Jakub Jelinek wrote:
> --- gcc/testsuite/gcc.dg/pr72816.c.jj 2016-08-06 13:06:45.046003282 +0200
> +++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-06 13:07:57.217093845 +0200
> @@ -0,0 +1,9 @@
> +/* PR c/72816 */
> +/* { dg-do compile } */
> +/* { dg-options "-std=gnu11" } */
> +
> +typedef const int A[];
> +struct S {
> + int a;
> + A b; /* { dg-error "array size missing" } */
> +};
As far as I can tell, this is actually valid code that should not produce
an error; the type of a flexible array member can be given by a typedef,
and I see nothing to disallow it being given by a typedef for an array of
qualified type. Note that both the version of this test without const,
and the version with const but not using a typedef, are accepted.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)
2016-08-08 11:04 ` Joseph Myers
@ 2016-08-08 11:53 ` Marek Polacek
2016-08-10 15:19 ` Jakub Jelinek
1 sibling, 0 replies; 6+ messages in thread
From: Marek Polacek @ 2016-08-08 11:53 UTC (permalink / raw)
To: Joseph Myers; +Cc: Jakub Jelinek, Richard Biener, gcc-patches
On Mon, Aug 08, 2016 at 11:04:32AM +0000, Joseph Myers wrote:
> On Sat, 6 Aug 2016, Jakub Jelinek wrote:
>
> > --- gcc/testsuite/gcc.dg/pr72816.c.jj 2016-08-06 13:06:45.046003282 +0200
> > +++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-06 13:07:57.217093845 +0200
> > @@ -0,0 +1,9 @@
> > +/* PR c/72816 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-std=gnu11" } */
> > +
> > +typedef const int A[];
> > +struct S {
> > + int a;
> > + A b; /* { dg-error "array size missing" } */
> > +};
>
> As far as I can tell, this is actually valid code that should not produce
> an error; the type of a flexible array member can be given by a typedef,
> and I see nothing to disallow it being given by a typedef for an array of
> qualified type. Note that both the version of this test without const,
> and the version with const but not using a typedef, are accepted.
I was looking into this last week a bot and the problem seems to be that for
typedefs the array 'b' doesn't have TYPE_DOMAIN, so its type is in fact
const int b[<unknown>] (so the code tries to deduce the size of the array
which fails) whereas without typedef the type is const int b[0:]. I thought
this discrepancy was the core issue here.
Marek
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)
2016-08-08 11:04 ` Joseph Myers
2016-08-08 11:53 ` Marek Polacek
@ 2016-08-10 15:19 ` Jakub Jelinek
2016-08-10 15:31 ` Joseph Myers
1 sibling, 1 reply; 6+ messages in thread
From: Jakub Jelinek @ 2016-08-10 15:19 UTC (permalink / raw)
To: Joseph Myers; +Cc: Marek Polacek, Richard Biener, gcc-patches
On Mon, Aug 08, 2016 at 11:04:32AM +0000, Joseph Myers wrote:
> On Sat, 6 Aug 2016, Jakub Jelinek wrote:
>
> > --- gcc/testsuite/gcc.dg/pr72816.c.jj 2016-08-06 13:06:45.046003282 +0200
> > +++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-06 13:07:57.217093845 +0200
> > @@ -0,0 +1,9 @@
> > +/* PR c/72816 */
> > +/* { dg-do compile } */
> > +/* { dg-options "-std=gnu11" } */
> > +
> > +typedef const int A[];
> > +struct S {
> > + int a;
> > + A b; /* { dg-error "array size missing" } */
> > +};
>
> As far as I can tell, this is actually valid code that should not produce
> an error; the type of a flexible array member can be given by a typedef,
> and I see nothing to disallow it being given by a typedef for an array of
> qualified type. Note that both the version of this test without const,
> and the version with const but not using a typedef, are accepted.
Indeed.
The following untested patch fixes the issue for me. The problem was that
when we create the distinct type with TYPE_DOMAIN [0:], if
TYPE_MAIN_VARIANT (orig_qual_type) is TYPE_MAIN_VARIANT (type) before we
do this, then c_build_qualified_type will return that orig_qual_type and
the TYPE_DOMAIN [0:] is gone again. I think for orig_qual_indirect > 0
we are ok, in that case c_build_qualified_type will never return that and
as the flexible array member is the outermost ARRAY_TYPE, we should be fine.
But perhaps if (orig_qual_indirect > 0 && orig_qual_type), we never reach
the flexible array member through typedef else if, so perhaps
just unconditional orig_qual_type = NULL_TREE; in that else if would work too.
Which of these two versions do you prefer (or something else)?
Shall I revert the stor-layout.c change which might be unnecessary (though
shouldn't hurt)?
2016-08-10 Jakub Jelinek <jakub@redhat.com>
PR c/72816
* c-decl.c (grokdeclarator): When adding TYPE_DOMAIN for flexible
array member through typedef, for orig_qual_indirect == 0 clear
orig_qual_type.
* gcc.dg/pr72816.c: New test.
--- gcc/c/c-decl.c.jj 2016-08-06 12:11:47.000000000 +0200
+++ gcc/c/c-decl.c 2016-08-10 17:07:10.675144603 +0200
@@ -6710,6 +6710,8 @@ grokdeclarator (const struct c_declarato
type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
TYPE_DOMAIN (type) = build_range_type (sizetype, size_zero_node,
NULL_TREE);
+ if (orig_qual_indirect == 0)
+ orig_qual_type = NULL_TREE;
}
type = c_build_qualified_type (type, type_quals, orig_qual_type,
orig_qual_indirect);
--- gcc/testsuite/gcc.dg/pr72816.c.jj 2016-08-07 11:48:34.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr72816.c 2016-08-10 17:08:21.153266419 +0200
@@ -5,5 +5,5 @@
typedef const int A[];
struct S {
int a;
- A b; /* { dg-error "array size missing" } */
+ A b;
};
Jakub
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816)
2016-08-10 15:19 ` Jakub Jelinek
@ 2016-08-10 15:31 ` Joseph Myers
0 siblings, 0 replies; 6+ messages in thread
From: Joseph Myers @ 2016-08-10 15:31 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Marek Polacek, Richard Biener, gcc-patches
On Wed, 10 Aug 2016, Jakub Jelinek wrote:
> 2016-08-10 Jakub Jelinek <jakub@redhat.com>
>
> PR c/72816
> * c-decl.c (grokdeclarator): When adding TYPE_DOMAIN for flexible
> array member through typedef, for orig_qual_indirect == 0 clear
> orig_qual_type.
>
> * gcc.dg/pr72816.c: New test.
OK (subject to testing).
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-08-10 15:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-06 19:09 [PATCH] Allow relayout_decl on FIELD_DECLs (PR c/72816) Jakub Jelinek
2016-08-07 7:14 ` Richard Biener
2016-08-08 11:04 ` Joseph Myers
2016-08-08 11:53 ` Marek Polacek
2016-08-10 15:19 ` Jakub Jelinek
2016-08-10 15:31 ` 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).