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