facebook / facebook/infer

Issue type not being consistently detected - EXPENSIVE_LOOP_INVARIANT_CALL​

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

Description

In Code Snippet A below (EXPENSIVE_LOOP_INVARIANT_CALL​) detected while in Code Snippet B below which is same as Code Snippet A aside from some mutations that did not change the code semantics. The same bug is not being detected in both code snippet which shows the issues are not consistently being detected by Infer, is there an explanation.

class ExpensiveLoopInvariantCallExample {

@Expensive
void foo_linear(int size) {
int x = 10;
for (int i = 0; i < size; i++) {
incr(x); // constant call, don't hoist
}
}
int incr(int x) {
return x + 1;
}
void symbolic_expensive_hoist(int size) {
for (int i = 0; i < size; i++) {
foo_linear(size); // hoist // BUG: EXPENSIVE_LOOP_INVARIANT_CALL​
}
}
public int showBug(int size) {
symbolic_expensive_hoist(size);
return size;
}
}

Code Snippet A

import com.facebook.infer.annotation.Expensive;

class ExpensiveLoopInvariantCallExample {
@Expensive
void foo_linear(int size) {
int x = 10;
for (int i = 0; i < size; i++) {
incr(x); // constant call, don't hoist
}
boolean condition = getCondition();
if (condition) {
// Unreachable code
System.out.println("This is an unreachable statement.");
}
}
int incr(int x) {
return x + 1;
}
void symbolic_expensive_hoist(int size) {
for (int i = 0; i < size; i++) {
foo_linear(size); // hoist // BUG: EXPENSIVE_LOOP_INVARIANT_CALL​
}
boolean condition = getCondition();
if (condition) {
// Unreachable code
System.out.println("This is another unreachable statement.");
}
}
public int showBug(int size) {
symbolic_expensive_hoist(size);
return size;
private boolean getCondition() {
return false;
}
}

Code Snippet B

Infer Command:
infer run --loop-hoisting -- javac ExpensiveLoopInvariantCallExample.java

Infer version:
Infer version 1.0.0

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.