[Lldb-commits] [clang] [lldb] [clang][lldb] Don't assert structure layout correctness for layouts provided by LLDB (PR #93809)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 17 04:52:58 PDT 2024


Michael137 wrote:

> > > The correct answer here is probably to fix the sizes in the RecordLayout itself; in particular, the DataSize of the members.
> > 
> > 
> > That would be ideal, but also means we'd have to reflect the various C++ attributes that affect layout in DWARF. Avoiding adding such language-specific constructs to DWARF is what partly motivated this patch.
> 
> Given the offsets and sizes of the members of a struct, you can compute the datasize as the offset plus the size of the last member. That isn't really correct for POD structs, but the CGRecordLayout won't care: it can't tell the difference between padding that's illegal to reuse, vs. padding that the frontend chose not to reuse for some other reason.

Just got back to looking at this again. Haven't fully figured out yet why the AST and LLVM layouts in the LLDB case don't seem to be consistent. Though the asserts that iterate over `Members` and `FieldTypes` fail because those structures are filled out conditionally on `isZeroSize()` (which in the LLDB case won't work because we don't have that information in the AST, i.e., the `[[no_unique_address]]` attribute).

Interestingly, I only just found out about the `-foverride-record-layout=` flag, which seems like a neat way of testing externally provided layouts. I compiled the test attached to this patch but using the layout that LLDB computes. Then compared the `dump-record-layouts` output to the one that Clang generates without externally provided layouts.

```
$ ./bin/clang -cc1 ~/Git/llvm-project/clang/test/CodeGenCXX/override-layout-no_unique_address.cpp -w -std=c++14 -fdump-record-layouts-simple -DNUA= -foverride-record-layout=nua.lldb > nua.lldb.after                
michaelbuch at Michaels-MacBook-Pro-6:~/Git/lldb-build-main-rel
$ diff nua.lldb.after nua.before 
52c52
<   Alignment:8
---
>   Alignment:64
```
Interestingly the only difference here is the alignment computed for `Foo`.

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


More information about the lldb-commits mailing list