llvm-project
ac131eb4 - [Clang][CodeGen] Fix C++20 NTTP object field indexing (#204174)

Commit
17 days ago
[Clang][CodeGen] Fix C++20 NTTP object field indexing (#204174) C++20 allows a class object to be used as a non-type template parameter. For example, a template can take an object of a struct like `{ char A; long long B; char C; char First[2]; char Second[2]; }`. That struct has padding before `B`. The constant emitter can represent the value with an ordinary LLVM struct and let LLVM provide that padding implicitly. Normal record CodeGen instead uses the memory type for the record, which may contain explicit padding fields so C++ fields have stable LLVM field numbers. The bytes are laid out the same, but the LLVM field numbers are not. For the normal padded record type, `First` has one field index. For the compact constant type, that same index names a later field. Clang was computing the field index for the padded record type, then applying it to the compact template parameter object type. As a result, reading `First` could read from the bytes for `Second` instead. Return the template parameter object address using the normal memory type for the record. This makes the field index apply to the type it was computed for, so field access uses the same layout as an ordinary object. The constant data itself stays the same.
Author
Parents
Loading