[clang] [clang] Convert to a C23 enum with bool underlying type like bool (PR #244494)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 20:32:31 PST 2026
================
@@ -176,6 +176,15 @@ static bool MustVisitNullValue(const Expr *E) {
return E->getType()->isNullPtrType();
}
+/// Return true if conversion to \p T has the semantics of conversion to bool:
+/// \p T is bool or an enumeration with a fixed underlying type of bool
+/// (C23 6.7.3.3p16).
+static bool hasBoolConversionSemantics(QualType T) {
----------------
mohitmishra786 wrote:
thanks for catching this. i built main (d245e2386) with assertions and went through the points here:
- aaron's example, `constexpr enum E oops = (enum E)12;` with `static_assert(oops == True)`, is accepted in C23, and so are 256, -1 and 0.5. C++ with `static_cast` gives the same. there is no constexpr test for it yet, i'll add one.
- vectors: both `ext_vector_type` and `vector_size` reject `enum E` as an element type ("invalid vector element type"), so there is no bool enum vector to handle. bool vectors take the elementwise path, which this change didn't touch, and converting {2, 0, -1, 256} to a bool vector gives {1, 0, 1, 1} at -O0 and -O2.
- my tests missed two cases. a direct cast from `_Accum` hits the assertion at CGExprScalar.cpp:3054 (#245850), and atomic `+=` / `|=` still use `atomicrmw` and give 0 at -O2 (#245854). i applied #245853 and #245856 on main and each one fixes its case.
- duplication: `hasBoolConversionSemantics` can be `T->isScalarType() && T->getScalarTypeKind() == Type::STK_Bool`. with that change CodeGen, C, Sema and SemaCXX tests give the same results as main. i filed #245877 for this and the constexpr test and will send a PR after #245853 and #245856 land, since they touch the same code.
https://github.com/llvm/llvm-project/pull/244494
More information about the cfe-commits
mailing list