[cfe-dev] CFG blocks and variable scope

Martin Doucha next_ghost at quick.cz
Sun Mar 29 03:05:41 PDT 2009


Chris Lattner wrote:
> Would it make sense for the CFG to contain a "virtual statement"
> saying "variable x destroyed here"?  This would be a natural way to
> handle C++ dtors and would also be useful in C, because you'd know the
> end of the variable's life.  CFG construction would handle this as it
> is walking the scopes.

It would if you didn't have to destroy variables in transition between
CFG blocks. Look at C99/C++ for loop:
for (int i = 0; i < 10; i++) { int x =i; ... }
Here, 'x' is destroyed on each pass while 'i' is destroyed in transition
to the block directly after the loop. And destroying it in the following
block doesn't work because other blocks which have no variable
corresponding to 'i' may point at this block as well. So you either have
to start making virtual basic blocks for variable destruction or you can
list variables to be destroyed at the edge between basic blocks.

Yes, virtual statements could be used for destroying variables in the
middle of CFG block. But that's not enough. And each of those statements
should point to a group of variables rather than list each of them
separately. Listing each of them separately will take a lot of memory in
more complex code structures.

> For declstmt's?  I think the AST has enough information to know
> scopes. What is missing? 

Something like mapping between CFG blocks and complete AST?

Regards,
Martin



More information about the cfe-dev mailing list