r210609 - Teach __alignof__ to look through arrays before performing the

Richard Smith richard-llvm at metafoo.co.uk
Tue Jun 10 16:43:45 PDT 2014


Author: rsmith
Date: Tue Jun 10 18:43:44 2014
New Revision: 210609

URL: http://llvm.org/viewvc/llvm-project?rev=210609&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Sema/align-x86.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=210609&r1=210608&r2=210609&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jun 10 18:43:44 2014
@@ -1328,15 +1328,6 @@ CharUnits ASTContext::getDeclAlign(const
                    MinWidth <= getTypeSize(cast<ConstantArrayType>(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<VarDecl>(D)) {
@@ -1788,6 +1779,7 @@ unsigned ASTContext::getPreferredTypeAli
   const TypedefType *TT = T->getAs<TypedefType>();
 
   // Double and long long should be naturally aligned if possible.
+  T = T->getBaseElementTypeUnsafe();
   if (const ComplexType *CT = T->getAs<ComplexType>())
     T = CT->getElementType().getTypePtr();
   if (T->isSpecificBuiltinType(BuiltinType::Double) ||

Modified: cfe/trunk/test/Sema/align-x86.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/align-x86.c?rev=210609&r1=210608&r2=210609&view=diff
==============================================================================
--- cfe/trunk/test/Sema/align-x86.c (original)
+++ cfe/trunk/test/Sema/align-x86.c Tue Jun 10 18:43:44 2014
@@ -23,6 +23,10 @@ struct __attribute__((packed)) {unsigned
 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
 





More information about the cfe-commits mailing list