condition expression for while loops - not printing using

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

condition expression for while loops - not printing using

Rajendra
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
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: condition expression for while loops - not printing using

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

- Rajendra

On 2013-03-15 20:44, rks 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
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: condition expression for while loops - not printing using

Jordan Rose
In reply to this post by 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.



On Mar 15, 2013, at 8:14 , rks <[hidden email]> 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
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev