[PATCH] D107598: [AIX] "aligned" attribute should not decrease type alignment returned by __alignof__
Steven Wan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 5 15:19:20 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa91916500d67: [AIX] "aligned" attribute should not decrease type alignment returned by… (authored by stevewan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107598/new/
https://reviews.llvm.org/D107598
Files:
clang/lib/AST/ASTContext.cpp
clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
Index: clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
===================================================================
--- /dev/null
+++ clang/test/Layout/aix-alignof-align-and-pack-attr.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
+// RUN: FileCheck %s
+
+namespace test1 {
+struct __attribute__((__aligned__(2))) C {
+ double x;
+} c;
+
+// CHECK: @{{.*}}test1{{.*}}c{{.*}} = global %"struct.test1::C" zeroinitializer, align 8
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2), packed)) C {
+ double x;
+} c;
+
+// CHECK: @{{.*}}test2{{.*}}c{{.*}} = global %"struct.test2::C" zeroinitializer, align 2
+} // namespace test2
+
+namespace test3 {
+struct __attribute__((__aligned__(16))) C {
+ double x;
+} c;
+
+// CHECK: @{{.*}}test3{{.*}}c{{.*}} = global %"struct.test3::C" zeroinitializer, align 16
+} // namespace test3
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2478,11 +2478,16 @@
return ABIAlign;
if (const auto *RT = T->getAs<RecordType>()) {
- if (TI.AlignIsRequired || RT->getDecl()->isInvalidDecl())
+ const RecordDecl *RD = RT->getDecl();
+
+ // When used as part of a typedef, or together with a 'packed' attribute,
+ // the 'aligned' attribute can be used to decrease alignment.
+ if ((TI.AlignIsRequired && T->getAs<TypedefType>() != nullptr) ||
+ RD->isInvalidDecl())
return ABIAlign;
unsigned PreferredAlign = static_cast<unsigned>(
- toBits(getASTRecordLayout(RT->getDecl()).PreferredAlignment));
+ toBits(getASTRecordLayout(RD).PreferredAlignment));
assert(PreferredAlign >= ABIAlign &&
"PreferredAlign should be at least as large as ABIAlign.");
return PreferredAlign;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107598.364631.patch
Type: text/x-patch
Size: 2012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210805/2eaa0ba7/attachment.bin>
More information about the cfe-commits
mailing list