[libc] Add a note about using assertions in the libc runtime code.
authorSiva Chandra Reddy <sivachandra@google.com>
Tue, 7 Mar 2023 04:52:58 +0000 (20:52 -0800)
committerSiva Chandra Reddy <sivachandra@google.com>
Tue, 7 Mar 2023 18:16:50 +0000 (10:16 -0800)
Reviewed By: lntue

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

libc/docs/dev/code_style.rst

index 48197ee..c14786f 100644 (file)
@@ -102,3 +102,15 @@ followed:
    entrypoint is the only exceptional entrypoint on which other entrypoints
    should explicitly depend on if they set ``errno`` to indicate error
    conditions.
+
+Assertions in libc runtime code
+===============================
+
+The libc developers should, and are encouraged to, use assertions freely in
+the libc runtime code. However, the assertion should be listed via the macro
+``LIBC_ASSERT`` defined in ``src/__support/libc_assert.h``. This macro can be
+used from anywhere in the libc runtime code. Internally, all it does is to
+print the assertion expression and exit. It does not implement the semantics
+of the standard ``assert`` macro. Hence, it can be used from any where in the
+libc runtime code without causing any recursive calls or chicken-and-egg
+situations.