<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">kim.grasman@gmail.com</a>>:<br type="attribution"><blockquote class="quote" 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>