[cfe-dev] Quenstion about ParseAST()

John McCall rjmccall at apple.com
Sun Aug 19 14:57:27 PDT 2012


On Aug 19, 2012, at 2:42 PM, Journeyer J. Joh wrote:
> Hello Sean Silva,
>> I believe this is primarily a locality optimization so that codegen
>> operates on the AST while it is still hot on cache; you could just as
>> easily perform all codegen based on the final AST.
> 
> I think this is very much valuable explanation. Thank you.
> 
>> Clang does not do constant folding; it's AST exactly represents the
>> expression. Clang has facilities for evaluating constant expressions
>> when necessary, but it doesn't really "fold" them.
> 
> When I tested a declaration below, seems to be folded in AST.
> 
> char y[2 + sizeof(struct dummy)];
> 
> It is placed in AST as shown below.
> 
> "char y[6]"
> 
> And there is a documentation about constant folding.

The original expression should appear in the ArrayTypeLoc.
The ConstantArrayType is not dependent on the expression
(well, it can be instantiation-dependent, but that's different)
and is actually required to be the same type as others with
the same bound.

>> From the documentation I guess this is one case that clang follows the
> history of gcc. - compiler doesn't have to fold like this only
> emitting error would be enough but clang fold this because gcc is now
> de facto standard and most people expect a compiler compiles this kind
> of out of standard code.

I don't understand;  your example is perfectly standard code.

John.



More information about the cfe-dev mailing list