[clang] [clang] Implement -fstrict-bool (PR #160790)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 26 08:40:14 PDT 2025


================
@@ -2306,6 +2306,24 @@ are listed below.
    additional function arity information (for supported targets). See
    :doc:`ControlFlowIntegrity` for more details.
 
+.. option:: -fstrict-bool
+
+    ``bool`` values are stored to memory as 8-bit values on most targets. Under
+    ``-fstrict-bool``, it is undefined behavior for a ``bool`` value stored in
+    memory to have any other bit pattern than 0 or 1. This creates some
+    optimization opportunities for the compiler, but it enables memory
+    corruption if that assumption is violated, for instance if any other value
+    is ``memcpy``ed over a ``bool``. This is enabled by default.
----------------
apple-fcloutier wrote:

To make sure there's no misunderstanding, `-fstrict-bool` being enabled by default **maintains** the status quo. `-fno-strict-bool` (in either mode) is the change over today's behavior.

https://github.com/llvm/llvm-project/pull/160790


More information about the cfe-commits mailing list