[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)
Jan Hendrik Farr via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 25 18:40:30 PDT 2024
Cydox wrote:
> ```
> struct S {
> int foo;
> char fam[N];
> };
> ```
>
> Well, for N = 4 we have `sizeof(struct S) == 8` and for N = 5 we have `sizeof(struct S) == 12` (due to alignment padding), therefore N = 4. That makes `s->fam[4]` out-of-bounds. Am I wrong?
Using this example, every object of sizes 8 to 11 bytes, inclusive behaves like the struct defined with N = 4. Therefore `__bdos(ptr, 0)`, where `ptr` is a pointer to a `struct S` with a `__counted_by` attribute indicating N = 4, should return 11. `__bdos(ptr, 2)` should return 8.
https://github.com/llvm/llvm-project/pull/112636
More information about the cfe-commits
mailing list