<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 - Optimizer breaks compare for the negation of the signed integer -0x80000000"
   href="https://bugs.llvm.org/show_bug.cgi?id=44680">44680</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Optimizer breaks compare for the negation of the signed integer -0x80000000
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>C
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>info@artsoft.nl
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23065" name="attach_23065" title="simple program to reproduce the bug">attachment 23065</a> <a href="attachment.cgi?id=23065&action=edit" title="simple program to reproduce the bug">[details]</a></span>
simple program to reproduce the bug

The following 2 lines of code:

int NaN = -0x80000000;
printf ( "%d < 0 : %s\n", -NaN, (-NaN) < 0 ? "true" : "false" );

Correctly prints when build without optimizations:
-2147483648 < 0 : true

But incorrectly prints when build with -O1 or higher:
-2147483648 < 0 : false

_______________________________________________

-0x80000000 has no positive counterpart  as 0x7FFFFFFF is the max positive
value of an int32. So when you negate -0x80000000 it remains -0x80000000.

I think the optimizer rewrites the statement "( -Nan ) < 0" to  "Nan  > 0", but
this changes the result.</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>