[cfe-commits] [PATCH] PR9812: _Bool != bool

Enea Zaffanella zaffanella at cs.unipr.it
Thu Jun 16 06:00:01 PDT 2011


Il 14/06/2011 16:43, Douglas Gregor ha scritto:
> 
> On Jun 12, 2011, at 5:42 AM, Richard Smith wrote:
> 
>> Hi,
>>
>> The attached patch fixes PR9812 by splitting TST_bool into TST_bool (for
>> C++ bool) and TST__Bool (for C99 _Bool). They both still translate into
>> BuiltinType::Bool, but are now given the appropriate names in diagnostics.
> 
> Cool, thanks!
> 
>> One subtlety: BuiltinTypeLoc::getWrittenTypeSpec tries to convert
>> backwards from a BuiltinType to a TypeSpecifierType. I've arbitrarily made
>> this continue to produce TST_bool for BuiltinType::Bool, but this code is
>> actually not currently reachable: the function is only called by the AST
>> serialization code, and only in cases where the type cannot be bool.
> 
> Weird, but okay.

Sorry for this late answer, but I hadn't noticed this thread before.

The goal of BuiltinTypeLoc is to provide quite accurate information
about the syntax actually used in the sources and it is therefore
essential to distinguish between TST__Bool and TST_bool.

To this end, the thing to do is to change the implementation of

   bool needsExtraLocalData() const;

so as to return true for BuiltinType::Bool.

This way, calls to getWrittenTypeSpec() will return the TST stored in
the WrittenBuiltinSpecs data structure:

  struct WrittenBuiltinSpecs {
    /*DeclSpec::TST*/ unsigned Type  : 5;
    /*DeclSpec::TSS*/ unsigned Sign  : 2;
    /*DeclSpec::TSW*/ unsigned Width : 2;
    bool ModeAttr : 1;
  };

This data structure is loaded previously with the correct TST info by method

  void TypeSpecLocFiller::VisitBuiltinTypeLoc(BuiltinTypeLoc TL);

I hope the explanation was clear enough.

Cheers,
Enea.

PS : besides in the clang AST serializer, method getWrittenTypeSpec is
also used by client applications.


>> OK to commit?
> 
> 
> Yes, looks good.
> 
> 	- Doug
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 




More information about the cfe-commits mailing list