<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Wrongly suspected UB possibly during FP optimization causing miscompilation at O1"
   href="https://bugs.llvm.org/show_bug.cgi?id=32014">32014</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrongly suspected UB possibly during FP optimization causing miscompilation at O1
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.9
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>fh.faraz.hussain@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18010" name="attach_18010" title="Test case of clang miscompilation at O1">attachment 18010</a> <a href="attachment.cgi?id=18010&action=edit" title="Test case of clang miscompilation at O1">[details]</a></span>
Test case of clang miscompilation at O1

Summary: In pb1fh.c, g_113[0] should have value 1.000000 when the program ends.
This is exactly what clang prints at both O0 and O2. At O1, however, clang
prints 257.000000, which is wrong.


Analysis: The outer for loop ends with p_62 equals 2, which means the last
value of *l_112 is 1. l_112 points to g_113[0]. Hence, the last value of g_113
should be 1. 

The inner for-loop seems to be the one that's confusing the optimizer at O1.
This loop never gets executed because g_107 is 0. Perhaps the O1 optimization
algorithm suspects there's some undefined behavior (UB) due to the inner for
loop, and therefore messes up. Of course, there's no UB there because g_107 is
0.  Interestingly, O2 gets it right, likely due to more global and detailed
analysis. 

Adding assert(g_107 == 0) before the inner for-loop removes the problem. 

Independently of the assert, making g_113 and l_112 ints also removes this
problem.</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>