[cfe-dev] CFG blocks and variable scope

Martin Doucha next_ghost at quick.cz
Sat Mar 28 15:14:09 PDT 2009


Ted Kremenek wrote:
> In the CFG, my thought was that *potentially* destructor calls could
> be explicitly modeled.  The lifetimes of regular stack variables could
> also be modeled using the same mechanism.  Since we haven't resolved
> how we want to represent destructors in the AST or CFG, I think that
> should probably be addressed first.

Maybe "scope" is not the right word. Think of what I called "scope" in
my last email as just a list of variables with common destruction
points. The tree structure is there just to reduce memory usage by
keeping each variable in exactly one list. Modeling the life of each
variable explicitly (if you mean explicitly marking each point where the
variable gets destroyed) could eat a lot of memory. Imagine a loop with
a lot of variables declared on top and a lot of breaks and continues
below. Explicit model would require marking the destruction for each
break/continue and each variable (or a special destruction block). The
list model will keep one list for all variables and one pointer to the
list per basic block with break/continue statement.

> Within a single basic block multiple scopes may be "pushed" and
> "popped".  The CFG only corresponds to control-flow, and thus nested
> compound statements are flattened.  Note that C++ also introduces
> scopes in many places that C does not.

I am aware of that. That's why I've proposed the list of "scopes" that
live inside a basic block. And the "scopes" don't have to follow the
language concept of scope to the letter. "Scopes" with exactly the same
exit points can be merged into one and empty "scopes" can be removed
completely. I am interested in the effects, I just don't see any other
efficient way of storing this information.

Regards,
Martin



More information about the cfe-dev mailing list