From: Qing Zhao <qing.zhao@oracle.com>
To: Martin Uecker <uecker@tugraz.at>
Cc: Joseph Myers <josmyers@redhat.com>,
Richard Biener <richard.guenther@gmail.com>,
Siddhesh Poyarekar <siddhesh@gotplt.org>,
Kees Cook <keescook@chromium.org>,
"isanbard@gmail.com" <isanbard@gmail.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH v8 1/5] Provide counted_by attribute to flexible array member field (PR108896)
Date: Wed, 10 Apr 2024 19:35:24 +0000 [thread overview]
Message-ID: <C8622293-8E06-4E2F-BE40-17C16C96FF14@oracle.com> (raw)
In-Reply-To: <c2241a32cd1617cee0a83548ea62fddb288ed661.camel@tugraz.at>
> On Apr 10, 2024, at 15:05, Martin Uecker <uecker@tugraz.at> wrote:
>
> 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:
>>>
>>>> + /* Issue error when there is a counted_by attribute with a different
>>>> + field as the argument for the same flexible array member field. */
>>>
>>> There's another case of this to consider, though I'm not sure where best
>>> to check for it (Martin might have suggestions) - of course this case will
>>> need testcases as well.
>>>
>>> Suppose, as allowed in C23, a structure is defined twice in the same
>>> scope, but the two definitions of the structure use inconsistent
>>> counted_by attributes. I'd say that, when the declarations are in the
>>> same scope (thus required to be consistent), it should be an error for the
>>> two definitions of what is meant to be the same structure to use
>>> incompatible counted_by attributes (even though the member declarations
>>> are otherwise the same).
>>
>> I think the right place could be comp_types_attributes in
>> attributes.cc. It may be sufficient to set the
>> affects_type_identify flag.
>>
>> This should then give a redefinition error as it should do for
>> "packed".
>
> 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.
>
> So probably there should be a check added directly
> to tagged_types_tu_compatible_p
There are two cases we will check:
A. Both definitions are in the same scope;
Then if the 2nd definition has a counted-by attribute different from the 1st definition, the 2nd definition will be given a redefinition error;
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;
My question is, Will the routine “tagged_types_tu_compatible_p” can handle both A and B?
Thanks.
Qing
>
> Martin
>
>>
>>>
>>> In C23 structures defined with the same tag in different scopes are
>>> compatible given requirements including compatible types for corresponding
>>> elements. It would seem most appropriate to me for such structures with
>>> incompatible counted_by attributes to be considered *not* compatible types
>>> (but it would be valid to define structures with the same tag, different
>>> scopes, and elements the same except for counted_by - just not to use them
>>> in any way requiring them to be compatible).
>>
>> 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.
>>
>>
>> Martin
>>
>>>
>>>> +The @code{counted_by} attribute may be attached to the C99 flexible array
>>>> +member of a structure. It indicates that the number of the elements of the
>>>> +array is given by the field "@var{count}" in the same structure as the
>>>
>>> As noted previously, the "" quotes should be removed there (or replaced by
>>> ``'' quotes).
>>>
>>
>
next prev parent reply other threads:[~2024-04-10 19:36 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-29 16:06 [PATCH v8 0/5] New attribute "counted_by" to annotate bounds for C99 FAM(PR108896) Qing Zhao
2024-03-29 16:06 ` [PATCH v8 1/5] Provide counted_by attribute to flexible array member field (PR108896) Qing Zhao
2024-04-10 17:35 ` Joseph Myers
2024-04-10 18:05 ` Qing Zhao
2024-04-10 18:44 ` Joseph Myers
2024-04-10 19:21 ` Qing Zhao
2024-04-10 21:56 ` Joseph Myers
2024-04-11 13:17 ` Qing Zhao
2024-04-10 18:25 ` Martin Uecker
2024-04-10 19:05 ` Martin Uecker
2024-04-10 19:35 ` Qing Zhao [this message]
2024-04-11 6:02 ` Martin Uecker
2024-04-11 13:16 ` Qing Zhao
2024-03-29 16:07 ` [PATCH v8 2/5] Convert references with "counted_by" attributes to/from .ACCESS_WITH_SIZE Qing Zhao
2024-04-10 18:36 ` Joseph Myers
2024-04-10 19:38 ` Qing Zhao
2024-04-11 13:27 ` Qing Zhao
2024-03-29 16:07 ` [PATCH v8 3/5] Use the .ACCESS_WITH_SIZE in builtin object size Qing Zhao
2024-04-10 21:45 ` Siddhesh Poyarekar
2024-04-11 13:19 ` Qing Zhao
2024-03-29 16:07 ` [PATCH v8 4/5] Use the .ACCESS_WITH_SIZE in bound sanitizer Qing Zhao
2024-04-10 18:37 ` Joseph Myers
2024-04-10 21:46 ` Siddhesh Poyarekar
2024-04-11 13:22 ` Qing Zhao
2024-03-29 16:07 ` [PATCH v8 5/5] Add the 6th argument to .ACCESS_WITH_SIZE Qing Zhao
2024-04-10 18:38 ` Joseph Myers
2024-04-10 21:48 ` Siddhesh Poyarekar
2024-04-11 13:24 ` Qing Zhao
2024-03-29 18:09 ` [PATCH v8 0/5] New attribute "counted_by" to annotate bounds for C99 FAM(PR108896) Tom Tromey
2024-03-29 19:16 ` Kees Cook
2024-03-29 19:58 ` Qing Zhao
2024-03-30 0:16 ` Tom Tromey
2024-03-30 0:15 ` Tom Tromey
2024-03-30 13:57 ` Kees Cook
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=C8622293-8E06-4E2F-BE40-17C16C96FF14@oracle.com \
--to=qing.zhao@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=isanbard@gmail.com \
--cc=josmyers@redhat.com \
--cc=keescook@chromium.org \
--cc=richard.guenther@gmail.com \
--cc=siddhesh@gotplt.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).