https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016
--- Comment #38 from qinzhao at gcc dot gnu.org --- (In reply to Bill Wendling from comment #37) > I realized my error after sending this. So yeah it's not going to work. I'm > okay with what's being discussed. I just want to make it clear to the > programmer that it's _possible_ that the builtin may become a no-op and they > need to handle that, which will be DCE'ed if the attribute exists, etc. As mentioned in the previous comment, I think that separating the attribute checking from the functionality of the new "__builtin_get_counted_by (PTR)" is reasonable, and make the new builtin even more simpler and cleaner. that's a good idea. GCC's current __builtin_has_attribute should be available to be used by the programmer in their source code. Does CLANG provide a similar builtin currently? > That does make me wonder at the usefulness of this feature. The user will > need to set the count whether or not this builtin is used (either because > 'counted_by' wasn't specified or the compiler couldn't find the COUNT > variable for some reason (a compiler bug, but still...)). Isn't that > basically creating a feature useful for only this specific use case? I think that this new builtin (actually a new C keyword) is useful to be provided to the user to help the programming experience when using the new attribute "counted_by", two basic use cases are described in comment #1, and #31. currently, there is a GCC patch being proposed recently https://gcc.gnu.org/pipermail/gcc-patches/2024-July/658483.html c: Add _Lengthof operator >From my understanding, the new __builtin_get_counted_by serves similar functionality as this potential future new C operator, but for flexiable array members or (later) pointers if we extend the counted-by to pointers.