[cfe-dev] clang 3.8, libtooling cannot visit some BinaryOperator
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Mon Jan 9 02:11:32 PST 2017
It definitely should match:
$ cat /tmp/t.cc
void f() {
int i;
i = 2;
}
$ clang-query /tmp/t.cc --
Parsing /tmp/t.cc: 0.0015 (100.0%) 0.0015 (100.0%) 0.0018 (100.0%)
clang-query> m binaryOperator()
Match #1:
/tmp/t.cc:3:3: note: "root" binds here
i = 2;
If your code doesn't parse correctly, or doesn't find some headers, all
bets are off, so as the post above said, more context needed.
On Thu, Jan 5, 2017 at 11:55 AM mats petersson via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> 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
>
>
> _______________________________________________
> 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/20170109/2d4d9177/attachment.html>
More information about the cfe-dev
mailing list