[PATCH] D124006: [DebugInfo] Use the 'getTypeAlignIfRequired' function to get DW_AT_alignment correct when attribute((__aligned__)) is present.
Ying Yi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 21 11:55:26 PDT 2022
MaggieYi updated this revision to Diff 424257.
MaggieYi added a comment.
Thanks David, I have modified the test following your advice.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124006/new/
https://reviews.llvm.org/D124006
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGenCXX/debug-info-struct-align.cpp
Index: clang/test/CodeGenCXX/debug-info-struct-align.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-struct-align.cpp
@@ -0,0 +1,27 @@
+// Test for debug info related to DW_AT_alignment attribute in the struct type.
+// RUN: %clang_cc1 -dwarf-version=5 -debug-info-kind=standalone -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType", {{.*}}, align: 32
+// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType1", {{.*}}, align: 8
+// CHECK-DAG: DICompositeType(tag: DW_TAG_structure_type, name: "MyType2", {{.*}}, align: 8
+
+struct MyType {
+ int m;
+} __attribute__((aligned(1)));
+struct MyType mt;
+
+static_assert(alignof(struct MyType) == 4, "alignof MyType is wrong");
+
+struct MyType1 {
+ int m;
+} __attribute__((packed, aligned(1)));
+struct MyType1 mt1;
+
+static_assert(alignof(struct MyType1) == 1, "alignof MyType1 is wrong");
+
+struct MyType2 {
+ __attribute__((packed)) int m;
+} __attribute__((aligned(1)));
+struct MyType2 mt2;
+
+static_assert(alignof(struct MyType2) == 1, "alignof MyType2 is wrong");
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3553,7 +3553,11 @@
return getOrCreateRecordFwdDecl(Ty, RDContext);
uint64_t Size = CGM.getContext().getTypeSize(Ty);
- auto Align = getDeclAlignIfRequired(D, CGM.getContext());
+ // __attribute__((aligned)) can increase or decrease alignment *except* on a
+ // struct or struct member, where it only increases alignment unless 'packed'
+ // is also specified. To handle this case, the `getTypeAlignIfRequired` needs
+ // to be used.
+ auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
SmallString<256> Identifier = getTypeIdentifier(Ty, CGM, TheCU);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124006.424257.patch
Type: text/x-patch
Size: 1951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220421/df56aa76/attachment.bin>
More information about the cfe-commits
mailing list