[cfe-dev] Late-parsing function templates in tools

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 26 11:38:11 PDT 2018


It sounds like this issue would be fixed if we did what you are doing
(parsed all late parsed function templates) within
Sema::ActOnEndOfTranslationUnit, is that right?

If so, that would be a pretty reasonable extension for tools.

On Thu, Mar 8, 2018 at 11:58 AM Kim Gräsman via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Ping! I would love some input on this.
>
> Thanks,
> - Kim
>
> Den 29 juni 2017 4:42 em skrev "Kim Gräsman" <kim.grasman at gmail.com>:
>
> Hello all,
>
> In include-what-you-use, we need to parse and AST-visit templates
> whether they're instantiated or not, in order to record all uses. This
> is somewhat at odds with `-fdelayed-template-parsing` for MSVC
> compatibility. Uninstantiated function templates are never visited in
> this mode. So we have a hack, suggested here [1] that explicitly
> parses these function templates, implemented here [2].
>
> This works surprisingly well, but we've run into a corner case
> triggered by llvm/include/llvm/Support/MathExtras.h. When run under
> include-what-you-use on Windows, the GNU builtins are still available,
> so we end up trying to parse the equivalent of the following code:
>
>     template <class T>
>     int myctz(unsigned int value) {
>      return __builtin_ctz(value);
>     }
>
> Essentially a GNU builtin called from a function template. This causes
> the call to LateTemplateParser to crash because parsing the builtin
> needs the TUScope member to be non-null. More details in a patch by
> @zjturner here [3].
>
> Some open questions borrowed from that review:
>
> Can we seed Sema with a valid `TUScope` before invoking
> `LateTemplateParser`, and if so, how?
>
> Or is this because we invoke the parser multiple times? Can we avoid
> that somehow?
>
> For us, it sure would be nice if Clang had a more proofed API for
> doing this somewhere, but I'm not sure where it belongs or how it
> might be implemented.
>
> Many thanks for any input,
> - Kim
>
> [1]
> http://clang-developers.42468.n3.nabble.com/Tooling-vs-fdelayed-template-parsing-WAS-Clang-cl-exe-and-the-VC-preprocessor-td4040899.html
> [2]
> https://github.com/include-what-you-use/include-what-you-use/blob/master/iwyu.cc#L3530
> [3] https://reviews.llvm.org/D31697
>
>
> _______________________________________________
> 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/20180326/4899fcd1/attachment.html>


More information about the cfe-dev mailing list