diff options
| author | Justin Bogner <mail@justinbogner.com> | 2014-04-15 20:12:41 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2014-04-15 20:12:41 +0000 |
| commit | 399093276c9af10ab1afe5740f11fc90eed7ae63 (patch) | |
| tree | f82a554ec527d2f4daf4c2904e8dcfd050e8c35a /clang | |
| parent | aac2eac4c2dbf8b6b611082a7c63884014c9d697 (diff) | |
| download | bcm5719-llvm-399093276c9af10ab1afe5740f11fc90eed7ae63.tar.gz bcm5719-llvm-399093276c9af10ab1afe5740f11fc90eed7ae63.zip | |
AST: Respect alignment attributes on typedef'd arrays
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.
llvm-svn: 206317
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 4 | ||||
| -rw-r--r-- | clang/test/Sema/attr-aligned.c | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 0f3809d538d..8a60bebd57a 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -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())); diff --git a/clang/test/Sema/attr-aligned.c b/clang/test/Sema/attr-aligned.c index ad593576586..0a2698ec91a 100644 --- a/clang/test/Sema/attr-aligned.c +++ b/clang/test/Sema/attr-aligned.c @@ -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 }; |

