Skip to content

Commit

Permalink
Restore documentation for __builtin_assume
Browse files Browse the repository at this point in the history
This got removed by 6cacd42, and that was a
mistake.

Differential Revision: https://reviews.llvm.org/D120205
  • Loading branch information
serge-sans-paille committed Feb 22, 2022
1 parent 8e10448 commit 79c9072
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions clang/docs/LanguageExtensions.rst
Expand Up @@ -2205,6 +2205,39 @@ Query for this feature with ``__has_builtin(__builtin_alloca_with_align)``.
.. _langext-__builtin_assume:
``__builtin_assume``
--------------------
``__builtin_assume`` is used to provide the optimizer with a boolean
invariant that is defined to be true.
**Syntax**:
.. code-block:: c++
__builtin_assume(bool)
**Example of Use**:
.. code-block:: c++
int foo(int x) {
__builtin_assume(x != 0);
// The optimizer may short-circuit this check using the invariant.
if (x == 0)
return do_something();
return do_something_else();
}
**Description**:
The boolean argument to this function is defined to be true. The optimizer may
analyze the form of the expression provided as the argument and deduce from
that information used to optimize the program. If the condition is violated
during execution, the behavior is undefined. The argument itself is
Query for this feature with ``__has_builtin(__builtin_assume)``.
``__builtin_call_with_static_chain``
------------------------------------
Expand Down

0 comments on commit 79c9072

Please sign in to comment.