summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMomchil Velikov <momchil.velikov@arm.com>2018-05-21 14:28:43 +0000
committerMomchil Velikov <momchil.velikov@arm.com>2018-05-21 14:28:43 +0000
commitfe76b36ab1286a1248e7a302dcca4245e91714ad (patch)
treeac1579496b7f8fe815c4e2374ad63a7c1199d24c
parent86188d8a404093c37b7b63515aaf223d5aa4d113 (diff)
downloadbcm5719-llvm-fe76b36ab1286a1248e7a302dcca4245e91714ad.tar.gz
bcm5719-llvm-fe76b36ab1286a1248e7a302dcca4245e91714ad.zip
[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 llvm-svn: 332843
-rw-r--r--clang/lib/Sema/SemaDecl.cpp7
-rw-r--r--clang/test/Layout/itanium-pack-and-align.cpp26
2 files changed, 30 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9a1ab4a3c58..e8e3faf7578 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -15594,6 +15594,10 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
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, SourceLocation RecLoc, Decl *EnclosingDecl,
CDecl->setIvarRBraceLoc(RBrac);
}
}
-
- if (Attr)
- ProcessDeclAttributeList(S, Record, Attr);
}
/// Determine whether the given integral value is representable within
diff --git a/clang/test/Layout/itanium-pack-and-align.cpp b/clang/test/Layout/itanium-pack-and-align.cpp
new file mode 100644
index 00000000000..64569168e47
--- /dev/null
+++ b/clang/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]
OpenPOWER on IntegriCloud