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

mats petersson via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 5 02:55:37 PST 2017


Then I'm afraid I'm not sure. Maybe the assignments aren't classed as a
binary operator any longer?

It would be great if you can produce a COMPLETE (but minimal to show the
problem) example of both the code you are working on, and the input that
you are giving it, for debugging.

--
Mats

On 5 January 2017 at 06:51, 詹石岩 via cfe-dev <cfe-dev at lists.llvm.org> wrote:

> 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
>
>
> ------------------
> ----
> 祝好!
> 詹石岩
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170105/75ae0dfe/attachment.html>


More information about the cfe-dev mailing list