This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/5] gdb: fix printing of flag enums with multi-bit enumerators


On 2020-02-17 5:56 a.m., Luis Machado wrote:
>> @@ -15526,10 +15527,17 @@ update_enumeration_type_from_children (struct die_info *die,
>>         unsigned_enum = 0;
>>         flag_enum = 0;
>>       }
>> -      else if ((mask & value) != 0)
>> -    flag_enum = 0;
>>         else
>> -    mask |= value;
>> +    {
>> +      int nbits = count_one_bits_ll (value);
>> +
>> +      if (nbits != 0 && nbits && nbits != 1)
> 
> Isn't this the same as nbits >= 2? popcount shouldn't return a negative number, should it?

I think I wrote that because count_one_bits_ll returns a signed int, so I
indeed thought "what if it returns a negative number".  But if it did, there
would be some quite more serious problems, so we probably don't have to think
about it here.  I'll change it as "nbits >= 2".

Oh and there was a spurious "&& nbits" in there.

> 
>> +        flag_enum = 0;
>> +      else if ((mask & value) != 0)
>> +        flag_enum = 0;
>> +      else
>> +        mask |= value;
>> +    }
>>           /* If we already know that the enum type is neither unsigned, nor
>>        a flag type, no need to look at the rest of the enumerates.  */
>> diff --git a/gdb/testsuite/gdb.base/printcmds.c b/gdb/testsuite/gdb.base/printcmds.c
>> index 57e04e6c01f3..f0b4fa4b86b1 100644
>> --- a/gdb/testsuite/gdb.base/printcmds.c
>> +++ b/gdb/testsuite/gdb.base/printcmds.c
>> @@ -96,9 +96,35 @@ enum some_volatile_enum { enumvolval1, enumvolval2 };
>>      name.  See PR11827.  */
>>   volatile enum some_volatile_enum some_volatile_enum = enumvolval1;
>>   -enum flag_enum { ONE = 1, TWO = 2 };
>> +/* An enum considered as a "flag enum".  */
>> +enum flag_enum
>> +{
>> +  FE_NONE = 0x00,
>> +  FE_ONE  = 0x01,
>> +  FE_TWO  = 0x02,
>> +};
>> +
>> +enum flag_enum three = FE_ONE | FE_TWO;
>> +
>> +/* Another enum considered as a "flag enum", but with enumerator with value
>> +   0.  */
>> +enum flag_enum_without_zero
>> +{
>> +  FEWZ_ONE = 0x01,
>> +  FEWZ_TWO = 0x02,
>> +};
>> +
> 
> Typo maybe? There is no enum with value 0 in flag_enum_without_zero. Maybe you meant flag_enum to contain a 0 value with FE_NONE?
> 
>> +enum flag_enum_without_zero flag_enum_without_zero = 0;
>> +
> 
> Or maybe you were referring to the above?

Do you mean a typo in the comment, or the type name?  Because there indeed seems
to be a typo, it should read "but with no enumerator with value", not
"but with enumerator with value".

The type name "flag_enum_without_zero" means there is no enumerator that has value
zero, is that clear?

> Otherwise LGTM.

Thanks for your review, I'll likely send a new version.

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]