[Lldb-commits] [clang] [lldb] [clang][RecordLayoutBuilder] Be stricter about inferring packed-ness in ExternalLayouts (PR #97443)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 9 09:16:32 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.)

Good point, we would still infer packedness in this example, but for the wrong reasons.

Skipping empty fields does seem like a better heuristic here

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


More information about the lldb-commits mailing list