[clang] [Clang] Disable use of the counted_by attribute for whole struct pointers (PR #112636)

Tavian Barnes via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 29 09:01:07 PDT 2024


tavianator wrote:

> The expression can be simplified to ... As the padding at the end of the structure is always smaller than the alignof. So `round_up(alignof(struct S), offsetof(struct S, fam)) = sizeof(struct S)`

I think that's right for sane ABIs.  I assume Clang always lays structs out like this.

My use of `max(sizeof(struct S))` was to support pathological compilers that add unnecessary padding.  But it doesn't completely handle pathological compilers, since they may also pad

```c
struct S {
    int foo;
    char fam[N];
};
```

unnecessarily and you can't really predict that.  Ignoring that case, your simplification seems fine to me.

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


More information about the cfe-commits mailing list