Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the control flow graph to reduce false positives #141

Open
arthaud opened this issue Jul 12, 2019 · 0 comments
Open

Optimize the control flow graph to reduce false positives #141

arthaud opened this issue Jul 12, 2019 · 0 comments
Labels
C-false-positive Category: False Positive C-feature-request Category: Feature Request L-c Language: C P-low Priority: Low

Comments

@arthaud
Copy link
Member

arthaud commented Jul 12, 2019

The analyzer generates false positives when the code uses the following pattern:

#include <ikos/analyzer/intrinsic.h>
#define SUCCESS 0

extern int f(void);
extern int g(void);
extern int h(void);

int x = 0;

int main() {
    int status = f();
    if (status == SUCCESS) {
        status = g();
        x = 1;
    }
    if (status == SUCCESS) {
        status = h();
        __ikos_assert(x == 1);
    }
    return 0;
}

The analyzer generates the following warning:

test.c:18:9: warning: assertion could not be proven
        __ikos_assert(x == 1);
        ^

First, this code pattern is questionable and I would recommend not using it. It is hard to read and causes trouble to static analyzers. Prefer the early-return pattern, see this example.

Anyway, we could solve this false positive by optimizing the control flow graph. The current control flow graph is here. We could write an optimization pass that replaces the edge from #3 to #4 by an edge from #3 to #6. This would fix remove the warning.

@arthaud arthaud added C-false-positive Category: False Positive L-c Language: C P-low Priority: Low C-feature-request Category: Feature Request labels Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-false-positive Category: False Positive C-feature-request Category: Feature Request L-c Language: C P-low Priority: Low
Projects
None yet
Development

No branches or pull requests

1 participant