[PATCH] D107394: [AIX] "aligned" attribute does not decrease alignment
Steven Wan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 12 11:24:33 PDT 2021
stevewan updated this revision to Diff 366051.
stevewan added a comment.
Rebase to latest main
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107394/new/
https://reviews.llvm.org/D107394
Files:
clang/lib/AST/RecordLayoutBuilder.cpp
clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===================================================================
--- clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -27,3 +27,23 @@
// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
} // namespace test3
+
+namespace test4 {
+struct C {
+ struct CC {
+ long double ld;
+ } __attribute__((aligned(2))) cc;
+} c;
+
+// CHECK: @{{.*}}test4{{.*}}c{{.*}} = global %"struct.test4::C" zeroinitializer, align 8
+} // namespace test4
+
+namespace test5 {
+struct C {
+ struct CC {
+ long double ld;
+ } __attribute__((aligned(2), packed)) cc;
+} c;
+
+// CHECK: @{{.*}}test5{{.*}}c{{.*}} = global %"struct.test5::C" zeroinitializer, align 2
+} // namespace test5
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===================================================================
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -1968,6 +1968,12 @@
}
}
+ const Type *Ty = D->getType()->getBaseElementTypeUnsafe();
+ // When used as part of a typedef, the 'aligned' attribute can be used to
+ // decrease alignment.
+ bool AlignAttrCanDecreaseAlignment =
+ AlignIsRequired && Ty->getAs<TypedefType>() != nullptr;
+
// The AIX `power` alignment rules apply the natural alignment of the
// "first member" if it is of a floating-point data type (or is an aggregate
// whose recursively "first" member or element is such a type). The alignment
@@ -1978,7 +1984,7 @@
// and zero-width bit-fields count as prior members; members of empty class
// types marked `no_unique_address` are not considered to be prior members.
CharUnits PreferredAlign = FieldAlign;
- if (DefaultsToAIXPowerAlignment && !AlignIsRequired &&
+ if (DefaultsToAIXPowerAlignment && !AlignAttrCanDecreaseAlignment &&
(FoundFirstNonOverlappingEmptyFieldForAIX || IsNaturalAlign)) {
auto performBuiltinTypeAlignmentUpgrade = [&](const BuiltinType *BTy) {
if (BTy->getKind() == BuiltinType::Double ||
@@ -1989,7 +1995,6 @@
}
};
- const Type *Ty = D->getType()->getBaseElementTypeUnsafe();
if (const ComplexType *CTy = Ty->getAs<ComplexType>()) {
performBuiltinTypeAlignmentUpgrade(CTy->getElementType()->castAs<BuiltinType>());
} else if (const BuiltinType *BTy = Ty->getAs<BuiltinType>()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107394.366051.patch
Type: text/x-patch
Size: 2454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210812/20e2b8b2/attachment.bin>
More information about the cfe-commits
mailing list