Author: chill Date: Mon May 21 07:28:43 2018 New Revision: 332843 URL: http://llvm.org/viewvc/llvm-project?rev=332843&view=rev Log: [Sema] Fix incorrect packed aligned structure layout
Handle attributes before checking the record layout (e.g. underalignment check during `alignas` processing), as layout may be cached without taking into account attributes that may affect it. Differential Revision: https://reviews.llvm.org/D46439 Added: cfe/trunk/test/Layout/itanium-pack-and-align.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp Modified: cfe/trunk/lib/Sema/SemaDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=332843&r1=332842&r2=332843&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDecl.cpp (original) +++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 21 07:28:43 2018 @@ -15594,6 +15594,10 @@ void Sema::ActOnFields(Scope *S, SourceL 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(); @@ -15724,9 +15728,6 @@ void Sema::ActOnFields(Scope *S, SourceL CDecl->setIvarRBraceLoc(RBrac); } } - - if (Attr) - ProcessDeclAttributeList(S, Record, Attr); } /// Determine whether the given integral value is representable within Added: cfe/trunk/test/Layout/itanium-pack-and-align.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Layout/itanium-pack-and-align.cpp?rev=332843&view=auto ============================================================================== --- cfe/trunk/test/Layout/itanium-pack-and-align.cpp (added) +++ cfe/trunk/test/Layout/itanium-pack-and-align.cpp Mon May 21 07:28:43 2018 @@ -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] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits