[clang] 79c9072 - Restore documentation for __builtin_assume

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 22 08:20:15 PST 2022


Author: serge-sans-paille
Date: 2022-02-22T17:19:11+01:00
New Revision: 79c9072dc009693477242bc1347a2a6c3e419423

URL: https://github.com/llvm/llvm-project/commit/79c9072dc009693477242bc1347a2a6c3e419423
DIFF: https://github.com/llvm/llvm-project/commit/79c9072dc009693477242bc1347a2a6c3e419423.diff

LOG: Restore documentation for __builtin_assume

This got removed by 6cacd420a1d72bca7809e6b516fb1e18ac6056c8, and that was a
mistake.

Differential Revision: https://reviews.llvm.org/D120205

Added: 
    

Modified: 
    clang/docs/LanguageExtensions.rst

Removed: 
    


################################################################################
diff  --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst
index f45d88092eb4..865a877b0219 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``
 ------------------------------------
 


        


More information about the cfe-commits mailing list