[llvm-bugs] [Bug 25421] New: Clang -O1 is incorrectly removing a comparison
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 5 12:36:43 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25421
Bug ID: 25421
Summary: Clang -O1 is incorrectly removing a comparison
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Global Analyses
Assignee: sanjoy at playingwithpointers.com
Reporter: rtrieu at google.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151105/40201262/attachment.html>
More information about the llvm-bugs
mailing list