Boost C++ Libraries: Ticket #9180: Valgrind reports usage of uninitialised values https://svn.boost.org/trac10/ticket/9180 <p> When running the following example with Valgrind: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/coroutine/coroutine.hpp&gt; typedef boost::coroutines::coroutine&lt;int()&gt; generator; void bar(generator::caller_type&amp; yield) { yield(32); } void foo(generator::caller_type&amp; yield) { generator nested_gen(bar); std::cout &lt;&lt; nested_gen.get() &lt;&lt; std::endl; yield(33); } int main() { generator gen(foo); std::cout &lt;&lt; gen.get() &lt;&lt; std::endl; return 0; }; </pre><p> I get the following trace (this is an extract, I give only the first error): </p> <pre class="wiki">$ valgrind --max-stackframe=6516920 --track-origins=yes ./a.out </pre><pre class="wiki">==10734== Memcheck, a memory error detector ==10734== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al. ==10734== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info ==10734== Command: ./a.out ==10734== ==10734== Warning: client switching stacks? SP change: 0x7ff0001b8 --&gt; 0x512af98 ==10734== to suppress, use: --max-stackframe=34257850912 or greater ==10734== Warning: client switching stacks? SP change: 0x512aca8 --&gt; 0x5761f98 ==10734== to suppress, use: --max-stackframe=6517488 or greater ==10734== Use of uninitialised value of size 8 ==10734== at 0x4C0E727: jump_fcontext (in /home/ahamez/usr/boost1.54/lib/libboost_context.so.1.54.0) ==10734== by 0x40C6E9: boost::coroutines::detail::coroutine_object&lt;int (), void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::coroutines::detail::standard_stack_allocator, std::allocator&lt;boost::coroutines::coroutine&lt;int (), 0&gt; &gt;, boost::coroutines::coroutine&lt;void (int), 1&gt;, int, 0&gt;::coroutine_object(void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::coroutines::attributes const&amp;, boost::coroutines::detail::standard_stack_allocator const&amp;, std::allocator&lt;boost::coroutines::detail::coroutine_object&lt;int (), void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::coroutines::detail::standard_stack_allocator, std::allocator&lt;boost::coroutines::coroutine&lt;int (), 0&gt; &gt;, boost::coroutines::coroutine&lt;void (int), 1&gt;, int, 0&gt; &gt; const&amp;) (in /home/ahamez/a.out) ==10734== by 0x407F29: boost::coroutines::coroutine&lt;int (), 0&gt;::coroutine&lt;void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;)&gt;(void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::coroutines::attributes const&amp;, boost::coroutines::detail::standard_stack_allocator const&amp;, std::allocator&lt;boost::coroutines::coroutine&lt;int (), 0&gt; &gt; const&amp;, boost::disable_if&lt;boost::is_convertible&lt;void (*&amp;)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::rv&lt;void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;)&gt;&amp;&gt;, boost::coroutines::coroutine&lt;int (), 0&gt;::dummy*&gt;::type) (in /home/ahamez/a.out) ==10734== by 0x403DB9: foo(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;) (in /home/ahamez/a.out) ==10734== by 0x410A1C: boost::coroutines::detail::coroutine_object&lt;int (), void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::coroutines::detail::standard_stack_allocator, std::allocator&lt;boost::coroutines::coroutine&lt;int (), 0&gt; &gt;, boost::coroutines::coroutine&lt;void (int), 1&gt;, int, 0&gt;::run() (in /home/ahamez/a.out) ==10734== by 0x40EAC6: void boost::coroutines::detail::trampoline1&lt;boost::coroutines::detail::coroutine_object&lt;int (), void (*)(boost::coroutines::coroutine&lt;void (int), 1&gt;&amp;), boost::coroutines::detail::standard_stack_allocator, std::allocator&lt;boost::coroutines::coroutine&lt;int (), 0&gt; &gt;, boost::coroutines::coroutine&lt;void (int), 1&gt;, int, 0&gt; &gt;(long) (in /home/ahamez/a.out) ==10734== by 0x4C0E6BD: make_fcontext (in /home/ahamez/usr/boost1.54/lib/libboost_context.so.1.54.0) ==10734== Uninitialised value was created by a stack allocation ==10734== at 0x4C0E723: jump_fcontext (in /home/ahamez/usr/boost1.54/lib/libboost_context.so.1.54.0) </pre><p> Tested under MacOS X 10.8 with clang 3.3 and under Linux (CentOS 6) with gcc 4.8. I can't say if it's just Valgrind which can't cope with coroutines or if it's a real bug from Boost.Coroutine. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9180 Trac 1.4.3 olli Mon, 30 Sep 2013 09:11:34 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9180#comment:1 https://svn.boost.org/trac10/ticket/9180#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> coroutines swap the stack-pointer (and some other registers) which might confuse valgrind. 'Warning: client switching stacks? SP change: 0x512aca8 --&gt;' </p> Ticket