facebook / facebook/infer

An inconsistent behaviour in EXPENSIVE_LOOP_INVARIANT_CALL detector

Open
#1,953 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
OCaml
Stars
15.7k
Forks
2.1k
Avg merge
19h 36m
Merged PRs (30d)
13

Description

I discovered an inconsistency in the `EXPENSIVE_LOOP_INVARIANT_CALL` detector. In the following code example, Infer reports a warning of this type at line 22, but no warnings at line 23, despite both lines being semantically equivalent. This indicates an inconsistent bug in the detection logic.

```java
import java.util.ArrayList;

public class Main {
int incr(int x) {
return x + 1;
}

void foo1(ArrayList list) {
int x = 0;
for (Integer elem : list) {
incr(x);
}
}

void foo2(ArrayList list) {
int x = 0;
list.forEach(elem -> incr(x));
}

void func(int size, ArrayList list) {
for (int i = 0; i < size; i++) {
foo1(list); // report an EXPENSIVE_LOOP_INVARIANT_CALL warning
foo2(list); // report no warnigns
}
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.