[clang] 806ff3c - [AIX] Check for typedef properly when getting preferred type align

Steven Wan via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 8 13:22:14 PDT 2021


Author: Steven Wan
Date: 2021-09-08T16:21:52-04:00
New Revision: 806ff3c4a42c7393a0bbeab3dd1c0295f61ad457

URL: https://github.com/llvm/llvm-project/commit/806ff3c4a42c7393a0bbeab3dd1c0295f61ad457
DIFF: https://github.com/llvm/llvm-project/commit/806ff3c4a42c7393a0bbeab3dd1c0295f61ad457.diff

LOG: [AIX] Check for typedef properly when getting preferred type align

The current check for typedef is naive and doesn't deal with any convoluted cases. This patch makes use of the new 'AlignRequirement' enum field from 'TypeInfo' to determine whether or not this is an 'aligned' attribute on a typedef.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D109387

Added: 
    

Modified: 
    clang/lib/AST/ASTContext.cpp
    clang/test/Layout/aix-power-alignment-typedef-2.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index dc19dd6959049..74af9f869d084 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -2497,8 +2497,10 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const {
     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.isAlignRequired() && T->getAs<TypedefType>() != nullptr) ||
+    // the 'aligned' attribute can be used to decrease alignment. Note that the
+    // 'packed' case is already taken into consideration when computing the
+    // alignment, we only need to handle the typedef case here.
+    if (TI.AlignRequirement == AlignRequirementKind::RequiredByTypedef ||
         RD->isInvalidDecl())
       return ABIAlign;
 

diff  --git a/clang/test/Layout/aix-power-alignment-typedef-2.cpp b/clang/test/Layout/aix-power-alignment-typedef-2.cpp
index 8e7e3db47c602..b814be9c06cff 100644
--- a/clang/test/Layout/aix-power-alignment-typedef-2.cpp
+++ b/clang/test/Layout/aix-power-alignment-typedef-2.cpp
@@ -4,12 +4,26 @@
 // RUN: %clang_cc1 -triple powerpc64-ibm-aix-xcoff -S -emit-llvm -x c++ < %s | \
 // RUN:   FileCheck %s
 
-struct C {
+namespace test1 {
+struct S {
   double x;
 };
 
-typedef struct C __attribute__((__aligned__(2))) CC;
+typedef struct S __attribute__((__aligned__(2))) SS;
 
-CC cc;
+SS ss;
 
-// CHECK: @cc = global %struct.C zeroinitializer, align 2
+// CHECK: @{{.*}}test1{{.*}}ss{{.*}} = global %"struct.test1::S" zeroinitializer, align 2
+} // namespace test1
+
+namespace test2 {
+struct __attribute__((__aligned__(2))) S {
+  double x;
+};
+
+typedef struct S SS;
+
+SS ss;
+
+// CHECK: @{{.*}}test2{{.*}}ss{{.*}} = global %"struct.test2::S" zeroinitializer, align 8
+} // namespace test2


        


More information about the cfe-commits mailing list