[cfe-dev] condition expression for while loops - not printing using

Jordan Rose jordan_rose at apple.com
Mon Mar 18 18:23:02 PDT 2013


Well, this seems a little dangerous unless you've already tested that it actually is a WhileStmt. You should be using dyn_cast if you're not sure.

> WhileStmt* While = cast<WhileStmt>(stmt);
> const Expr* cond = While->getCond();


Without posting your stack trace, though, it's hard to tell.

Jordan

P.S. The terminator of a CFG block is not included in the elements of the block, and I would think a while statement would always be a terminator.



On Mar 15, 2013, at 8:14 , rks <rks at cse.iitb.ac.in> wrote:

> Hi,
> 
> We are trying to dump condition expression for while loop using clang Visit methods.
> 
> It works fine for normal while loops. It doesn't work and crashes with stack dump for following code:
> 
> int main(void)
> {
>  int a ;
> 
>  {
>  {
>  while (1) {
>    while_continue: ;
>    if (! a) {
>      goto while_break;
>    }
>    if (a > 20) {
>      a ++;
>      goto while_break;
>    } else {
>      goto while_break;
>    }
>  }
>  while_break: ;
>  }
>  return (0);
> }
> }
> 
> I am unable to figure out why it doesn't print condition.
> 
> I am using this code:
> 
> WhileStmt* While = cast<WhileStmt>(stmt);
> const Expr* cond = While->getCond();
> 
> where stmt is pointer to clang::Stmt object.
> 
> We are getting clang::CFGStmt object by iterating over statements in basic block using CFG Block iterators.
> 
> - Rajendra
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list