[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:33:44 PDT 2024


Cydox wrote:

We do have to consider though that when `__bdos` is for one of the maximum types (`type & 2 == 0`), it should actually return the largest allowed object that is consistent with the count.

https://github.com/llvm/llvm-project/blob/3b88805ca20018ae202afd3aea39f4fa856a8c64/clang/docs/LanguageExtensions.rst?plain=1#L5502-L5507

So I think the correct result for `type & 2 == 0` is actually:

```C
round_up(
    alignof(struct S)
    offsetof(struct S, fam) + count * sizeof(((struct S *)0)->fam[0])
)
+ alignof(struct S) - 1
```

because all objects that are 1 byte smaller than the calculation in https://github.com/llvm/llvm-project/pull/112636#issuecomment-2436559387 plus `alignof(struct S)` are perfectly legal to have the same count.

Using that calculation for the two examples above looks to actually solve the issue: https://godbolt.org/z/Pdx7Mbano
But that's just after having a quick look at it, we gotta prove that this will actually give a result >= `struct_size` in the kernel in all cases.

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


More information about the cfe-commits mailing list