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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to