[llvm] eb70253 - [LangRef/DataLayout] Spell out requirements for alignment values (#104705)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 6 10:08:56 PDT 2025
Author: Sergei Barannikov
Date: 2025-04-06T20:08:52+03:00
New Revision: eb70253fcbe57c7cb3c309c06b94b05f2eab314d
URL: https://github.com/llvm/llvm-project/commit/eb70253fcbe57c7cb3c309c06b94b05f2eab314d
DIFF: https://github.com/llvm/llvm-project/commit/eb70253fcbe57c7cb3c309c06b94b05f2eab314d.diff
LOG: [LangRef/DataLayout] Spell out requirements for alignment values (#104705)
For 'p' the added wording matches the implementation.
For 'i', 'f', 'v' the implementation also allows 0 for `<pref>`
component, making 'i16:16:0' valid, for example. 'Fi0', 'Fn0' and 'S0'
are also currently accepted. This is likely unintentional. There are no
tests in the codebase that rely on this behavior, so the added wording
prohibits zero alignments for these specifications.
For 'a', the implementation currently allows 0 for both `<abi>` and
`<pref>` components. The added wording prohibits specifying zero for
`<pref>` with the same justification as above. Zero `<abi>` is used in
tests, and the example at the end of the section suggests that this is
valid, so that's left unchanged.
This effectively prohibits zero alignments everywhere except for the
`<abi>` component of aggregate specification.
Added:
Modified:
llvm/docs/LangRef.rst
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index d242c945816cc..d462609fa0c52 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -3109,8 +3109,7 @@ as follows:
``S<size>``
Specifies the natural alignment of the stack in bits. Alignment
promotion of stack variables is limited to the natural stack
- alignment to avoid dynamic stack realignment. The stack alignment
- must be a multiple of 8-bits. If omitted, the natural stack
+ alignment to avoid dynamic stack realignment. If omitted, the natural stack
alignment defaults to "unspecified", which does not prevent any
alignment promotions.
``P<address space>``
@@ -3136,8 +3135,8 @@ as follows:
Defaults to the default address space of 0.
``p[n]:<size>:<abi>[:<pref>][:<idx>]``
This specifies the *size* of a pointer and its ``<abi>`` and
- ``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional
- and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the
+ ``<pref>``\erred alignments for address space ``n``.
+ The fourth parameter ``<idx>`` is the size of the
index that used for address calculation, which must be less than or equal
to the pointer size. If not
specified, the default index size is equal to the pointer size. All sizes
@@ -3147,23 +3146,21 @@ as follows:
``i<size>:<abi>[:<pref>]``
This specifies the alignment for an integer type of a given bit
``<size>``. The value of ``<size>`` must be in the range [1,2^24).
- ``<pref>`` is optional and defaults to ``<abi>``.
For ``i8``, the ``<abi>`` value must equal 8,
that is, ``i8`` must be naturally aligned.
``v<size>:<abi>[:<pref>]``
This specifies the alignment for a vector type of a given bit
``<size>``. The value of ``<size>`` must be in the range [1,2^24).
- ``<pref>`` is optional and defaults to ``<abi>``.
``f<size>:<abi>[:<pref>]``
This specifies the alignment for a floating-point type of a given bit
``<size>``. Only values of ``<size>`` that are supported by the target
will work. 32 (float) and 64 (double) are supported on all targets; 80
or 128 (
diff erent flavors of long double) are also supported on some
targets. The value of ``<size>`` must be in the range [1,2^24).
- ``<pref>`` is optional and defaults to ``<abi>``.
``a:<abi>[:<pref>]``
This specifies the alignment for an object of aggregate type.
- ``<pref>`` is optional and defaults to ``<abi>``.
+ In addition to the usual requirements for alignment values,
+ the value of ``<abi>`` can also be zero, which means one byte alignment.
``F<type><abi>``
This specifies the alignment for function pointers.
The options for ``<type>`` are:
@@ -3202,6 +3199,9 @@ as follows:
as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
address space cannot be specified as non-integral.
+Unless explicitly stated otherwise, on every specification that specifies
+an alignment, the value of the alignment must be in the range [1,2^16)
+and must be a power of two times the width of a byte.
On every specification that takes a ``<abi>:<pref>``, specifying the
``<pref>`` alignment is optional. If omitted, the preceding ``:``
should be omitted too and ``<pref>`` will be equal to ``<abi>``.
More information about the llvm-commits
mailing list