chill created this revision. chill added reviewers: rsmith, aaron.ballman. Executing the following program
#include <cassert> #include <cstddef> struct S { char x; int y; } __attribute__((packed, aligned(8))); struct alignas(8) T { char x; int y; } __attribute__((packed)); int main() { assert(offsetof(S, x) == 0); assert(offsetof(S, y) == 1); assert(offsetof(T, x) == 0); assert(offsetof(T, y) == 1); } fails with assertion a.out: a.cc:19: int main(): Assertion `offsetof(T, y) == 1' failed. The layout if `T` is incorrect, because it's computed and effectively cached when checking for `alignas` under-aligning the structure, however, this happens before `__attribute__((packed))` is processed. This patch moves the processing of attributes before the `alignas` under-alignment check. Repository: rC Clang https://reviews.llvm.org/D46439 Files: lib/Sema/SemaDecl.cpp 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 for alignas underalignment. + 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
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 for alignas underalignment. + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits