<html>
    <head>
      <base href="https://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 --- - Over-aggressive overflow elimination check with call to exit()"
   href="https://llvm.org/bugs/show_bug.cgi?id=28012">28012</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Over-aggressive overflow elimination check with call to exit()
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>eli.friedman@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>atrick@apple.com, llvm-bugs@lists.llvm.org, sanjoy@playingwithpointers.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
static int will_add_overflow(int a, int x) {
  return a >= INT_MIN - x;
}
void f(int a, long last_value) {
  if (will_add_overflow(a, 3)) {
    // Leave, and don't actually do the increment, so no UB.
    printf("last_value = %ld\n", last_value);
    exit(0);
  }
}
void (*ff)(int, long) = f;
int main() {
  int a = 0;
  unsigned a_u = 0;
  volatile long last_value;
  do {
    a_u += 3;
    last_value = (long) ((int) a_u);
    ff(a, last_value);
    a += 3;
  } while (a != 46);
  return 0;
}

With clang -O0, prints "last_value = -2147483647". With clang -O2, prints
nothing.  (Tested on x86-64 Linux.)

Basically the same testcase as <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - new overflow check elimination code is too good"
   href="show_bug.cgi?id=27315">bug 27315</a>, except that I hid the call to exit().</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>