[cfe-dev] Finding out if an assignment is within If statement's predicate

Vedant Kumar via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 30 12:36:07 PDT 2016


Hi,

Have you tried setting a flag when visiting the conditional? E.g;

  void VisitIfStmt(const IfStmt *S) {
    InConditional = true;
    Visit(S->getCond());
    InConditional = false;
  }

vedant

> On Jul 30, 2016, at 10:45 AM, Himanshu via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi All, 
> 
> In my VisitBinaryOperator I want to treat assignments in IfStmt's predicate check part differently 
> than the assignments in its body. For example: 
> 
> if( (*ptrI = malloc(sizeof(int) * 10)) == NULL)  // => this assignment is within predicate 
>         msg = "success"; // assignment in body (treat it differently than the above)
> else
>         msg = "fail"; // assignment in body
> 
> 
> Here, I would like to handle the ptrI = malloc assignment differently than the other two assignments of 'msg'. I tries setting a flag in VisitIfStmt, but that can't distinguish between the two different kind of assignments. 
> 
> Thanks!
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list