[clang] [CodeGen] Revamp counted_by calculations (PR #70606)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 17:08:53 PDT 2023


rapidsna wrote:

> @kees, @nickdesaulniers, @rapidsna, and @apple-fcloutier Should this feature support a `__bdos` to an address inside the FAM?
> 
> ```
> #include <stdio.h>
> #include <stdlib.h>
> 
> struct flex {
>         double dummy;
>         char count;
>         char fam[] __attribute__((counted_by(count)));
> };
> 
> int main() {
>         struct flex *f = malloc(sizeof(struct flex) + 42 * sizeof(char));
> 
>         f->count = 42;
>         printf("__bdos(&f->fam[3], 1) == %lu\n", __builtin_dynamic_object_size(&f->fam[3], 1));
>         return 0;
> }
> ```

Supporting it similar to how const-sized arrays are currently handled makes sense to me.

https://github.com/llvm/llvm-project/pull/70606


More information about the cfe-commits mailing list