[cfe-dev] clang 3.8, libtooling cannot visit some BinaryOperator

詹石岩 via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 4 22:51:12 PST 2017


I added code just at the beginning of VisitBinaryOperator like:
bool VisitBinaryOperator(BinaryOperator *b){
    PrintingPolicy policy = PrintingPolicy(this->TheRewriter.getLangOpts());
    b->printPretty(llvm::errs(), NULL, policy);
    llvm::errs()<<'\n';
    if(b->isAssignmentOp()){
        handler.HandleBinaryOperator(b);
    }
    return true;
}The test code includes these lines:void setForceMethod(NbodyModel *theModel,int force_method) {
    theModel->force_method=force_method;
}
void setTreeRangeCoefficient(NbodyModel *theModel,double coefficient) {
    theModel->treeRangeCoefficient=coefficient;
}
void setIntMethod(NbodyModel *theModel,int int_method) {
    theModel->int_method=int_method;
}expected output should include these assignments but I didn't find them in terminal.I tried `clang -Xclang -ast-dump -fsyntax-only mycode.c` and these assignments were printed out.The older version of this tool can get most of these assignments(7 out of 8) but after I added some code, all of them are gone. Does this problem have any relation to compiler? Or the memory layout was messed up by my code?
Are you SURE that the VisitBinaryOperator function is not being called? I
find that highly unlikely (considering that these visitors are quite
commonly used for all sorts of different purposes, and checking for
assignments isn't unusual by any means).

I would expect that the conditions INSIDE your function is what is causing
problems. Try adding some printout (or set a breakpoint in a debugger) at
the beginning of the function. I suspect the function is being called, but
the operands are not the kind you think they are in this case, so your
printout or "do stuff" isn't happening.

--
Mats


------------------
----
祝好!詹石岩
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170105/ceaacbf7/attachment.html>


More information about the cfe-dev mailing list