[PATCH] D12358: [Analyzer] Handling constant bound loops

Devin Coughlin via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 21 22:38:51 PDT 2015


dcoughlin added inline comments.

================
Comment at: lib/StaticAnalyzer/Core/LoopWidening.cpp:149
@@ +148,3 @@
+      break;
+    }
+
----------------
This doesn't seem quite right. Consider:

```
int i;
for (i = 0; i < 21; i += 3) {}
clang_analyzer_eval(i == 23);
```
The value of `i` should be 21 after the loop, but this code sets it to 23. And what happens if `i` starts at 1 instead of 0?

Another (ridiculous) case to consider:

```
for (i = 0; i < 21; i += 3) {
  if (random() % 2 == 1) {
     i = i * i;
  } else {
    i--;
  }
}
```
What are the possible values of `i` after the loop?


http://reviews.llvm.org/D12358





More information about the cfe-commits mailing list