From: Joseph Myers <joseph@codesourcery.com>
To: Martin Uecker <uecker@tugraz.at>
Cc: <gcc-patches@gcc.gnu.org>
Subject: Re: [C PATCH 6/6] c23: construct composite type for tagged types
Date: Tue, 7 Nov 2023 23:45:22 +0000 [thread overview]
Message-ID: <52324a2-4ea6-4d4b-61cf-971b76d5c089@codesourcery.com> (raw)
In-Reply-To: <748ad71f62bb0e306d2fc050763b2e69ca81190f.camel@tugraz.at>
On Sat, 26 Aug 2023, Martin Uecker via Gcc-patches wrote:
> @@ -501,9 +510,61 @@ composite_type (tree t1, tree t2)
> return build_type_attribute_variant (t1, attributes);
> }
>
> - case ENUMERAL_TYPE:
> case RECORD_TYPE:
> case UNION_TYPE:
> + if (flag_isoc2x && !comptypes_same_p (t1, t2))
> + {
> + gcc_checking_assert (COMPLETE_TYPE_P (t1) && COMPLETE_TYPE_P (t2));
> + gcc_checking_assert (comptypes (t1, t2));
> +
> + /* If a composite type for these two types is already under
> + construction, return it. */
> +
> + for (struct composite_cache *c = cache; c != NULL; c = c->next)
> + if (c->t1 == t1 && c->t2 == t2)
> + return c->composite;
> +
> + /* Otherwise, create a new type node and link it into the cache. */
> +
> + tree n = make_node (code1);
> + struct composite_cache cache2 = { t1, t2, n, cache };
> + cache = &cache2;
> +
> + tree f1 = TYPE_FIELDS (t1);
> + tree f2 = TYPE_FIELDS (t2);
> + tree fields = NULL_TREE;
> +
> + for (tree a = f1, b = f2; a && b;
> + a = DECL_CHAIN (a), b = DECL_CHAIN (b))
> + {
> + tree ta = TREE_TYPE (a);
> + tree tb = TREE_TYPE (b);
> +
> + gcc_assert (DECL_NAME (a) == DECL_NAME (b));
> + gcc_assert (comptypes (ta, tb));
> +
> + tree f = build_decl (input_location, FIELD_DECL, DECL_NAME (a),
> + composite_type_internal (ta, tb, cache));
> +
> + DECL_FIELD_CONTEXT (f) = n;
> + DECL_CHAIN (f) = fields;
There is a lot more per-field setup done in grokdeclarator, grokfield and
finish_struct when a struct or union is defined. I'm concerned that just
calling build_decl here and then missing most of the per-field setup done
elsewhere will not get the composite type set up correctly, especially in
cases such as bit-fields and packed structures.
Note that the test you have of bit-fields (c2x-tag-composite-3.c) probably
doesn't exercise this code, because the two types are the same (defined in
the same scope, so it would be an error if they weren't the same) and so
the comptypes_same_p check should short-circuit this code. You need to
test such issues in cases where the types are genuinely not the same - and
for bit-fields, that includes ensuring you cover code paths that depend on
each of DECL_BIT_FIELD, DECL_C_BIT_FIELD, DECL_BIT_FIELD_TYPE, to make
sure that all of those are correct.
--
Joseph S. Myers
joseph@codesourcery.com
next prev parent reply other threads:[~2023-11-07 23:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-26 16:19 c23 type compatibility rules, v2 Martin Uecker
2023-08-26 16:20 ` [C PATCH 1/6] c: reorganize recursive type checking Martin Uecker
2023-09-06 20:59 ` Joseph Myers
2023-09-10 8:17 ` [C PATCH 1/6 v2] " Martin Uecker
2023-09-11 20:28 ` Joseph Myers
2023-08-26 16:22 ` [C PATCH 2/6] c23: recursive type checking of tagged type Martin Uecker
2023-11-07 23:06 ` Joseph Myers
2023-08-26 16:23 ` [C PATCH 3/6] c23: tag compatibility rules for struct and unions Martin Uecker
2023-11-07 23:18 ` Joseph Myers
2023-08-26 16:24 ` [C PATCH 4/6] c23: tag compatibility rules for enums Martin Uecker
2023-11-07 23:20 ` Joseph Myers
2023-08-26 16:25 ` [C PATCH 5/6] c23: aliasing of compatible tagged types Martin Uecker
2023-08-26 16:26 ` [C PATCH 6/6] c23: construct composite type for " Martin Uecker
2023-11-07 23:45 ` Joseph Myers [this message]
2023-08-26 16:26 ` [C PATCH] c: flag for tag compatibility rules Martin Uecker
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=52324a2-4ea6-4d4b-61cf-971b76d5c089@codesourcery.com \
--to=joseph@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=uecker@tugraz.at \
/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).