condition expression for while loops - not printing using

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

Any pointers? on why it doesn't print condition for the code given below.

- Rajendra

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.