Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #pragma (packed, n) not emitting the alignment in debug info #94673

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ using namespace clang::CodeGen;

static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext &Ctx) {
auto TI = Ctx.getTypeInfo(Ty);
return TI.isAlignRequired() ? TI.Align : 0;
if (TI.isAlignRequired())
return TI.Align;

// MaxFieldAlignmentAttr is the attribute added to types
// declared after #pragma pack(n).
if (auto *Decl = Ty->getAsRecordDecl())
if (Decl->hasAttr<MaxFieldAlignmentAttr>())
return TI.Align;

return 0;
}

static uint32_t getTypeAlignIfRequired(QualType Ty, const ASTContext &Ctx) {
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/debug-info-packed-struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct layout2 {
#pragma pack()
// CHECK: l2_ofs0
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1",
// CHECK-SAME: {{.*}}size: 64, offset: 8)
// CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8)
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9",
// CHECK-SAME: {{.*}}size: 1, offset: 72, flags: DIFlagBitField, extraData: i64 72)

Expand All @@ -81,7 +81,7 @@ struct layout3 {
#pragma pack()
// CHECK: l3_ofs0
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4",
// CHECK-SAME: {{.*}}size: 64, offset: 32)
// CHECK-SAME: {{.*}}size: 64, align: 32, offset: 32)
// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12",
// CHECK-SAME: {{.*}}size: 1, offset: 96, flags: DIFlagBitField, extraData: i64 96)

Expand Down
8 changes: 8 additions & 0 deletions clang/test/CodeGenCXX/debug-info-struct-align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ struct MyType2 {
MyType2 mt2;

static_assert(alignof(MyType2) == 1, "alignof MyType2 is wrong");

#pragma pack(1)
struct MyType3 {
int m;
};
MyType3 mt3;

static_assert(alignof(MyType3) == 1, "alignof MyType3 is wrong");
Loading