<div dir="ltr">Looks buggy to me. Static locals created by explicit template instantiation should probably not be discardable.<div><br></div><div>I think we're just lucky so far because either the local has constant initialization and no guard variable, so we never need a real definition, or it has a guard variable which keeps it from being optimized away.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 26, 2017 at 2:51 PM, David Blaikie via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In implementing modular codegen, specifically verifying the behavior for static local variables in inline functions in modular headers, I came across a piece of logic in Clang's linkage calculation that seems off.<br><br>To demonstrate a real-world example:<br><br>template<typename T><br>inline void f() { static int i; }<br>extern template void f<int>();<br>...<br>template void f<int>();<br><br>In the TU with the extern template declaration, an available_externally definition of f<int> and f<int>::i are provided (when optimizations are enabled).<br><br>In the TU with the extern template definition, a weak_odr definition of f<int> is provided but a linkonce_odr definition of f<int>::i is provided.<br><br>This surprises me and doesn't seem correct. What if the TU with the weak_odr definition is optimized to the point of removing the f<int>::i definition - but the available_externally TU is not - it inlines f<int> but leaves a use of f<int>::i available?<br><br>What's the deal here - am I missing something that makes this safe/correct?<br><br>- Dave</div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">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/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>