[clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)
Michael Buch via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 06:05:01 PDT 2024
Michael137 wrote:
> If I'm understanding correctly, the way this currently works is that you do normal field layout, then if you discover that the actual offset of a field is less than the offset normal field layout would produce, you assume the struct is packed. This misses cases where a struct is packed, but the packing doesn't affect the offset of any of the fields. But as you note, this can't be fixed without adjusting the overall architecture.
>
> There's an issue with the current implementation: it skips fields which actually are packed, I think. Consider the following:
>
> ```
> struct Empty {};
> struct __attribute((packed)) S {
> [[no_unique_address]] Empty a,b,c,d;
> char x;
> int y;
> };
> S s;
> ```
>
> In this case, the field "y" is both overlapping, and at a packed offset. Really, you don't want to check for overlap; you want to ignore empty fields. (Non-empty fields can't overlap.)
Updated the patch to ignore empty fields instead of checking overlap with previous fields.
https://github.com/llvm/llvm-project/pull/97443
More information about the cfe-commits
mailing list