[PATCH] D148381: [WIP][Clang] Add counted_by attribute
Bill Wendling via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 29 16:54:21 PDT 2023
void added a comment.
In D148381#4626229 <https://reviews.llvm.org/D148381#4626229>, @serge-sans-paille wrote:
> Jumping a bit late in the thread, apologize in advance if I missed something.
>
> The GCC version of the attributes seems to be `element_count` (as found in the link https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896 mentionned by @kees) I guess we could align (I personally prefer the GCC name, FWIW)
Qing Zhao has been sending out patches to gcc-patches@, so I've been trying to follow those as much as possible. I plan to go through my implementation to ensure that I copy hers as much as possible. See the thread here: https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626376.html
> I may be wrong , but it seems to me that there is nothing specific to FAM there, and this would work as well for
>
> struct foo {
> size_t num_elements;
> // ...
> struct bar ** data __attribute__((counted_by(num_elements)));
> };
>
> struct foo make_foo(size_t num_elements) {
> struct foo f;
> f.data = malloc(num_elements *
> sizeof(struct bar *));
>
> f.num_elements = num_elements;
> return f;
> }
>
> Which makes us very close to:
>
> void stuff(int n, int *data __attribute__((counted_by(n)))) {
> for(int i = 0; i < n; ++i)
> other_stuff(data[i]);
> }
>
> which is very close to VLA, right?
Yeah. It could definitely be extended to the Apple RFC (which is similar to your example).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148381/new/
https://reviews.llvm.org/D148381
More information about the cfe-commits
mailing list