Issue 71629
Summary More exploded graph nodes with fewer if branches
Labels new issue
Assignees
Reporter Joshua1023
    The problem was found when I used alpha.deadcode.UnreachableCode to check `test.c`:
```
clang --analyze --analyzer-no-default-checks  test.c -Xanalyzer -analyzer-config -Xanalyzer experimental-enable-naive-ctu-analysis=true  -Xanalyzer -analyzer-checker=alpha.deadcode.UnreachableCode
```
It reported:
```
test.c:90:38: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
   90 |           tmp_g && tmp_4 && tmp_5 && tmp_6 && tmp_8 && tmp_a && tmp_b && tmp_c &&
      | ^~~~~
test.c:94:54: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
   94 |                  tmp_3 && tmp_g && tmp_4 && tmp_5 && tmp_6 && tmp_8 && tmp_a &&
      | ^~~~~
test.c:123:15: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  123 | res = 10U;
      |               ^~~
test.c:187:18: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  187 | tmp_9 && tmp_a && tmp_b && tmp_c && tmp_d && tmp_e && tmp_f) {
      |                  ^~~~~
test.c:192:18: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  192 | tmp_9 && tmp_a && tmp_h && tmp_i && tmp_e && tmp_f) {
      | ^~~~~
test.c:206:61: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  206 |                  tmp_7 && tmp_8 && tmp_9 && condition_14 && tmp_h &&
      | 
6 warnings generated.
```

However, after I commented out the last `else if` branch (`test-remove-one-else-if.c`), the first two warnings disappeared:
```
test.c:123:15: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  123 |         res = 10U;
 |               ^~~
test.c:187:18: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  187 |                  tmp_9 && tmp_a && tmp_b && tmp_c && tmp_d && tmp_e && tmp_f) {
      | ^~~~~
test.c:192:18: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  192 |                  tmp_9 && tmp_a && tmp_h && tmp_i && tmp_e && tmp_f) {
      | ^~~~~
test.c:206:61: warning: This statement is never executed [alpha.deadcode.UnreachableCode]
  206 |                  tmp_7 && tmp_8 && tmp_9 && condition_14 && tmp_h &&
      | ^~~~~
4 warnings generated.
```

Since the `UnreachableCode` checker depends on the exploded graph, I modified the implementation to get the number of nodes in the exploded graph. It is wired that removing one `else if` branch leads to more nodes in the exploded graph.  The exploded graph of `test.c` has `229535` nodes while the exploded graph of `est-remove-one-else-if.c` has `229598` nodes. 

clang version: 17.0.2 (https://github.com/llvm/llvm-project/releases/tag/llvmorg-17.0.2)

`test.c` and `test-remove-one-else-if.c` are in [examples.zip](https://github.com/llvm/llvm-project/files/13291735/examples.zip)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to