From: Richard Smith Date: Tue, 10 Jun 2014 23:43:44 +0000 (+0000) Subject: Teach __alignof__ to look through arrays before performing the X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d7e1fe40e15ea5e077628daf6b742bb69eab65a7;p=platform%2Fupstream%2Fllvm.git Teach __alignof__ to look through arrays before performing the preferred-alignment transformations. Corrects alignof(T[]) to return alignof(T) in all cases, as required by relevant standards. llvm-svn: 210609 --- diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index f78f2a9..eaf77e9 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1328,15 +1328,6 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const { MinWidth <= getTypeSize(cast(arrayType))) Align = std::max(Align, Target->getLargeArrayAlign()); } - - // Keep track of extra alignment requirements on the array itself, then - // work with the element type. - // - // FIXME: Computing the preferred type alignment for the array element - // type should not be necessary, but getPreferredTypeAlign returns the - // wrong thing in some cases (such as 'long long[]' on x86_64). - Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); - T = BaseT; } Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr())); if (const VarDecl *VD = dyn_cast(D)) { @@ -1788,6 +1779,7 @@ unsigned ASTContext::getPreferredTypeAlign(const Type *T) const { const TypedefType *TT = T->getAs(); // Double and long long should be naturally aligned if possible. + T = T->getBaseElementTypeUnsafe(); if (const ComplexType *CT = T->getAs()) T = CT->getElementType().getTypePtr(); if (T->isSpecificBuiltinType(BuiltinType::Double) || diff --git a/clang/test/Sema/align-x86.c b/clang/test/Sema/align-x86.c index 6b93a48..f112c63 100644 --- a/clang/test/Sema/align-x86.c +++ b/clang/test/Sema/align-x86.c @@ -23,6 +23,10 @@ struct __attribute__((packed)) {unsigned int a;} g4; short chk1[__alignof__(g4) == 1 ? 1 : -1]; short chk2[__alignof__(g4.a) == 1 ? 1 : -1]; +double g6[3]; +short chk1[__alignof__(g6) == 8 ? 1 : -1]; +short chk2[__alignof__(double[3]) == 8 ? 1 : -1]; + // PR5637