https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116983
Bug ID: 116983 Summary: counted_by not used to identify singleton pointers Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: kees at outflux dot net Target Milestone: --- When counted_by is present in a structure, it means that the object must be a singleton. For example: struct counted { int counter; int array[] __attribute__((counted_by(counter))); }; struct notcounted { int counter; int array[]; }; void __attribute__((noinline)) emit_length(size_t length) { printf("%zu\n", length); } // This correctly cannot know size of p object, and returns SIZE_MAX void objsize_notcounted(struct notcounted *p) { emit_length(__builtin_dynamic_object_size(p, 1)); } // This must be operating on a singleton, therefor the // return must be: // max(sizeof(*p), // sizeof(*p) + offsetof(typeof(*p), array) * p->counter) void objsize_counted(struct counted *p) { emit_length(__builtin_dynamic_object_size(p, 1)); }