[cfe-dev] Iterating over a CFGBlock excluding subexpressions

Stefan Schulze Frielinghaus via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 16 10:22:30 PDT 2020


Yes, that's it! I was reusing an AnalysisDeclContext from which I
derived the CFG. However, previous analyses set some build options.

Thanks for your help!

On Mon, Mar 16, 2020 at 05:44:38PM +0100, Gábor Horváth wrote:
> How did you get the CFG? There is a build option called setAlwaysAdd that
> you probably set before the CFG was built.
> 
> On Mon, 16 Mar 2020 at 17:13, Stefan Schulze Frielinghaus via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
> 
> > Hi all,
> >
> > Is there some way to iterate over a CFGBlock excluding subexpressions?
> >
> > Currently I iterate over a CFGBlock as e.g.
> >
> >    const CFGBlock *block;
> >    /* ... */
> >    for (const auto &I : *block) {
> >      if (Optional<CFGStmt> S = I.getAs<CFGStmt>())
> >        foo(const_cast<Stmt*>(S->getStmt()));
> >    }
> >
> > where function foo *recursively* descends into statements.  This has the
> > drawback that I visit some (sub)expressions twice: one time via the loop
> > and
> > another time by recursively descending into subexpressions via function
> > foo.
> > For example, a CFGBlock for a single statement e1=e2 looks as follows:
> >
> >    <begin>  (e2)  (e1)  (e1=e2)  <end>
> >
> > Therefore, I would first call foo for e2, then for e1, and in the end for
> > e1=e2
> > where I would recursively call foo for e1 and e2 again. Although they have
> > been
> > visited previously.
> >
> > Maybe this is not the supposed way to iterate over a CFGBlock?
> >
> > Cheers,
> > Stefan
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> >


More information about the cfe-dev mailing list