[cfe-dev] A patch for integer promotions.

Eli Friedman eli.friedman at gmail.com
Wed Aug 19 14:23:38 PDT 2009


On Wed, Aug 19, 2009 at 4:21 AM, Enea Zaffanella<zaffanella at cs.unipr.it> wrote:
> +/// \brief Whether this is a promotable bitfield reference according
> +/// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
> +///
> +/// \returns the type this bit-field will promote to, or NULL if no
> +/// promotion occurs.
> +QualType ASTContext::isPromotableBitField(Expr *E) {
> +  FieldDecl *Field = E->getBitField();
> +  if (!Field)
> +    return QualType();
> +
> +  const BuiltinType *BT = Field->getType()->getAsBuiltinType();
> +  if (!BT)
> +    return QualType();

What about enum types?

> +  assert(BitWidth >= IntSize);
> +  switch (BT->getKind()) {
> +  case BuiltinType::Bool:
> +  case BuiltinType::Char_S:
> +  case BuiltinType::Char_U:
> +  case BuiltinType::SChar:
> +  case BuiltinType::UChar:
> +  case BuiltinType::Short:
> +  case BuiltinType::UShort:
> +  case BuiltinType::Int:
> +  case BuiltinType::UInt:
> +    assert(BitWidth == IntSize);
> +    // Here promotion occurs and it only depends on signedness.
> +    return Field->getType()->isSignedIntegerType() ? IntTy : UnsignedIntTy;
> +  default:
> +    // Types having rank greater than int are not subject to promotions.
> +    return QualType();
> +  }

This should use getIntegerRank instead of a switch.

Would you please include a test of some sort?  You can use the test I
committed for the previous patch as a model.

-Eli




More information about the cfe-dev mailing list