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

Steven Wan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 8 12:34:43 PDT 2021


stevewan updated this revision to Diff 371418.
stevewan added a comment.

Add test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109387/new/

https://reviews.llvm.org/D109387

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


Index: clang/test/Layout/aix-power-alignment-typedef-2.cpp
===================================================================
--- clang/test/Layout/aix-power-alignment-typedef-2.cpp
+++ 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
Index: clang/lib/AST/ASTContext.cpp
===================================================================
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -2497,8 +2497,10 @@
     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;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109387.371418.patch
Type: text/x-patch
Size: 1769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210908/6f6e7701/attachment.bin>


More information about the cfe-commits mailing list