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

Reply via email to