[clang] [C23] Fixed the value of BOOL_WIDTH (PR #117364)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 22 11:34:23 PST 2024


================
@@ -1103,7 +1103,15 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
   assert(TI.getCharWidth() == 8 && "Only support 8-bit char so far");
   Builder.defineMacro("__CHAR_BIT__", Twine(TI.getCharWidth()));
 
-  Builder.defineMacro("__BOOL_WIDTH__", Twine(TI.getBoolWidth()));
+  // The macro is specifying the number of bits in the value representation,
+  // not the number of bits in the object representation, which is what
+  // getBoolWidth() will return. For the bool/_Bool data type, there is only
+  // ever one bit in the value representation. See C23 6.2.6.2p2 for the rules
+  // in C. Note that [basic.fundamental]p10 allows an implementation-defined
+  // value representation for bool; Clang represents bool as an i1 when
+  // lowering to LLVM, so this value is also correct for C++ for our
+  // implementation.
----------------
zygoloid wrote:

Clang represents bools as i8 in memory, and for example you can `bit_cast` between `bool` and `char` because our `bool` has no padding bits.

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


More information about the cfe-commits mailing list