]> granicus.if.org Git - clang/commitdiff
AST: Respect alignment attributes on typedef'd arrays
authorJustin Bogner <mail@justinbogner.com>
Tue, 15 Apr 2014 20:12:41 +0000 (20:12 +0000)
committerJustin Bogner <mail@justinbogner.com>
Tue, 15 Apr 2014 20:12:41 +0000 (20:12 +0000)
When instantiating an array that has an alignment attribute on it, we
were looking through the array type and only considering the element
type for the resulting alignment. We need to make sure we take the
array's requirements into account too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206317 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
test/Sema/attr-aligned.c

index 0f3809d538d66e976521835ee2ea0df7364c7842..8a60bebd57a1c0bfc45b283803481f8eabda1452 100644 (file)
@@ -1322,7 +1322,9 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool ForAlignof) const {
             Align = std::max(Align, Target->getLargeArrayAlign());
         }
 
-        // Walk through any array types while we're at it.
+        // Keep track of extra alignment requirements on the array itself, then
+        // work with the element type.
+        Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr()));
         T = getBaseElementType(arrayType);
       }
       Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr()));
index ad59357658669854a53a074a54775a922dae5fdd..0a2698ec91afdd145c3fd58a15d0995b349b1cf6 100644 (file)
@@ -43,3 +43,14 @@ struct E { int member __attribute__((aligned(2))); } __attribute__((packed));
 struct E e;
 char e1[__alignof__(e) == 2 ?: -1] = {0};
 char e2[__alignof__(e.member) == 2 ?: -1] = {0};
+
+typedef char overaligned_char __attribute__((aligned(16)));
+typedef overaligned_char array_with_overaligned_char[11];
+typedef char array_with_align_attr[11] __attribute__((aligned(16)));
+
+char f0[__alignof__(array_with_overaligned_char) == 16 ? 1 : -1] = { 0 };
+char f1[__alignof__(array_with_align_attr) == 16 ? 1 : -1] = { 0 };
+array_with_overaligned_char F2;
+char f2[__alignof__(F2) == 16 ? 1 : -1] = { 0 };
+array_with_align_attr F3;
+char f3[__alignof__(F3) == 16 ? 1 : -1] = { 0 };