Boost C++ Libraries: Ticket #10005: erf_inv_initializer crashes under valgrind https://svn.boost.org/trac10/ticket/10005 <p> It was reported before on the mailing list: <a class="ext-link" href="http://lists.boost.org/boost-users/2012/08/75711.php"><span class="icon">​</span>http://lists.boost.org/boost-users/2012/08/75711.php</a> and I assume it's because valgrind doesn't support long doubles: <a class="ext-link" href="https://bugs.kde.org/show_bug.cgi?id=197915"><span class="icon">​</span>https://bugs.kde.org/show_bug.cgi?id=197915</a> </p> <p> Somehow erfc_inv is called in this place and the argument is then found to be 0: </p> <div class="wiki-code"><div class="code"><pre> <span class="c1">// Some compilers choke on constants that would underflow, even in code that isn&#39;t instantiated</span> <span class="c1">// so try and filter these cases out in the preprocessor:</span> <span class="cp">#if LDBL_MAX_10_EXP &gt;= 800</span> <span class="k">if</span><span class="p">(</span><span class="k">static_cast</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">BOOST_MATH_BIG_CONSTANT</span><span class="p">(</span><span class="n">T</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mf">1e-800</span><span class="p">))</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="n">boost</span><span class="o">::</span><span class="n">math</span><span class="o">::</span><span class="n">erfc_inv</span><span class="p">(</span><span class="k">static_cast</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">BOOST_MATH_BIG_CONSTANT</span><span class="p">(</span><span class="n">T</span><span class="p">,</span> <span class="mi">64</span><span class="p">,</span> <span class="mf">1e-800</span><span class="p">)),</span> <span class="n">Policy</span><span class="p">());</span> </pre></div></div><p> So an exception is thrown during initialization. While it may not be a bug, valgrind is extremely useful and it would be nice to have a workaround. </p> <p> I don't understand why erf_inv and erfc_inv are called with these arguments in <code>erf_inv_initializer&lt;&gt;::init::do_init()</code>, so I'm not sure what workaround is safe. </p> <p> Here is a full traceback: </p> <pre class="wiki">#0 0x00000036fb435c39 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 #1 0x00000036fb437348 in __GI_abort () at abort.c:89 #2 0x00000036ff860f85 in __gnu_cxx::__verbose_terminate_handler () at ../../../../libstdc++-v3/libsupc++/vterminate.cc:95 #3 0x00000036ff85eee6 in __cxxabiv1::__terminate (handler=&lt;optimized out&gt;) at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:38 #4 0x00000036ff85ef13 in std::terminate () at ../../../../libstdc++-v3/libsupc++/eh_terminate.cc:48 #5 0x00000036ff85f13f in __cxxabiv1::__cxa_throw (obj=0x526e490, tinfo=&lt;optimized out&gt;, dest=&lt;optimized out&gt;) at ../../../../libstdc++-v3/libsupc++/eh_throw.cc:84 #6 0x0000000004cb1541 in boost::throw_exception&lt;std::overflow_error&gt; (e=...) at /usr/include/boost/throw_exception.hpp:67 #7 0x0000000004cb7f28 in boost::math::policies::detail::raise_error&lt;std::overflow_error, long double&gt; ( function=0x4d2d338 "boost::math::erfc_inv&lt;%1%&gt;(%1%, %1%)", message=0x4d1bf8e "Overflow Error") at /usr/include/boost/math/policies/error_handling.hpp:95 #8 0x0000000004cb7f98 in boost::math::policies::detail::raise_overflow_error&lt;long double&gt; (function=&lt;optimized out&gt;, message=&lt;optimized out&gt;) at /usr/include/boost/math/policies/error_handling.hpp:211 #9 0x0000000004cdf17e in raise_overflow_error&lt;long double, boost::math::policies::policy&lt;boost::math::policies::promote_float&lt;false&gt;, boost::math::policies::promote_double&lt;false&gt;, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy&gt; &gt; (message=0x0, function=&lt;optimized out&gt;) at /usr/include/boost/math/policies/error_handling.hpp:515 #10 boost::math::erfc_inv&lt;long double, boost::math::policies::policy&lt;boost::math::policies::promote_float&lt;false&gt;, boost::math::policies::promote_double&lt;false&gt;, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy&gt; &gt; (z=0, z@entry=0, pol=...) at /usr/include/boost/math/special_functions/detail/erf_inv.hpp:383 #11 0x0000000004cdfaae in boost::math::detail::erf_inv_initializer&lt;long double, boost::math::policies::policy&lt;boost::math::policies::promote_float&lt;false&gt;, boost::math::policies::promote_double&lt;false&gt;, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy&gt; &gt;::init::do_init () at /usr/include/boost/math/special_functions/detail/erf_inv.hpp:347 #12 0x0000000004cda34b in init (this=&lt;optimized out&gt;) at /usr/include/boost/math/special_functions/detail/erf_inv.hpp:332 #13 __static_initialization_and_destruction_0 ( __initialize_p=__initialize_p@entry=1, __priority=__priority@entry=65535) at /usr/include/boost/math/special_functions/detail/erf_inv.hpp:367 #14 0x0000000004cda463 in _GLOBAL__sub_I_fit.cpp(void) () at ../../fityk/fit.cpp:643 #15 0x00000036fb00f2ea in call_init (l=&lt;optimized out&gt;, argc=argc@entry=1, argv=argv@entry=0xffefffc48, env=env@entry=0xffefffc58) at dl-init.c:82 #16 0x00000036fb00f3d3 in call_init (env=&lt;optimized out&gt;, argv=&lt;optimized out&gt;, argc=&lt;optimized out&gt;, l=&lt;optimized out&gt;) at dl-init.c:34 #17 _dl_init (main_map=0x36fb221168, argc=1, argv=0xffefffc48, env=0xffefffc58) at dl-init.c:130 #18 0x00000036fb00122a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10005 Trac 1.4.3 John Maddock Sun, 04 May 2014 16:24:17 GMT <link>https://svn.boost.org/trac10/ticket/10005#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:1</guid> <description> <p> Oh boy this sucks :-( </p> <p> You could work around the problem by defining BOOST_MATH_PROMOTE_DOUBLE_POLICY=false when building I guess. </p> <p> I don't really understand why this is being triggered, the code checks that 1e-800 is non-zero before calling erc_inv(1e-800) at which point it apparently is zero after all! The argument values can't be changed BTW - they're cunningly chosen to take specific code paths and force initialization of all the static data. Or I could add some try/catch blocks I guess, I will probably experiment with that. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Sun, 04 May 2014 17:36:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:2</guid> <description> <p> Update: I just experimented with this, and I'm unable to reproduce with current Git master and valgrind-3.8.1. Do you have a reduced test case? </p> </description> <category>Ticket</category> </item> <item> <author>Marcin Wojdyr <wojdyr@…></author> <pubDate>Sun, 04 May 2014 23:27:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:3</guid> <description> <p> I haven't realized it before, but it depends on compiler flags. I'm using now Fedora 20, valgrind 3.9.0, GCC 4.8 and boost 1.54 and 1.55 (both give the same result). I can reproduce the problem only with <code>g++ -Og</code>. </p> <p> But I've seen it with previous GCC versions (4.6 or 4.7, I'm not sure) and valgrind 3.8.1. I don't remember what optimization flags I used, but there was no <code>-Og</code> in previous versions. </p> <p> The minimal program I now use for testing is: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;stdlib.h&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/math/special_functions.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> <span class="p">{</span> <span class="kt">double</span> <span class="n">x</span> <span class="o">=</span> <span class="n">strtod</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="nb">NULL</span><span class="p">);</span> <span class="n">printf</span><span class="p">(</span><span class="s">&quot;%g</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">math</span><span class="o">::</span><span class="n">erfc_inv</span><span class="p">(</span><span class="n">x</span><span class="p">));</span> <span class="p">}</span> </pre></div></div><p> So as a workaround I'll just use a different compilation flags. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Mon, 26 May 2014 18:23:35 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10005#comment:4 https://svn.boost.org/trac10/ticket/10005#comment:4 <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">fixed</span> </li> </ul> <p> It does indeed seem to be specific to using -Og. After a bit of experimentation I believe I have it fixed in <a class="ext-link" href="https://github.com/boostorg/math/commit/a29a74bdaf078b5df4f875ead18960671fd5c479"><span class="icon">​</span>https://github.com/boostorg/math/commit/a29a74bdaf078b5df4f875ead18960671fd5c479</a> </p> Ticket jon.gammell@… Fri, 17 Jul 2015 18:47:49 GMT <link>https://svn.boost.org/trac10/ticket/10005#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:5</guid> <description> <p> I am experiencing this on Ubuntu 12.04 (valgrind-3.7.0 and gcc 4.6.3) with a manually installed Boost 1.58.0. </p> <pre class="wiki">terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;std::overflow_error&gt; &gt;' what(): Error in function boost::math::erfc_inv&lt;long double&gt;(long double, long double): Overflow Error </pre><p> It occurs when either the <code>-O3</code> or <code>-O2</code> flag is given, but does not occur without an <code>-O</code> flag. I didn't test any other optimization flag combinations. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Fri, 17 Jul 2015 19:00:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:6</guid> <description> <p> Sigh... I'll look into this again, but no promises, long double floating point values seem to behave completely unpredictably under valgrind :( </p> </description> <category>Ticket</category> </item> <item> <author>mlogicli <elliot.li.tech@…></author> <pubDate>Tue, 10 Nov 2015 20:21:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:7</guid> <description> <p> I was hit by this problem using Ubuntu 15.10 LTS on x86-64, which ships with boost 1.58.0 and GCC 5.2.1. For me, this problem exists only when my program is compiled by using -O2 -g. It ran ok under valgrind when compiled without -O2. I guess GCC removes is_value_non_zero() during optimization. </p> </description> <category>Ticket</category> </item> <item> <author>scott_paulin@…</author> <pubDate>Tue, 19 Jan 2016 22:38:52 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/10005#comment:8 https://svn.boost.org/trac10/ticket/10005#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> I am getting this under boost version 1.54.0.1 installed from apt-get on Mint 17.2. Compiled with clang 3.4. Still occurs when no build flags are specified. </p> Ticket anonymous Wed, 20 Jan 2016 03:33:12 GMT <link>https://svn.boost.org/trac10/ticket/10005#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10005#comment:8" title="Comment 8">scott_paulin@…</a>: </p> <blockquote class="citation"> <p> I am getting this under boost version 1.54.0.1 installed from apt-get on Mint 17.2. Compiled with clang 3.4. Still occurs when no build flags are specified. </p> </blockquote> <p> Update: Works fine when I compile my code WITHOUT -std=c++11 </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 20 Jan 2016 03:36:06 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:10</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10005#comment:9" title="Comment 9">anonymous</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/10005#comment:8" title="Comment 8">scott_paulin@…</a>: </p> <blockquote class="citation"> <p> I am getting this under boost version 1.54.0.1 installed from apt-get on Mint 17.2. Compiled with clang 3.4. Still occurs when no build flags are specified. </p> </blockquote> <p> Update: Works fine when I compile my code WITHOUT -std=c++11 </p> </blockquote> <p> Sorry, the first message should have read "Still occurs when no -O build flags are specified". I can't edit that message, it would be cool if someone with admin rights could clean up my mess by editing my first message. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 20 Jan 2016 11:53:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:11</guid> <description> <p> Boost-1.54 is an old Boost release now - and precedes the fixes (such as they are) above. Can you please try with Boost-1.60? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 21 Jan 2016 11:08:28 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:12</guid> <description> <p> I'm unable to reproduce on ubuntu with any combination of -ON and -g and either latest clang or gcc-5.1 or 4.9.2 and current develop branch (which should be the same as 1.60). Which is not to say that some folks won't experience this still. </p> <p> The essential issue is that valgrind doesn't support long double fully, so finite long doubles can get truncated to zero or infinity and random points in the program (ie you can check that a variable is non-zero, and then in the next line when you go to actually use it, it's been magically truncated to zero. The result is that it completely breaks program logic). </p> <p> There are a couple of possible workarounds (other than choosing -O options carefully), to define: </p> <p> BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS - which prevents any long double functions from being defined or used with Boost.Math, or else define: BOOST_MATH_PROMOTE_DOUBLE_POLICY=false, which prevents double functions from being evaluated at long double precision internally, but otherwise retains the long double implementations if they're needed. </p> <p> Both of these will reduce precision slightly, and both will typically improve performance on 64-bit hardware. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 05 Oct 2016 08:42:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:13</guid> <description> <p> We have this problem using boost 1.60. Is there any work around? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 21 Apr 2017 11:42:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:14</guid> <description> <p> I still have this problem with boost 1.64. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 21 Apr 2017 11:42:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:14</guid> <description> <p> I still have this problem with boost 1.64. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 22 Apr 2017 11:27:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:15</guid> <description> <p> I'm unable to reproduce, I tried every combination of -std= and -O options I could think of with gcc-4.8.4, 6.1.0 and clang-5. </p> <p> Can you provide an updated test case along with the build options and compiler version used? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 29 Aug 2017 09:38:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:16</guid> <description> <p> Reproduced under Ubuntu 17.04 <br /> </p> <p> $ valgrind --version valgrind-3.13.0 <br /> </p> <p> $ gcc --version gcc (Ubuntu 7.2.0-1ubuntu2) 7.2.0 <br /> I use both -std=c++11 and -O2 flags and valgrind works fine if I remove the -O flag </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Tom Anderson</dc:creator> <pubDate>Tue, 31 Oct 2017 15:44:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10005#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10005#comment:17</guid> <description> <p> I appear to have this with valgrind 3.10.1, and Boost 1.63.0, compiled with GCC 7.2.0 on Ubuntu 14.04.5. </p> <p> I'm not sure what compiler flags i'm using: Boost is a dependency of a third-party library whose build process is an impenetrable thicket. </p> </description> <category>Ticket</category> </item> </channel> </rss>