Boost C++ Libraries: Ticket #8695: boost::polygon faillure with optimizations enabled on g++-4.7.2 https://svn.boost.org/trac10/ticket/8695 <p> Following program does not return same results depending on optimization level. When using -00 with g++-4.7.2, area is 100 (good result). When using -02, area is 0 (bad result). </p> <p> Other compilation options: -Wall -std=c++0x -g </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;boost/polygon/polygon.hpp&gt; typedef boost::polygon::point_data&lt;int&gt; point_t; typedef boost::polygon::polygon_data&lt;int&gt; poly_t; typedef boost::polygon::polygon_set_data&lt;int&gt; poly_set_t; int main(int argc, char** argv) { using namespace boost::polygon::operators; std::list&lt;point_t&gt; points = { point_t(0, 0), point_t(10, 0), point_t(10, 10), point_t(0, 10) }; poly_t poly; poly.set(points.begin(), points.end()); poly_set_t poly_set; poly_set |= poly; std::cout &lt;&lt; "poly_set area: " &lt;&lt; boost::polygon::area(poly_set) &lt;&lt; std::endl; return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8695 Trac 1.4.3 Andrii Sydorchuk Sun, 16 Jun 2013 01:10:24 GMT owner, status changed https://svn.boost.org/trac10/ticket/8695#comment:1 https://svn.boost.org/trac10/ticket/8695#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Lucanus Simonson</span> to <span class="trac-author">Andrii Sydorchuk</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Andrii Sydorchuk Sun, 16 Jun 2013 01:31:30 GMT <link>https://svn.boost.org/trac10/ticket/8695#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:2</guid> <description> <p> Hi, </p> <p> I've tried to reproduce the given behavior with g++ 4.7.3, however got correct output. </p> <p> [CLI] g++ -I ~/Downloads/boost_1_53_0 -Wall -std=c++0x -g -O2 -v main.cpp &amp;&amp; ./a.out<br /> [OUTPUT] poly_set area: 100 </p> <p> We've got a few other reports, that state some flakiness with -O2 flag for g++ 4.7.2. </p> <p> Would it be feasible for you to upgrade to 4.7.3 and verify the failure? </p> </description> <category>Ticket</category> </item> <item> <author>hodevel@…</author> <pubDate>Mon, 01 Jul 2013 15:51:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:3</guid> <description> <p> Hi, </p> <p> Compiled gcc-4.7.3 on the same machine to test. Got no problem with gcc-4.7.3 - just like you. </p> <p> Using gdb is not very easy since optimizations are enabled. Is there any other test I can run to find what's wrong ? Maybe this is more a bug of gcc rather than a bug in boost polygon... </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrii Sydorchuk</dc:creator> <pubDate>Thu, 07 Nov 2013 00:01:34 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8695#comment:4 https://svn.boost.org/trac10/ticket/8695#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> I didn't have enough time to go deeper in this issue. So far I was not able to reproduce it, thus marking it as resolved. Potentially the issue here might be with the snap-rounding modes used by the Polygon. If that's the case the issue will be a duplicate of the ticket <a class="assigned ticket" href="https://svn.boost.org/trac10/ticket/6063" title="#6063: Bugs: resize does not offset rectangles (etc.) correctly or crashes (assigned)">#6063</a>. </p> Ticket aar@… Mon, 28 Apr 2014 09:44:17 GMT <link>https://svn.boost.org/trac10/ticket/8695#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:5</guid> <description> <p> Hello, get_trapezoids() is affected too, and I can reproduce the issue on any Debian Wheezy machine, since that distro uses 4.7.2. It looks like the gcc issue might be <a class="ext-link" href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56125"><span class="icon">​</span>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56125</a> or <a class="ext-link" href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54767"><span class="icon">​</span>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54767</a> </p> <p> I think this needs to be reopened and investigated, and some macros need to be added to workaround the issue if 4.7.0, 4.7.1 or 4.7.2 is detected. While upgrading to 4.7.3 makes the problem disappear, the great popularity of gcc 4.7.2 (thanks to Debian Wheezy) raises the need for a built-in workaround IMHO. </p> </description> <category>Ticket</category> </item> <item> <author>aar@…</author> <pubDate>Mon, 28 Apr 2014 10:06:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:6</guid> <description> <p> What about adding this to the relevant Boost.Polygon file(s): </p> <pre class="wiki">#pragma GCC optimize ("O1") </pre><p> wrapped in a conditional check for GCC version? Would the maintainers accept such a patch? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrii Sydorchuk</dc:creator> <pubDate>Sun, 04 May 2014 12:13:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:7</guid> <description> <p> Thank you for your email aar.<br /> I would prefer to avoid applying such a fix without understanding the actual reason of the issue. <br /> I was able to reproduce the behavior on ARMv6, Arch OS, g++ 4.7.2 with the following compilation prompt:<br /> g++ -O2 main.cpp -I ../../boost/libs/polygon -std=c++11<br /> Going to investigate. </p> </description> <category>Ticket</category> </item> <item> <author>aar@…</author> <pubDate>Sun, 04 May 2014 12:17:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:8</guid> <description> <p> Thank you asydorchuk for investigating. Maybe the GCC bugs I linked can give hints about the code patterns to look for? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrii Sydorchuk</dc:creator> <pubDate>Sun, 04 May 2014 12:53:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:9</guid> <description> <p> Those are definitely a good references.<br /> I've also found the following report: <a class="ext-link" href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60766"><span class="icon">​</span>http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60766</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrii Sydorchuk</dc:creator> <pubDate>Wed, 07 May 2014 23:49:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:10</guid> <description> <p> I've found the defect in the optimizer. Only one edge (instead of four) is inserted into the resulting polygon_data_set inside the polygon_set_data.hpp:insert_vertex_sequence call. <br /><br /> </p> <p> Using binary search I've figured out, that this behavior is caused by the following g++ compilation option: -f-inline-small-functions.<br /><br /> </p> <p> It would be great if you could confirm that adding flag -fno-inline-small-functions to your prompt fixes the issue with trapezoids.<br /> <br /> </p> <p> Polygon code is in places quite convoluted. I rewrote insert_vertex_sequence so that it's more readable for humans and less confusing for compiler. Please find the patch attached. It will be automatically released with the next version of Boost. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrii Sydorchuk</dc:creator> <pubDate>Wed, 07 May 2014 23:50:10 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/8695 https://svn.boost.org/trac10/ticket/8695 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">8695.patch</span> </li> </ul> Ticket aar@… Sat, 10 May 2014 15:00:58 GMT <link>https://svn.boost.org/trac10/ticket/8695#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:11</guid> <description> <p> Hi asydorchuk, sorry for the late reply. I can confirm that the OP code snippet works for me when I compile it with: -O3 -fno-inline-small-functions I also confirm that my trapezoid code works correctly if I compile with -fno-inline-small-functions -O3 (unfortunately my toolchain does not let me append anything after -O3 but luckily enough -f options take precedence over -O regardless of their position). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Andrii Sydorchuk</dc:creator> <pubDate>Sat, 10 May 2014 21:55:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8695#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8695#comment:12</guid> <description> <p> Glad to hear. I would assume that 8695 patch will also fix the issue, even without using -fno-inline-small-functions flag. </p> </description> <category>Ticket</category> </item> </channel> </rss>