[clang] [clang] Rework `hasBooleanRepresentation`. (PR #136038)

Michele Scandale via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 17 14:44:27 PDT 2025


================
@@ -8623,6 +8624,13 @@ inline bool Type::isIntegralOrEnumerationType() const {
 inline bool Type::isBooleanType() const {
   if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() == BuiltinType::Bool;
+  if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
+    // Incomplete enum types are not treated as integer types.
+    // FIXME: In C++, enum types are never integer types.
+    return IsEnumDeclComplete(ET->getDecl()) &&
+           !IsEnumDeclScoped(ET->getDecl()) &&
----------------
michele-scandale wrote:

>Since the existing methods are arguably misnamed, I wonder if we could reasonably just change them. Since the difference is (AFAIK) purely to make them vector-inclusive, perhaps we should just remove them and have a getNonVectorType() method that clients are expected to call before using the existing predicates.

Just to make sure I'm not misunderstanding things: are you suggesting to just drop the "vector of" portion of the `has*Representation` and move that onto clients of these APIs, right?

I'm not sure if that can work in general. E.g.
```
bool Type::hasIntegerRepresentation() const {
  if (const auto *VT = dyn_cast<VectorType>(CanonicalType))
    return VT->getElementType()->isIntegerType();
  if (CanonicalType->isSveVLSBuiltinType()) {
    const auto *VT = cast<BuiltinType>(CanonicalType);
    return VT->getKind() == BuiltinType::SveBool ||
           (VT->getKind() >= BuiltinType::SveInt8 &&
            VT->getKind() <= BuiltinType::SveUint64);
  }
  if (CanonicalType->isRVVVLSBuiltinType()) {
    const auto *VT = cast<BuiltinType>(CanonicalType);
    return (VT->getKind() >= BuiltinType::RvvInt8mf8 &&
            VT->getKind() <= BuiltinType::RvvUint64m8);
  }

  return isIntegerType();
}
```

This is more than just types where `isIntegerType` is `true`, or vector of such types.

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


More information about the cfe-commits mailing list