[cfe-dev] CFG blocks and variable scope

Martin Doucha next_ghost at quick.cz
Mon Mar 30 15:55:25 PDT 2009


Ted Kremenek wrote:
> I don't follow this argument.  First, I don't understand the memory
> concerns.  Having statements point to group of N variables still
> requires N+1 pointers versus having N pointers in a basic block to
> virtual statements.  A basic block that contains virtual statements
> (which would be a format for this information that existing clients
> would already understand) would require space for the basic block
> (which is insignificant) and N pointers.

The problem is there may be multiple blocks with virtual statements. Now
if you have M blocks and N variables to destroy (the same variables in
each block), the group approach requires O(M+N) memory while the direct
approach requires O(M*N) memory. Though these numbers are unlikely to be
significantly different for hand-written code, don't underestimate the
stupidity of automatic code generators.

>> Something like mapping between CFG blocks and complete AST?
>
> I think this is already present.  CFG blocks contain Stmt* which
> directly reference the AST.  This seems more than adequate to
> reference the complete AST (although I'm not certain if "complete"
> implies something more specific).

Complete implies some sense of start and end of CFG block with respect
to scopes (CoumpoundStmts) in the AST. Though I'm sure it can be mapped
by hand, no such mapping is available without extra effort.

Regards,
Martin



More information about the cfe-dev mailing list