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

Zhongxing Xu xuzhongxing at gmail.com
Tue Aug 24 17:43:34 PDT 2010


On Wed, Aug 25, 2010 at 8:24 AM, Ted Kremenek <kremenek at apple.com> wrote:
>
> On Aug 23, 2010, at 8:41 PM, Zhongxing Xu wrote:
>
>>>
>>> +/// 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'.
>
> Interesting observation.  Would we really want to analyze the initializers unless we were directly analyzing the effects of a constructor call?  That is, when we see a CXXConstructExpr, why not just treat it as a function call?  If we do function inlining, it makes sense to me to analyze the initializers when we analyze the definition of the constructor, but that would be part of "jumping" into the CFG of the constructor (just like we do with inlining function calls).
>
>>
>> Note that now only initializers of CallExpr is lifted to block-level
>> expr, because we need to place CallEnter/CallExit nodes around them.
>
> Going with my above suggestion, CXXConstructExprs should probably just be treated the same way as CallExprs, and have their own CallEnter/CallExit nodes.  In this way they are treated just like any other call.  That means they should also be block-level expressions.

We're treating CXXConstructExprs as CallExprs. But they have an
implicit 'this' argument. I prefer we set up 'this' before entering
the call. That is, I'm suggesting we create CFG for DeclStmt

A a(3), b(4);

as

A a(3)
A b(4)

not

3
a(3)
4
b(4)




More information about the cfe-dev mailing list