From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 6032B3858D1E for ; Tue, 7 Nov 2023 23:45:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6032B3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6032B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=68.232.141.98 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699400729; cv=none; b=jZ7A/yWuAyGdeglfqbEfbbLnIYWDfKdYcT5yGH6I7GpZ7rRFon6j0xFn6EaI1K27Q90z4opGB4oG3hbCRwFO9ZwxEdd2O6+0rXniCFxYcf0GpTzsNqeYNCT2VzEUyC8qF/9ku1MxsAzHEqAn60LhwegAFkSLzbbsPEancEk/YPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699400729; c=relaxed/simple; bh=3Vq53OKtUhbdj5ima/htDHYcuxXz4ZHS0DyHLefCQ/Q=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=UuQqfyBG1uQJMxeOPHU0BeBwmhKUj026qgErGEghRMFy/wvIRn5PdGV+/jgJf5Q+bMqIWnhqqSToBSiYW59AiJIvQGhQICAntlSkYX/sNfk6JRrivzYEPPw93QpLlR13we6kxII/9ekex1/REYO/3ZZWVdwa5U7HcTyg04S1u3o= ARC-Authentication-Results: i=1; server2.sourceware.org X-CSE-ConnectionGUID: xQaVH+HzSXWHUthJbNJRTQ== X-CSE-MsgGUID: nylnz019T6qadrlQy5CnSA== X-IronPort-AV: E=Sophos;i="6.03,284,1694764800"; d="scan'208";a="24852492" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 07 Nov 2023 15:45:26 -0800 IronPort-SDR: 5gWr0FJ+janCsscuURAapwtw95dVHHBwfJKr3pTqeJg/D574OtUfYQSJcIsiJ3eqaRS+dFrJja z2JWVenQ+f79VZLUW9Tx73eoxtDhiXjkY3hmLxA6RJRUTh85IgMuOrS4Pch3sZDdHoRmP7lHI/ Ccjw6IOwSdSoozR8f1laZQOrexGQ7maZwdgLXkW4PnKZ+FSZHG1++fA+zqoTza5Cdr4t9q9V+a SYnAiP7rIfhWhM97+WLd04WXmD74VU1tHflyOfjpji1JHXmPgBEnbsJSFs9B1aCse6zohVVddm PNI= Date: Tue, 7 Nov 2023 23:45:22 +0000 From: Joseph Myers To: Martin Uecker CC: Subject: Re: [C PATCH 6/6] c23: construct composite type for tagged types In-Reply-To: <748ad71f62bb0e306d2fc050763b2e69ca81190f.camel@tugraz.at> Message-ID: <52324a2-4ea6-4d4b-61cf-971b76d5c089@codesourcery.com> References: <4b3866a8cc9b48f3be97c004dedbac8e9149da63.camel@tugraz.at> <748ad71f62bb0e306d2fc050763b2e69ca81190f.camel@tugraz.at> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-14.mgc.mentorg.com (139.181.222.14) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3103.4 required=5.0 tests=BAYES_00,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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