[cfe-dev] Clang AST: how to get more precise debug information in certain cases?

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Mon Jun 3 07:34:16 PDT 2019


I /think/ that column 16 in your example is the first b in bbbbb, and that
Clang's AST dump is printing the first column of each token (& that the
range internally is stored in terms of tokens, essentially) - the dumping
format could be improved to compute the size of the token and print the end
of it instead of the start. Though this is mostly an aid for the developers
of Clang and having a more
raw/low-level/closer-to-how-the-compiler-is-internally might be the right
tradeoff here, I don't know for sure.

On Mon, Jun 3, 2019 at 1:21 AM Stanislav Pankevich via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Hi all,
>
> I would like to obtain the correct source locations from the Clang AST
> information but I am having some difficulties in doing that.
>
> The attached screenshot example-1 demonstrates running clang -Xclang
> -ast-dump foo.c on the following code:
>
> int foo(int aaaaa, int bbbbb) {
>   if (aaaaa == bbbbb) {
>     return 1;
>   } else {
>     return 0;
>   }
> }
>
> The source locations for the BinaryOperator only cover the "aaaaa =="
> part, not the full expression "aaaaa == bbbbb".
>
> In other cases (see the example-2) only the part of the second operand
> is covered but never the whole expression.
>
> My questions are:
>
> 1) Is there a specific reason for this behavior?
> 2) Which API should I use to obtain more precise information about the
> source locations? I have tried using getExpansionColumnNumber() and
> getColumnNumber() functions of the SourceManager class but they both
> give me the results similar to those of -ast-dump and I never get the
> precise information.
>
> Thanks in advance.
>
> Stanislav Pankevich
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://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/20190603/e564ea5b/attachment.html>


More information about the cfe-dev mailing list