]> granicus.if.org Git - clang/commit
Implement target-specific __attribute__((aligned)) value
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 21 Apr 2015 17:29:35 +0000 (17:29 +0000)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 21 Apr 2015 17:29:35 +0000 (17:29 +0000)
commitd85ab2e6f33aa0fcce3c3fed476284ab2d71d0db
tree71e14fc5539447f4c64b83b5735f96c0673a1b12
parentf8c5754967d252eaea1fa7b9597ca85923b54962
Implement target-specific __attribute__((aligned)) value

The GCC construct __attribute__((aligned)) is defined to set alignment
to "the default alignment for the target architecture" according to
the GCC documentation:

  The default alignment is sufficient for all scalar types, but may not be
  enough for all vector types on a target that supports vector operations.
  The default alignment is fixed for a particular target ABI.

clang currently hard-coded an alignment of 16 bytes for that construct,
which is correct on some platforms (including X86), but wrong on others
(including SystemZ).  Since this value is ABI-relevant, it is important
to get correct for compatibility purposes.

This patch adds a new TargetInfo member "DefaultAlignForAttributeAligned"
that targets can set to the appropriate default __attribute__((aligned))
value.

Note that I'm deliberately *not* using the existing "SuitableAlign"
value, which is used to set the pre-defined macro __BIGGEST_ALIGNMENT__,
since those two values may not be the same on all platforms.  In fact,
on X86, __attribute__((aligned)) always uses 16-byte alignment, while
__BIGGEST_ALIGNMENT__ may be larger if AVX-2 or AVX-512 are supported.
(This is actually not yet correctly implemented in clang either.)

The patch provides a value for DefaultAlignForAttributeAligned only for
SystemZ, and leaves the default for all other targets at 16, which means
no visible change in behavior on all other targets.  (The value is still
wrong for some other targets, but I'd prefer to leave it to the target
maintainers for those platforms to fix.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235397 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/ASTContext.h
include/clang/Basic/TargetInfo.h
lib/AST/ASTContext.cpp
lib/Basic/TargetInfo.cpp
lib/Basic/Targets.cpp
test/Sema/struct-packed-align.c
utils/TableGen/ClangAttrEmitter.cpp