<div dir="ltr">Oh jeez, I forgot a very important aspect to the reproducer. Last time I looked into this it seemed that <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:12px;line-height:16.799999237060547px;white-space:pre">__attribute__ ((__always_inline__)) also played a part in this. In the last example "get_x()" should have this attribute.</span></div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 16, 2014 at 3:04 AM, Eric Fiselier <span dir="ltr"><<a href="mailto:eric@efcs.ca" target="_blank">eric@efcs.ca</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">I could have been a lot clearer. It seems to be a bug in MSAN. I've run into it before. <div>The code that causes it is something like:</div><div><br></div><div>// TestClass.hpp</div><div>template <class T></div>

<div>class TestClass</div><div>{</div><div>   int x{0};</div><div>   int get_x() { return x; }</div><div>};</div><div><br></div><div>extern template class TestClass<int>;</div><div><br></div><div>// TestClass.cpp</div>

<div>template class TestClass<int>;</div><div><br></div><div>// main.cpp </div><div>#include "TestClass.hpp"</div><div>int main()</div><div>{</div><div>   TestClass<int> t;</div><div>   // MSAN fires on use of uninitialized value here.</div>

<div>   int x = t.get_x();te </div><div>}</div><div><br></div><div>That's by no means a reproducer, but it represents similar code to what causes the test failures in "/test/string". MSAN seems to fire *any* time a value is returned from a method of a class that has been instantiated externally. I think the shared object boundary might be important. I haven't had time to investigate. </div>

