[PATCH] D46439: Fix incorrect packed aligned structure layout

Momchil Velikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 8 07:26:21 PDT 2018


chill updated this revision to Diff 145687.

https://reviews.llvm.org/D46439

Files:
  lib/Sema/SemaDecl.cpp
  test/Layout/itanium-pack-and-align.cpp


Index: test/Layout/itanium-pack-and-align.cpp
===================================================================
--- /dev/null
+++ test/Layout/itanium-pack-and-align.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only -fdump-record-layouts %s \
+// RUN:            | FileCheck %s
+
+struct S {
+  char x;
+  int y;
+} __attribute__((packed, aligned(8)));
+
+struct alignas(8) T {
+  char x;
+  int y;
+} __attribute__((packed));
+
+S s;
+T t;
+// CHECK:          0 | struct T
+// CHECK-NEXT:          0 |   char x
+// CHECK-NEXT:          1 |   int y
+// CHECK-NEXT:            | [sizeof=8, dsize=8, align=8,
+// CHECK-NEXT:            |  nvsize=8, nvalign=8]
+
+// CHECK:          0 | struct S
+// CHECK-NEXT:          0 |   char x
+// CHECK-NEXT:          1 |   int y
+// CHECK-NEXT:            | [sizeof=8, dsize=8, align=8,
+// CHECK-NETX:            |  nvsize=8, nvalign=8]
Index: lib/Sema/SemaDecl.cpp
===================================================================
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -15573,6 +15573,10 @@
     if (!Completed)
       Record->completeDefinition();
 
+    // Handle attributes before checking the layout.
+    if (Attr)
+      ProcessDeclAttributeList(S, Record, Attr);
+
     // We may have deferred checking for a deleted destructor. Check now.
     if (CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(Record)) {
       auto *Dtor = CXXRecord->getDestructor();
@@ -15703,9 +15707,6 @@
       CDecl->setIvarRBraceLoc(RBrac);
     }
   }
-
-  if (Attr)
-    ProcessDeclAttributeList(S, Record, Attr);
 }
 
 /// \brief Determine whether the given integral value is representable within


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46439.145687.patch
Type: text/x-patch
Size: 1684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180508/9dbbdac8/attachment.bin>


More information about the cfe-commits mailing list