Skip to content

Commit dbfd0fd

Browse files
authored
[LangRef] Clarify that ptrtoint behaves like a capturing bitcast
This clarifies the outcome of the discussion in https://discourse.llvm.org/t/clarifiying-the-semantics-of-ptrtoint/83987/54 In the future, we will also introduce a non-capturing pointer -> address conversion using a new `ptrtoaddr` instruction. Reviewed By: krzysz00 Pull Request: #139349
1 parent e9c0840 commit dbfd0fd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

llvm/docs/LangRef.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12428,12 +12428,15 @@ Semantics:
1242812428
""""""""""
1242912429

1243012430
The '``ptrtoint``' instruction converts ``value`` to integer type
12431-
``ty2`` by interpreting the pointer value as an integer and either
12432-
truncating or zero extending that value to the size of the integer type.
12431+
``ty2`` by interpreting the all pointer representation bits as an integer
12432+
(equivalent to a ``bitcast``) and either truncating or zero extending that value
12433+
to the size of the integer type.
1243312434
If ``value`` is smaller than ``ty2`` then a zero extension is done. If
1243412435
``value`` is larger than ``ty2`` then a truncation is done. If they are
1243512436
the same size, then nothing is done (*no-op cast*) other than a type
1243612437
change.
12438+
The ``ptrtoint`` always :ref:`captures address and provenance <pointercapture>`
12439+
of the pointer argument.
1243712440

1243812441
Example:
1243912442
""""""""
@@ -12488,6 +12491,9 @@ of the integer ``value``. If ``value`` is larger than the size of a
1248812491
pointer then a truncation is done. If ``value`` is smaller than the size
1248912492
of a pointer then a zero extension is done. If they are the same size,
1249012493
nothing is done (*no-op cast*).
12494+
The behavior is equivalent to a ``bitcast``, however, the resulting value is not
12495+
guaranteed to be dereferenceable (e.g. if the result type is a
12496+
:ref:`non-integral pointers <nointptrtype>`).
1249112497

1249212498
Example:
1249312499
""""""""

0 commit comments

Comments
 (0)