<div><br></div><div>Unfortunately there is currently no good way to run the libc++ tests with sanitizers. The easiest way is to just insert "-fsanitize=memory" into the `compile_flags` list in `test/lit.cfg'.  Then just "cd test/string ; lit -sv . "</div>

<div><br></div><div>I hope that made it a little clearer.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>/Eric</div></font></span><div><br></div><div>P.S. These failures arn't localized to "test/string". They are anywhere templates are instantiated externally. String is just representative. </div>

<div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 16, 2014 at 2:42 AM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Eric Fiselier <<a href="mailto:eric@efcs.ca" target="_blank">eric@efcs.ca</a>> writes:<br>
> Hi Justin,<br>
><br>
> I'm not quite sure we are should do that right now. <br>
> If your compiling with MSAN and you call a function in an extern<br>
> template MSAN will fire. <br>
<br>
</div>I don't think I understand what you mean here. Which function? Why does<br>
msan fire?<br>
<div><br>
> For example testing test/string with MSAN enabled causes 124 failures.<br>
> Normally there are just 2.<br>
<br>
</div>If there are invalid memory accesses we should fix them. I don't see how<br>
explicit template instantiations would cause memory errors though.<br>
<br>
Are there bots that show this issue? How can I reproduce it?<br>
<div><div><br>
> We could probably guard the _LIBCPP_EXTERN_TEMPLATE definition to<br>
> check for MSAN but for now I don't think we are ready to re-enable<br>
> external template definitions.<br>
><br>
> /Eric<br>
><br>
> On Fri, Aug 15, 2014 at 11:58 AM, Justin Bogner <<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>> wrote:<br>
><br>
>     Author: bogner<br>
>     Date: Fri Aug 15 12:58:56 2014<br>
>     New Revision: 215740<br>
><br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project?rev=215740&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=215740&view=rev</a><br>
>     Log:<br>
>     Revert "Turn off extern templates for most uses."<br>
><br>
>     Turning off explicit template instantiation leads to a pretty<br>
>     significant build time and code size cost. We're better off dealing<br>
>     with ABI incompatibility issues that come up in a less heavy handed<br>
>     way.<br>
><br>
>     This reverts commit r189610.<br>
><br>
>     Modified:<br>
>         libcxx/trunk/include/__config<br>
>         libcxx/trunk/src/algorithm.cpp<br>
>         libcxx/trunk/src/ios.cpp<br>
>         libcxx/trunk/src/locale.cpp<br>
>         libcxx/trunk/src/string.cpp<br>
>         libcxx/trunk/src/valarray.cpp<br>
><br>
>     Modified: libcxx/trunk/include/__config<br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev</a><br>
>     =215740&r1=215739&r2=215740&view=diff<br>
>     ==========================================================================<br>
>     ====<br>
>     --- libcxx/trunk/include/__config (original)<br>
>     +++ libcxx/trunk/include/__config Fri Aug 15 12:58:56 2014<br>
>     @@ -608,7 +608,7 @@ template <unsigned> struct __static_asse<br>
>      #endif<br>
><br>
>      #ifndef _LIBCPP_EXTERN_TEMPLATE<br>
>     -#define _LIBCPP_EXTERN_TEMPLATE(...)<br>
>     +#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;<br>
>      #endif<br>
><br>
>      #ifndef _LIBCPP_EXTERN_TEMPLATE2<br>
><br>
>     Modified: libcxx/trunk/src/algorithm.cpp<br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/algorithm.cpp" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/algorithm.cpp</a>?<br>
>     rev=215740&r1=215739&r2=215740&view=diff<br>
>     ==========================================================================<br>
>     ====<br>
>     --- libcxx/trunk/src/algorithm.cpp (original)<br>
>     +++ libcxx/trunk/src/algorithm.cpp Fri Aug 15 12:58:56 2014<br>
>     @@ -7,7 +7,6 @@<br>
>      //<br>
>      //===<br>
>     ----------------------------------------------------------------------===/<br>
>     /<br>
><br>
>     -#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;<br>
>      #include "algorithm"<br>
>      #include "random"<br>
>      #include "mutex"<br>
><br>
>     Modified: libcxx/trunk/src/ios.cpp<br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/ios.cpp?rev=" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/ios.cpp?rev=</a><br>
>     215740&r1=215739&r2=215740&view=diff<br>
>     ==========================================================================<br>
>     ====<br>
>     --- libcxx/trunk/src/ios.cpp (original)<br>
>     +++ libcxx/trunk/src/ios.cpp Fri Aug 15 12:58:56 2014<br>
>     @@ -7,8 +7,6 @@<br>
>      //<br>
>      //===<br>
>     ----------------------------------------------------------------------===/<br>
>     /<br>
><br>
>     -#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;<br>
>     -<br>
>      #include "ios"<br>
>      #include "streambuf"<br>
>      #include "istream"<br>
><br>
>     Modified: libcxx/trunk/src/locale.cpp<br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/locale.cpp?rev=</a><br>
>     215740&r1=215739&r2=215740&view=diff<br>
>     ==========================================================================<br>
>     ====<br>
>     --- libcxx/trunk/src/locale.cpp (original)<br>
>     +++ libcxx/trunk/src/locale.cpp Fri Aug 15 12:58:56 2014<br>
>     @@ -7,8 +7,6 @@<br>
>      //<br>
>      //===<br>
>     ----------------------------------------------------------------------===/<br>
>     /<br>
><br>
>     -#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;<br>
>     -<br>
>      // On Solaris, we need to define something to make the C99 parts of<br>
>     localeconv<br>
>      // visible.<br>
>      #ifdef __sun__<br>
><br>
>     Modified: libcxx/trunk/src/string.cpp<br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/string.cpp?rev=" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/string.cpp?rev=</a><br>
>     215740&r1=215739&r2=215740&view=diff<br>
>     ==========================================================================<br>
>     ====<br>
>     --- libcxx/trunk/src/string.cpp (original)<br>
>     +++ libcxx/trunk/src/string.cpp Fri Aug 15 12:58:56 2014<br>
>     @@ -7,8 +7,6 @@<br>
>      //<br>
>      //===<br>
>     ----------------------------------------------------------------------===/<br>
>     /<br>
><br>
>     -#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;<br>
>     -<br>
>      #include "string"<br>
>      #include "cstdlib"<br>
>      #include "cwchar"<br>
><br>
>     Modified: libcxx/trunk/src/valarray.cpp<br>
>     URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/valarray.cpp?rev" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/valarray.cpp?rev</a><br>
>     =215740&r1=215739&r2=215740&view=diff<br>
>     ==========================================================================<br>
>     ====<br>
>     --- libcxx/trunk/src/valarray.cpp (original)<br>
>     +++ libcxx/trunk/src/valarray.cpp Fri Aug 15 12:58:56 2014<br>
>     @@ -7,8 +7,6 @@<br>
>      //<br>
>      //===<br>
>     ----------------------------------------------------------------------===/<br>
>     /<br>
><br>
>     -#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;<br>
>     -<br>
>      #include "valarray"<br>
><br>
>      _LIBCPP_BEGIN_NAMESPACE_STD<br>
><br>
>     _______________________________________________<br>
>     cfe-commits mailing list<br>
>     <a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
>     <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>