[cfe-dev] A patch for integer promotions.

Enea Zaffanella zaffanella at cs.unipr.it
Wed Aug 19 16:56:39 PDT 2009


Eli Friedman wrote:
> 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?

Right, we were forgetting this case.

>> +  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.

Now using getIntegerTypeOrder (because it accepts QualType arguments).

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

Please find attached the revised patch (adding some tests to 
bitfield-promote.c) as well as new test file bitfield-promote-int-16bit.c.

Cheers,
Enea Zaffanella

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: BitField_Promotion_rev2.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090820/1e255888/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bitfield-promote-int-16bit.c
Type: text/x-csrc
Size: 564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090820/1e255888/attachment.c>


More information about the cfe-dev mailing list