From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 164B53858D34 for ; Mon, 15 Apr 2024 06:55:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 164B53858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 164B53858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713164160; cv=none; b=V71kqJbyCpXGfruYVUHQzBWCoTaw3ikuhrjRpVRCW0ED9bFjoVVXhGGuYC5xwVur+6lksfndMaZfN8fOUPt6RZeWA1qsAAR053vYMRQrpz8RjmFEf2+9hKk1wZ/TXc55pQMLyFUBVPbB06xdgOqKVcrRoQPj1YMG4+mOJDtGivg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713164160; c=relaxed/simple; bh=RTyu+613JC7SWyOunaK4/hCR9odIhbTuRLTODxv+CyA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=OAZQFRbJFYK/3LcNVySO4mV5MbNqKTd8K5ChbKup/2YK37chiNR2P3youhOjP9rpVvKER3mZ6Tx14wdtxBHLYxFpwlDmVzq4FebcSOrjzmyepUkxwhg1esHx+wcba6JJhO2tNHnpUp+wFqyPL5dFrIWfdlBRwA/iWpPriUlFZgM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id CC5A634543; Mon, 15 Apr 2024 06:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713164157; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vCmuORAQANySLvYgN0Z7lCDDC6E2T2cLTT8unMan47A=; b=wKf5mjvo9gps2G4BmFYA52tVYM2C38qHSr/4fMzfgYeWbgbGqQqsdbnFqG11Z5+KZeEqvC Q1OLny8/1F0SKT2q7RFhCLaMbrTu9Fp5Fj7CgHHH3C8o2dmK+wpYoIFksHDjgDETSgENZz yPeH237auBu/upYeFncr5GASI8RAVOI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713164157; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vCmuORAQANySLvYgN0Z7lCDDC6E2T2cLTT8unMan47A=; b=QENn9BKMmU5PW90S2Kq+ldZFYgwuXBNnX3RjEO1SezniHZNn+zli+dlCcDAIiINZDi5H1R GBX7C8bLFdXu6bDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713164156; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vCmuORAQANySLvYgN0Z7lCDDC6E2T2cLTT8unMan47A=; b=bSwgX+YUpXjCppQSQgtBQWIALc93WPDV9BV7DIP3SNmxVjx7L9nHmpcHEfPpHzMtjAQqf7 c20Nyq2oNwfjLzDQsb1IBCBXzDVmFOeKfGShxsk2h4kilIoP6+9qHZZ6oaJmOYLGKqwkhU Xcdn/az1f6VJOhM5eN9law6qvDFhc8Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713164156; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vCmuORAQANySLvYgN0Z7lCDDC6E2T2cLTT8unMan47A=; b=3bRfgJnxJmeQIfkN82y128tX9b+myyUjiAFPk3ZdW01LFl9uoDGspTa35YJ5Dus6dxKrg0 X0q/fSy7FqtykZAQ== Date: Mon, 15 Apr 2024 08:55:56 +0200 (CEST) From: Richard Biener To: Martin Uecker cc: gcc-patches@gcc.gnu.org, Joseph Myers , jakub@redhat.com Subject: Re: [C PATCH, v2] Fix ICE with -g and -std=c23 related to incomplete types [PR114361] In-Reply-To: <448b0744f89d5c6ba5d6a5bacda154fcb74b7bca.camel@tugraz.at> Message-ID: <71q844s1-p7ps-492r-qp8r-r8nq69s8qp8n@fhfr.qr> References: <02a9b94e4d653b6f1b9f89a1b62187f46e871738.camel@tugraz.at> <448b0744f89d5c6ba5d6a5bacda154fcb74b7bca.camel@tugraz.at> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email] X-Spam-Score: -4.30 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham 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 Sun, 14 Apr 2024, Martin Uecker wrote: > > I had to revert the old patch because it broke LTO which lead > to PR114574. We now set TYPE_STRUCTURAL_EQUALITY and properly > update TYPE_CANONICAL for such types and also for pointers > to such types via a new function c_update_type_canonical > (thanks to Jakob). > > > Bootstrapped and regession tested on x86_64. > > > > Fix ICE with -g and -std=c23 related to incomplete types [PR114361] > > We did not update TYPE_CANONICAL for incomplete variants when > completing a structure. We now set TYPE_STRUCTURAL_EQUALITY for > incomplete structure and union types and then update TYPE_CANONICAL > later. See PR114574 for discussion. > > > 2024-04-12 Martin Uecker > Jakub Jelinek > > PR lto/114574 > PR c/114361 > gcc/ > * ipa-free-lang-data.cc (fld_incomplete_type_of): Allow > either of the types in the assert to have TYPE_STRUCTURAL_EQUALITY_P. > gcc/c/ > * c-decl.cc (shadow_tag_warned): For flag_isoc23 and code not > ENUMERAL_TYPE use SET_TYPE_STRUCTURAL_EQUALITY. > (parser_xref_tag): Likewise. > (start_struct): For flag_isoc23 use SET_TYPE_STRUCTURAL_EQUALITY. > (c_update_type_canonical): New function. > (finish_struct): Put NULL as second == operand rather than first. > Assert TYPE_STRUCTURAL_EQUALITY_P. Call c_update_type_canonical. > * c-typeck.cc (composite_type_internal): Use > SET_TYPE_STRUCTURAL_EQUALITY. Formatting fix. > gcc/testsuite/ > * gcc.dg/pr114574-1.c: New test. > * gcc.dg/pr114574-2.c: New test. > * gcc.dg/pr114361.c: New test. > * gcc.dg/c23-tag-incomplete-1.c: New test. > * gcc.dg/c23-tag-incomplete-2.c: New test. > --- > gcc/c/c-decl.cc | 47 ++++++++++++++++++++- > gcc/c/c-typeck.cc | 4 +- > gcc/ipa-free-lang-data.cc | 4 +- > gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c | 14 ++++++ > gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c | 13 ++++++ > gcc/testsuite/gcc.dg/pr114361.c | 11 +++++ > gcc/testsuite/gcc.dg/pr114574-1.c | 10 +++++ > gcc/testsuite/gcc.dg/pr114574-2.c | 10 +++++ > 8 files changed, 110 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c > create mode 100644 gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c > create mode 100644 gcc/testsuite/gcc.dg/pr114361.c > create mode 100644 gcc/testsuite/gcc.dg/pr114574-1.c > create mode 100644 gcc/testsuite/gcc.dg/pr114574-2.c > > diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc > index 345090dae38..54917297b6a 100644 > --- a/gcc/c/c-decl.cc > +++ b/gcc/c/c-decl.cc > @@ -5051,6 +5051,8 @@ shadow_tag_warned (const struct c_declspecs *declspecs, int warned) > if (t == NULL_TREE) > { > t = make_node (code); > + if (flag_isoc23 && code != ENUMERAL_TYPE) > + SET_TYPE_STRUCTURAL_EQUALITY (t); > pushtag (input_location, name, t); > } > } > @@ -8809,6 +8811,8 @@ parser_xref_tag (location_t loc, enum tree_code code, tree name, > the forward-reference will be altered into a real type. */ > > ref = make_node (code); > + if (flag_isoc23 && code != ENUMERAL_TYPE) > + SET_TYPE_STRUCTURAL_EQUALITY (ref); > if (code == ENUMERAL_TYPE) > { > /* Give the type a default layout like unsigned int > @@ -8910,6 +8914,8 @@ start_struct (location_t loc, enum tree_code code, tree name, > if (ref == NULL_TREE || TREE_CODE (ref) != code) > { > ref = make_node (code); > + if (flag_isoc23) > + SET_TYPE_STRUCTURAL_EQUALITY (ref); > pushtag (loc, name, ref); > } > > @@ -9347,6 +9353,43 @@ is_flexible_array_member_p (bool is_last_field, > return false; > } > > +/* Recompute TYPE_CANONICAL for qualified versions of the type and > + related pointer types after an aggregate type has been finalized. > + Will not update array types, pointers to array types, function > + types and other derived types created while the type was still > + incomplete, those will remain TYPE_STRUCTURAL_EQUALITY_P. */ > + > +static void > +c_update_type_canonical (tree t) > +{ > + for (tree x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x)) > + { > + if (x != t > + && TYPE_STRUCTURAL_EQUALITY_P (x) > + && check_qualified_type (x, t, TYPE_QUALS (x))) > + { > + if (TYPE_CANONICAL (t) != t) > + TYPE_CANONICAL (x) > + = build_qualified_type (TYPE_CANONICAL (t), TYPE_QUALS (x)); > + else > + TYPE_CANONICAL (x) = x; > + } > + else if (x != t) > + continue; > + for (tree p = TYPE_POINTER_TO (x); p; p = TYPE_NEXT_PTR_TO (p)) > + { > + if (!TYPE_STRUCTURAL_EQUALITY_P (p)) > + continue; > + if (TYPE_CANONICAL (x) != x || TYPE_REF_CAN_ALIAS_ALL (p)) > + TYPE_CANONICAL (p) > + = build_pointer_type_for_mode (TYPE_CANONICAL (x), TYPE_MODE (p), > + false); > + else > + TYPE_CANONICAL (p) = p; > + c_update_type_canonical (p); > + } > + } > +} > > /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. > LOC is the location of the RECORD_TYPE or UNION_TYPE's definition. > @@ -9695,11 +9738,12 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, > /* Set type canonical based on equivalence class. */ > if (flag_isoc23) > { > - if (NULL == c_struct_htab) > + if (c_struct_htab == NULL) > c_struct_htab = hash_table::create_ggc (61); > > hashval_t hash = c_struct_hasher::hash (t); > > + gcc_checking_assert (TYPE_STRUCTURAL_EQUALITY_P (t)); > tree *e = c_struct_htab->find_slot_with_hash (t, hash, INSERT); > if (*e) > TYPE_CANONICAL (t) = *e; > @@ -9708,6 +9752,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, > TYPE_CANONICAL (t) = t; > *e = t; > } > + c_update_type_canonical (t); > } > > tree incomplete_vars = C_TYPE_INCOMPLETE_VARS (TYPE_MAIN_VARIANT (t)); > diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc > index ddeab1e2a8a..4567b114734 100644 > --- a/gcc/c/c-typeck.cc > +++ b/gcc/c/c-typeck.cc > @@ -532,6 +532,7 @@ composite_type_internal (tree t1, tree t2, struct composite_cache* cache) > /* Otherwise, create a new type node and link it into the cache. */ > > tree n = make_node (code1); > + SET_TYPE_STRUCTURAL_EQUALITY (n); > TYPE_NAME (n) = TYPE_NAME (t1); > > struct composite_cache cache2 = { t1, t2, n, cache }; > @@ -590,7 +591,8 @@ composite_type_internal (tree t1, tree t2, struct composite_cache* cache) > TYPE_STUB_DECL (n) = pushdecl (build_decl (input_location, TYPE_DECL, > NULL_TREE, n)); > > - n = finish_struct(input_location, n, fields, attributes, NULL, &expr); > + n = finish_struct (input_location, n, fields, attributes, NULL, > + &expr); > > n = qualify_type (n, t1); > > diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc > index 16ed55e2e5a..6f75444e513 100644 > --- a/gcc/ipa-free-lang-data.cc > +++ b/gcc/ipa-free-lang-data.cc > @@ -255,7 +255,9 @@ fld_incomplete_type_of (tree t, class free_lang_data_d *fld) > first = build_reference_type_for_mode (t2, TYPE_MODE (t), > TYPE_REF_CAN_ALIAS_ALL (t)); > gcc_assert (TYPE_CANONICAL (t2) != t2 > - && TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t))); > + && (TYPE_CANONICAL (t2) == TYPE_CANONICAL (TREE_TYPE (t)) > + || TYPE_STRUCTURAL_EQUALITY_P (t2) > + || TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t)))); I think we want the same canonical types for t2 and TREE_TYPE (t), why doesn't fld_incomplete_type_of make it so? Richard. > if (!fld->pset.add (first)) > add_tree_to_fld_list (first, fld); > return fld_type_variant (first, t, fld); > diff --git a/gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c b/gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c > new file mode 100644 > index 00000000000..82d652569e9 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/c23-tag-incomplete-1.c > @@ -0,0 +1,14 @@ > +/* { dg-do compile } > + * { dg-options "-std=c23 -g" } */ > + > +struct a; > +typedef struct a b; > + > +void g() { > + struct a { b* x; }; > +} > + > +struct a { b* x; }; > + > + > + > diff --git a/gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c b/gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c > new file mode 100644 > index 00000000000..bc47a04ece5 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/c23-tag-incomplete-2.c > @@ -0,0 +1,13 @@ > +/* { dg-do compile } > + * { dg-options "-std=c23 -g" } */ > + > +struct a; > +typedef struct a b; > + > +void f() { > + extern struct a { b* x; } t; > +} > + > +extern struct a { b* x; } t; > + > + > diff --git a/gcc/testsuite/gcc.dg/pr114361.c b/gcc/testsuite/gcc.dg/pr114361.c > new file mode 100644 > index 00000000000..0f3feb53566 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr114361.c > @@ -0,0 +1,11 @@ > +/* PR c/114361 */ > +/* { dg-do compile } */ > +/* { dg-options "-std=gnu23 -g" } */ > + > +void f() > +{ > + typedef struct foo bar; > + typedef __typeof( ({ (struct foo { bar *x; }){ }; }) ) wuz; > + struct foo { wuz *x; }; > +} > + > diff --git a/gcc/testsuite/gcc.dg/pr114574-1.c b/gcc/testsuite/gcc.dg/pr114574-1.c > new file mode 100644 > index 00000000000..060dcdbe73e > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr114574-1.c > @@ -0,0 +1,10 @@ > +/* PR lto/114574 > + * { dg-do compile } > + * { dg-options "-flto" } */ > + > +const struct S * x; > +struct S {}; > +void f(const struct S **); > + > + > + > diff --git a/gcc/testsuite/gcc.dg/pr114574-2.c b/gcc/testsuite/gcc.dg/pr114574-2.c > new file mode 100644 > index 00000000000..723291e2211 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr114574-2.c > @@ -0,0 +1,10 @@ > +/* PR lto/114574 > + * { dg-do compile } > + * { dg-options "-flto -std=c23" } */ > + > +const struct S * x; > +struct S {}; > +void f(const struct S **); > + > + > + > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)