Patchwork [C] Do not modify possibly shared types

login
register
mail settings
Submitter Richard Guenther
Date Sept. 10, 2010, 12:13 p.m.
Message ID <AANLkTikJc1XZgPwFwo6qx8zq1ZUxZwzEAR0_GMjj87k+@mail.gmail.com>
Download mbox | patch
Permalink /patch/64386/
State New
Headers show

Comments

Richard Guenther - Sept. 10, 2010, 12:13 p.m.
On Fri, Sep 10, 2010 at 1:52 PM, Joseph S. Myers
<joseph@codesourcery.com> wrote:
> On Fri, 10 Sep 2010, Richard Guenther wrote:
>
>> There's the address-space qualifiers above, but I now see that this
>> qualifies the element type, not the array type.  So you are right, we're
>> never going to see any qualifiers (I don't think you are right with
>> TYPE_MAIN_VARIANT removing qualifiers on the element type, at least
>> not with what I know of how tree.c builds array types).
>
> c_build_qualified_type uses build_variant_type_copy to build array types
> with qualified element types.

Ah, I see.

>> As of the sanity check, that would assert that TYPE_MAIN_VARIANT (type)
>> is equal to type, right?
>
> No, since it could also be different in the case of typedefs rather than
> just for qualifiers.  A check of TYPE_QUALS doesn't cover everything but
> may be enough as a basic sanity check on the logic.

Ok, so would be following patch be ok?  It follows what the preceeding
build_distinct_type_copy call does.

Thanks,
Richard.

2010-09-10  Richard Guenther  <rguenther@suse.de>

        * c-decl.c (grokdeclarator): When modifying TYPE_SIZE manually
        create a distinct copy of the type.
Joseph S. Myers - Sept. 10, 2010, 12:20 p.m.
On Fri, 10 Sep 2010, Richard Guenther wrote:

> Ok, so would be following patch be ok?  It follows what the preceeding
> build_distinct_type_copy call does.
> 
> Thanks,
> Richard.
> 
> 2010-09-10  Richard Guenther  <rguenther@suse.de>
> 
>         * c-decl.c (grokdeclarator): When modifying TYPE_SIZE manually
>         create a distinct copy of the type.

This is OK.

Patch

Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c        (revision 164165)
+++ gcc/c-decl.c        (working copy)
@@ -5458,6 +5458,7 @@  grokdeclarator (const struct c_declarato
                if (size && integer_zerop (size))
                  {
                    gcc_assert (itype);
+                   type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
                    TYPE_SIZE (type) = bitsize_zero_node;
                    TYPE_SIZE_UNIT (type) = size_zero_node;
                    SET_TYPE_STRUCTURAL_EQUALITY (type);
@@ -5466,6 +5467,7 @@  grokdeclarator (const struct c_declarato
                  {
                    gcc_assert (itype);
                    /* The type is complete.  C99 6.7.5.2p4  */
+                   type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
                    TYPE_SIZE (type) = bitsize_zero_node;
                    TYPE_SIZE_UNIT (type) = size_zero_node;
                    SET_TYPE_STRUCTURAL_EQUALITY (type);