From 79c9072dc009693477242bc1347a2a6c3e419423 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Sun, 20 Feb 2022 09:05:46 +0100 Subject: [PATCH] Restore documentation for __builtin_assume This got removed by 6cacd420a1d72bca7809e6b516fb1e18ac6056c8, and that was a mistake. Differential Revision: https://reviews.llvm.org/D120205 --- clang/docs/LanguageExtensions.rst | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index f45d88092eb4a..865a877b02190 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -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`` ------------------------------------