[clang] aligned attribute doc (PR #195278)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 7 02:04:23 PDT 2026
================
@@ -10000,3 +9983,61 @@ different languages to coexist on the same call stack while each interpreting
exceptions according to their own rules.
}];
}
+
+def AlignedDocs : Documentation {
+ let Category = DocCatDecl;
+ let Heading = "aligned";
+ let Content = [{
+The ``aligned`` attribute specifies a minimum alignment (in bytes) for a
+variable, structure field, or type definition. The attribute takes an
+optional non-negative integral constant expression. If the value is a
+power of two, the compiler ensures the declaration is aligned to at least
+that boundary; a value of zero has no effect on the alignment chosen at runtime.
+
+.. code-block:: c++
+
+ struct __attribute__((aligned(8))) S {
+ short f[3];
+ };
+
+If the alignment factor is omitted, the compiler defaults to the largest(the most strict)
+alignment supported by the target machine for any data type.
+
+Applying this attribute to a structure or union, or to one of its members, changes the type's layout
+properties. To ensure that array indexing and pointer arithmetic remain
+consistent, the compiler automatically increases the structure's total size
+(via tail padding) to a multiple of the alignment value. For example, a
+struct with a natural size of 6 bytes marked directly (or indirectly via a member declaration) with ``aligned(8)`` will be
+padded to 8 bytes.
+
+In C++, alignment requirements are inherited by derived classes. If a base
+class has an alignment specified, the derived class will honor that
+requirement to ensure the base subobject remains correctly aligned.
+
+.. code-block:: c++
+
+ struct alignas(16) Base {
----------------
Endilll wrote:
Why is this example using `alignas(16)`, but `aligned` is nowhere to be found? Is this turning into a documentation for `alignas`?
https://github.com/llvm/llvm-project/pull/195278
More information about the cfe-commits
mailing list