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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 7 12:32:07 PDT 2024


https://github.com/efriedma-quic commented:

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.)

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


More information about the cfe-commits mailing list