<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 --- - Clang -O1 is incorrectly removing a comparison"
   href="https://llvm.org/bugs/show_bug.cgi?id=25421">25421</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang -O1 is incorrectly removing a comparison
          </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>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>Global Analyses
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>sanjoy@playingwithpointers.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rtrieu@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Suspected revision is r251050.  Inside the loop, the comparison (i <
result_size - 1) is being treated as true for all cases, even on the last loop
iterator where i is equal to result_size - 1

test4.cc:
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;
int main(int argc, char** argv) {
  vector<int> vv = {1, 2};
  long int result_size = vv.back();
  for (long int i = 0; i < result_size; ++i) {
    cout << i << " < " << result_size
         << " - 1 = " << ((i < result_size - 1) ? "true" : "false") << endl;
  }

  return 0;
}

clang++ -std=c++11 test4.cc -O1 ; ./a.out
0 < 2 - 1 = true
1 < 2 - 1 = true

clang++ -std=c++11 test4.cc ; ./a.out
0 < 2 - 1 = true
1 < 2 - 1 = false</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>