On Tue, Apr 15, 2025 at 09:05:20PM +0000, Qing Zhao wrote: > > On Apr 15, 2025, at 16:35, Kees Cook <k...@kernel.org> wrote: > > 1) When applying counted_by to pointer members, are out-of-order member > > declarations expected to be handled? As in, is this expected to be valid? > > > > struct foo { > > struct bar *p __attribute__((counted_by(count))); > > int count; > > }; > > Yes, this is valid. > Given a lone identifier, you will use “counted_by” attribute the same as the > counted_by for FAM, and this identifier will be looked up inside the > enclosing > structure. (Even when the counted_by field is AFTER the pointer). > > The patch I sent a while ago on the counted_by for pointer filed of a > structure: > https://gcc.gnu.org/pipermail/gcc-patches/2025-January/673837.html > > Have supported this without issue.
Hurray! Okay, I think that will make this quite friendly to use. > > 4) If there are type mismatches between the counted_by_expr struct > > member declaration and the later actual struct member declaration, I > > assume that will be a hard error. For example, this would fail to compile: > > > > struct foo { > > struct bar *p __attribute__((counted_by_expr(int count; count))); > > unsigned long count; > > }; > > > > Is that correct? > > I guess that the hard error will be issued when the parser sees “unsigned > long count” which > Is conflict with the previous seen “int count” inside counted_by_expr. > > But I am not sure on this. I guess the mismatch could be ignored/warned as long as the actual struct member type is used in the end. Thanks! -- Kees Cook