[cfe-dev] Decls are not synonyms for the symbols they represent

Argiris Kirtzidis akyrtzi at gmail.com
Wed Sep 17 11:46:13 PDT 2008


Ted Kremenek wrote:
>
> The problem that I'm concerned with right now is that there are cases 
> where two DeclRefExprs can refer to different VarDecls that correspond 
> to the same variable, but a client of the AST has no way of knowing 
> that that is the case.  Consider:
>
> ----
>
> extern int x;
>
> void foo() {
>   x++;
> }
>
> extern int x;
>
> void bar() {
>   x++;
> }
>
> void baz() {
>    extern int x;
>    x++;
> }
>
> -----
>
> If you do an AST dump of this, you will see that the DeclRefExprs for 
> 'x' in foo(), bar(), and baz() respectively refer to separate 
> VarDecls.  Right now a client of the ASTs has no way of knowing that 
> these VarDecls refer to the same variable.  Certainly a higher-level 
> API that resolves identifiers across translation units could do this, 
> but it might have to do a lot of work to resolve situations like the 
> one above.  By having a mechanism to resolve identifiers within a 
> translation unit, this higher-level API would much easier to implement.

An "IdResolver" used beyond Sema would be very useful, but it may come 
with a memory cost.
Could we get away with having all DeclRefExprs for 'x' refer to the same 
VarDecl ?




More information about the cfe-dev mailing list