[cfe-dev] Does SourceLocation need more documentation?

Kim Gräsman via cfe-dev cfe-dev at lists.llvm.org
Sun May 13 06:51:26 PDT 2018


Hi Sam,

On Mon, Apr 9, 2018 at 8:06 PM, Sam McCall via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> I never felt that I completely understood the code I wrote/reviewed in tools
> dealing with SourceLocation. And clangd has had several bugs that boil down
> to wrong locations in the presence of macros.
>
> I couldn't find a good guide for how to think about them, so I spent a while
> reading the source code and wrote a tool to visualize them, which helped me
> a lot:
>   https://imgur.com/f3cXp7E
> (black edges are expansion, yellow edges are source)
>
> Did I miss some documentation of this concept?
> Would it be worth writing up an article illustrated with some examples, to
> add to llvm.org? Maybe this is niche or well-understood, interested in what
> others think.

Just to answer the question from your subject line: yes, that would be
very useful!

There are two challenges to locations, IMHO;

1) Details of the design: what are the concepts and mechanisms?
2) Use cases: how can we track macro expansion? Concatenation? What's
a bare-minimum handling of file vs macro locations? How can we be more
ambitious, e.g. attribute different parts of a macro to different
files?

I sometimes think it should be possible to build a queryable AST-like
structure for preprocessor symbols on top of the current location
design, but whenever I try actualize it, I get lost in the maze :)

So anything that helps clarify the model would be lovely.

- Kim



More information about the cfe-dev mailing list