<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 --- - LTO miscompiles some code?"
   href="http://llvm.org/bugs/show_bug.cgi?id=15364">15364</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LTO miscompiles some code?
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.2
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bruce.mitchener@gmail.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>Created <span class=""><a href="attachment.cgi?id=10081" name="attach_10081" title="Demonstration of error">attachment 10081</a> <a href="attachment.cgi?id=10081&action=edit" title="Demonstration of error">[details]</a></span>
Demonstration of error

I'm working on emscripten and am updating the version of libcxx that is used in
emscripten to the current version.  I thought it would be a good idea to run
the libcxx test cases against emscripten and found what appears to be a bug in
LLVM.

I've attached a fairly minimal test case for the bug and it goes into an
infinite loop when compiled with emscripten.

According to Alon Zakai (lead on emscripten):

    Looks like LLVM LTO is breaking this. It works with -O1 --llvm-lto 0 and
    fails with -O1 --llvm-lto 1.

    Diffing those, it does look like LTO messes stuff up. With

        <a href="https://gist.github.com/kripken/5039740">https://gist.github.com/kripken/5039740</a>

    applies to the LTO's one, it works ok. Basically, LTO copies the first
    into local vars - but never uses them. It also doesn't make a stack copy
    of the last vars. Manually changing those in the diff make it work
    properly.

The 'first' and 'last' variables that he is referring to are from the
definition of std::includes:

    template <class _Compare, class _InputIterator1, class _InputIterator2>
    bool
    __includes(_InputIterator1 __first1, _InputIterator1 __last1,
               _InputIterator2 __first2, _InputIterator2 __last2,
               _Compare __comp)
    {
        for (; __first2 != __last2; ++__first1)
        {
            if (__first1 == __last1 || __comp(*__first2, *__first1))
                return false;
            if (!__comp(*__first1, *__first2))
                ++__first2;
        }
        return true;
    }

The bug against emscripten can be seen at
<a href="https://github.com/kripken/emscripten/issues/873">https://github.com/kripken/emscripten/issues/873</a>.

I am using clang / llvm 3.2.</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>