[clang] [CIR] Model cir.is_fp_class flags as a bit-enum (PR #205941)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 26 08:56:03 PDT 2026


================
@@ -561,6 +561,13 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
   //===--------------------------------------------------------------------===//
   cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src,
                                    cir::FPClassTest flags) {
+    // FPClassTest occupies bits 0-9 (fcAllFlags).  Sema rejects an
+    // out-of-range __builtin_isfpclass mask, so any extra bit here is an
+    // internal error; assert and mask it off so lowering stays well-formed.
+    uint32_t raw = static_cast<uint32_t>(flags);
+    uint32_t all = static_cast<uint32_t>(cir::FPClassTest::All);
+    assert((raw & ~all) == 0 && "FPClassTest mask has bits outside 0-9");
----------------
andykaylor wrote:

```suggestion
    uint32_t raw = static_cast<uint32_t>(flags);
    uint32_t all = static_cast<uint32_t>(cir::FPClassTest::All);
    assert((static_cast<uint32_t>(flags) & 
            ~static_cast<uint32_t>(cir::FPClassTest::All)) == 0 &&
           "FPClassTest mask has bits outside 0-9");
```
Otherwise, you'd need to add `[[maybe_unused]]` to avoid unused variable warnings in non-debug builds.

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


More information about the cfe-commits mailing list