[cfe-dev] CFGElement changes and initializers addition (with patch)

Zhongxing Xu xuzhongxing at gmail.com
Mon Aug 23 20:41:19 PDT 2010


>
> +/// addInitializer - Add C++ base or member initializer element to CFG.
> +CFGBlock* CFGBuilder::addInitializer(CXXBaseOrMemberInitializer* I) {
> +  if (!AddInitializers)
> +    return Block;
> +
> +  autoCreateBlock();
> +  AppendInitializer(Block, I);
> +
> +  if (!I->getInit())
> +    // FIXME: Remove this check if is unnecessery.
> +    return Block;
> +
> +  return Visit(I->getInit());
>
> This should probably be addStmt().  We probably want the initializer values to be added to the CFGBlock as block-level expressions.  The reason is that we want:
>
>  a(a)
>
> to be properly sequenced in the CFG, just like we do for DeclStmts, e.g.:
>
>  int x = x
>

There is some subtleties here. Currently we don't lift initializers of
CXXConstructExpr to block-level exprs. The benefits is that by seeing
the VarDecl first we can evaluate the constructor directly into the
object being constructed. This is done with the help of
AggExprVisitor. A object pointer is passed to AggExprVisitor as
'DestPtr'.

Note that now only initializers of CallExpr is lifted to block-level
expr, because we need to place CallEnter/CallExit nodes around them.




More information about the cfe-dev mailing list