[Lldb-commits] [lldb] [LLDB] Respect the DW_AT_alignment attribute. (PR #73307)
Haojian Wu via lldb-commits
lldb-commits at lists.llvm.org
Fri Nov 24 04:14:07 PST 2023
================
@@ -1926,12 +1930,13 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
// TypeSystemClang is always in C++ mode, but some compilers such as
// GCC and Clang give empty structs a size of 0 in C mode (in contrast to
// the size of 1 for empty structs that would be computed in C++ mode).
- if (attrs.byte_size) {
+ if (attrs.byte_size || attrs.alignment) {
clang::RecordDecl *record_decl =
TypeSystemClang::GetAsRecordDecl(clang_type);
if (record_decl) {
ClangASTImporter::LayoutInfo layout;
- layout.bit_size = *attrs.byte_size * 8;
+ layout.bit_size = attrs.byte_size.value_or(0) * 8;
+ layout.alignment = attrs.alignment.value_or(0) * 8;
----------------
hokein wrote:
> Is it because in your tests alignof(EmptyStruct) wouldn't trigger CompleteRecordType?
Yes, exactly, this is the major reason. The codepath in `CompleteRecordType` has a conditional statement `if (!layout_info.field_offsets.empty() || !layout_info.base_offsets.empty() || !layout_info.vbase_offsets.empty())` where an empty structure will never hit.
We could tweak the if condition there, but I'm less certain about it, my reading of code is that the location here seem to be responsible for empty structures (happy to change if this is not reasonable).
https://github.com/llvm/llvm-project/pull/73307
More information about the lldb-commits
mailing list