[clang] [CodeGen] Revamp counted_by calculations (PR #70606)
Yeoul Na via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 2 18:25:43 PDT 2023
rapidsna wrote:
```
#include <stdio.h>
#include <stdlib.h>
struct flex {
int c;
int fam[] __attribute__((counted_by(c)));
};
int main() {
struct flex *p = (struct flex *)malloc(sizeof(struct flex) + sizeof(int) * 10);
p->c = 100;
printf("%lu\n", __builtin_dynamic_object_size(&p->fam[0], 0)); // 40 : size from malloc, but it only contains the array part. Shouldn't it be 44 to include the entire object size?
printf("%lu\n", __builtin_dynamic_object_size(&p->fam[0], 1)); // 40 : size from malloc;
printf("%lu\n", __builtin_dynamic_object_size(p, 0)); // 404 : size from counted_by
}
```
@bwendling It could be tracked as a separate issue, but there seems to be some inconsistencies in where bdos is derived from. For `p` it seems the counted_by wins over malloc. But for `&->fam[0]` malloc seems to win.
https://godbolt.org/z/G7WfY4faE
https://github.com/llvm/llvm-project/pull/70606
More information about the cfe-commits
mailing list