From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id 9B0553858CD1 for ; Thu, 11 Apr 2024 06:03:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B0553858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tugraz.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tugraz.at ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9B0553858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=129.27.2.202 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712815412; cv=none; b=OMU6y+aSz3DF7lhxkrqDk/6nTibVACfX/pmgApTXHsiDK45V47CfNzo8f32LfZ2ajn60HAAZ/xd1IcWSSOQQ3V+AAGPTVT/mdpI6TREQaEaJCnNI6WCPtIYFAYStP/JLDiYalXN3Mg0DdG/WkBkiDf1fcZHhIjmnde7FRgFZLek= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712815412; c=relaxed/simple; bh=Kb+rOH3Zmrw4IoMSIUPvTDGDbHgudXUhPZy0FubTr+o=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=EGr4To0g7POcdHDWDsol+4HquI/YC109r8UrwjrKZBDro0LMXxUDczHTDv31A7xA6zWnfWDLSCbyBhFjUjd3M/vgbNai18oXOWj9nlTrgJlM1/2rLOIt++VLFsRcXkvg1Jp//7pcwVD8dzO96WGWdO9cfRfRXKb/7ANRdvFHL9I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [192.168.0.221] (84-115-223-216.cable.dynamic.surfer.at [84.115.223.216]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4VFTdk3BGdz3xCD; Thu, 11 Apr 2024 08:03:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1712815406; bh=DQTi/j6U26woPaUcVC66MoQ2UDtyUvZbCP6u13Taokg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=LV759QBhIYsSUx2q3IAK8bv+59pkKs3CYQVnEJvS/K9gNBPVaDp+1Tm5IM2rfyMwg 3mLLgilMn9RqaWNJ5f9mYLMBY/GLBCnyfDgILRaQ5NLCU2ljBi2+ilLGpHK4l5adyL NAkBFj6p5TpWBxKCHjIDmktE5kP4o2/QTQ6PsTY0= Message-ID: Subject: Re: [PATCH v8 1/5] Provide counted_by attribute to flexible array member field (PR108896) From: Martin Uecker To: Qing Zhao Cc: Joseph Myers , Richard Biener , Siddhesh Poyarekar , Kees Cook , "isanbard@gmail.com" , "gcc-patches@gcc.gnu.org" Date: Thu, 11 Apr 2024 08:02:47 +0200 In-Reply-To: References: <20240329160703.4012941-1-qing.zhao@oracle.com> <20240329160703.4012941-2-qing.zhao@oracle.com> <7516d9f96d842f9316b7623b6851ee32caf74264.camel@tugraz.at> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Am Mittwoch, dem 10.04.2024 um 19:35 +0000 schrieb Qing Zhao: >=20 > > On Apr 10, 2024, at 15:05, Martin Uecker wrote: > >=20 > > Am Mittwoch, dem 10.04.2024 um 20:25 +0200 schrieb Martin Uecker: > > > Am Mittwoch, dem 10.04.2024 um 17:35 +0000 schrieb Joseph Myers: > > > > On Fri, 29 Mar 2024, Qing Zhao wrote: > > > >=20 > > > > > + /* Issue error when there is a counted_by attribute with a dif= ferent > > > > > + field as the argument for the same flexible array member fi= eld. */ > > > >=20 > > > > There's another case of this to consider, though I'm not sure where= best=20 > > > > to check for it (Martin might have suggestions) - of course this ca= se will=20 > > > > need testcases as well. > > > >=20 > > > > Suppose, as allowed in C23, a structure is defined twice in the sam= e=20 > > > > scope, but the two definitions of the structure use inconsistent= =20 > > > > counted_by attributes. I'd say that, when the declarations are in = the=20 > > > > same scope (thus required to be consistent), it should be an error = for the=20 > > > > two definitions of what is meant to be the same structure to use= =20 > > > > incompatible counted_by attributes (even though the member declarat= ions=20 > > > > are otherwise the same). > > >=20 > > > I think the right place could be comp_types_attributes in > > > attributes.cc. It may be sufficient to set the > > > affects_type_identify flag. > > >=20 > > > This should then give a redefinition error as it should do for > > > "packed". > >=20 > > Thinking about this a bit more, this will not work here, because > > the counted_by attribute is not applied to the struct type but > > one of the members. > >=20 > > So probably there should be a check added directly > > to tagged_types_tu_compatible_p >=20 >=20 > There are two cases we will check: >=20 > A. Both definitions are in the same scope; > Then if the 2nd definition has a counted-by attribute different fro= m the 1st definition, the 2nd definition will be given a redefinition error= ;=20 >=20 > B. These two definitions are in different scope; > When these two definitions are used in a way need to be compatible,= an incompatible error need to be issued at that > Point; >=20 >=20 > My question is, Will the routine =E2=80=9Ctagged_types_tu_compatible_p=E2= =80=9D can handle both A and B? Yes, changing this function should address both cases if I am not missing something. Martin >=20 > Thanks. >=20 > Qing > >=20 > > Martin > >=20 > > >=20 > > > >=20 > > > > In C23 structures defined with the same tag in different scopes are= =20 > > > > compatible given requirements including compatible types for corres= ponding=20 > > > > elements. It would seem most appropriate to me for such structures= with=20 > > > > incompatible counted_by attributes to be considered *not* compatibl= e types=20 > > > > (but it would be valid to define structures with the same tag, diff= erent=20 > > > > scopes, and elements the same except for counted_by - just not to u= se them=20 > > > > in any way requiring them to be compatible). > > >=20 > > > Another option might be to warn about the case when those types > > > are then used together in a way where they are required to > > > be compatible. Then comp_types_attributes would have to return 2. > > >=20 > > >=20 > > > Martin > > >=20 > > > >=20 > > > > > +The @code{counted_by} attribute may be attached to the C99 flexi= ble array > > > > > +member of a structure. It indicates that the number of the elem= ents of the > > > > > +array is given by the field "@var{count}" in the same structure = as the > > > >=20 > > > > As noted previously, the "" quotes should be removed there (or repl= aced by=20 > > > > ``'' quotes). > > > >=20 > > >=20 > >=20 >=20