kees wrote: > Consider this example. It tries to illustrate why putting `__counted_by()` on > a pointer to a structs containing flexible array members doesn't make sense. > > ```c > struct HasFAM { > int count; > char buffer[] __counted_by(count); // This is OK > }; > > struct BufferOfFAMS { > int count; > struct HasFAM* fams __counted_by(count); // This is invalid > }; > ```
Agreed: structs with flexible array members must be considered to be singletons. This property is actually important for being able to have `__builtin_dynamic_object_size()` work on pointers to flexible array structs. i.e.: ``` size_t func(struct foo *p) { return__builtin_dynamic_object_size(p, 0); } ``` This must always return `SIZE_MAX` for fixed-size arrays since the pointer may be in the middle of a larger array of `struct foo`s, but if it is a struct with a flexible array marked with `counted_by`, then we know deterministically what the size is, since it must be a single complete object. https://github.com/llvm/llvm-project/pull/90786 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits