[Prev][Next][Index]

Re: problem with insertStatementAfter(SgStatement &s);



Here's how to fix your problem. In the function 

void FTransform(SgProject *project)
you have the following code fragment:


      sub = f->functions(j);
      first = sub->lastDeclaration();
      last = sub->lastExecutable();
      InsertFCallNode(ENTRY_EVENT,first,AFTER);
      FixLoops(sub);
      FInstrumentSub(sub);
      InsertFCallNode(EXIT_EVENT, last, AFTER);

move the statement
      last = sub->lastExecutable();
so it appears after the call to FInstrumentSub(sub);, that is:

      sub = f->functions(j);
      first = sub->lastDeclaration();
      InsertFCallNode(ENTRY_EVENT,first,AFTER);
      FixLoops(sub);
      FInstrumentSub(sub);
      last = sub->lastExecutable();
      InsertFCallNode(EXIT_EVENT, last, AFTER);

The problem is that, if the "last" pointer gets set before
the transformations performed by FixLoops and by
FInstrumentSub, then it is possible that these
transformations will  invalidate the "last" pointer
(for example, if the statement that "last" points to is
transformed). You really want "last" to point to the last
executable _after_ the FixLoops and FInstrumentSub
transformations are done. --Beata