<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Invalid code generation / optimization of C++ with -O3"
   href="http://llvm.org/bugs/show_bug.cgi?id=19824">19824</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Invalid code generation / optimization of C++ with -O3
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dane@mapbox.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>After upgrading to Xcode 5.1.1 / Apple LLVM version 5.1 (clang-503.0.40) (based
on LLVM 3.4svn) I'm seeing a case where clang++ seems to mis-generate code when
the -O3 flag is used. The symptom is failing testcases in my application that
have been passing for years. Certainly there may be a bug in my code, but here
are the reasons I think clang is at fault:

  - if I compile with -Os the problem goes away (only happens with -O3)
  - if I put a statement like `std::clog << "foo\n";` in the problem area then
clang seems to generate the correct code. This seems to indicate to me that
clang is over-eagerly optimizing away code and effectively leading to it not
being run.
  - the problem did not exist with older clang

The application in question is Mapnik and the problem code involves c++11
lambda functions. I can reproduce the problem with latest clang on OS X and
Ubuntu precise by using the llvm 3.4 packages from <a href="http://llvm.org/apt/">http://llvm.org/apt/</a>.

In particular it is this block of code that is (seemingly) disappearing and
never executed at runtime:
<a href="https://github.com/mapnik/mapnik/blob/master/src/grid/process_markers_symbolizer.cpp#L123-L132">https://github.com/mapnik/mapnik/blob/master/src/grid/process_markers_symbolizer.cpp#L123-L132</a>.
If I put `std::clog << "something\n";` inside that `vector_dispatch_type` class
right here
(<a href="https://github.com/mapnik/mapnik/blob/master/include/mapnik/grid/grid_marker_helpers.hpp#L225-L228">https://github.com/mapnik/mapnik/blob/master/include/mapnik/grid/grid_marker_helpers.hpp#L225-L228</a>)
then the code does run at runtime and works properly. This seems to indicate to
me that over-eager optimization is at fault - could it be?

I've read <a href="http://llvm.org/docs/HowToSubmitABug.html#incorrect-code-generation">http://llvm.org/docs/HowToSubmitABug.html#incorrect-code-generation</a>
but its not clear to me how to use bugpoint for further providing a testcase
since I'm new to reporting bugs against clang. I can provide the output of
-save-temps or -emit-llvm easily, just let me know if these would help.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>