Skip to content
Snippets Groups Projects
Commit 02f895ab authored by Gabor Horvath's avatar Gabor Horvath
Browse files

[analyzer] Do not continue to analyze a path if the constraints contradict with builtin assume

Differential Revision: https://reviews.llvm.org/D34502


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305991 91177308-0d34-0410-b5e6-96231b3b80d8
parent 85856463
No related branches found
No related tags found
No related merge requests found
...@@ -50,8 +50,10 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE, ...@@ -50,8 +50,10 @@ bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
state = state->assume(ArgSVal.castAs<DefinedOrUnknownSVal>(), true); state = state->assume(ArgSVal.castAs<DefinedOrUnknownSVal>(), true);
// FIXME: do we want to warn here? Not right now. The most reports might // FIXME: do we want to warn here? Not right now. The most reports might
// come from infeasible paths, thus being false positives. // come from infeasible paths, thus being false positives.
if (!state) if (!state) {
C.generateSink(C.getState(), C.getPredecessor());
return true; return true;
}
C.addTransition(state); C.addTransition(state);
return true; return true;
......
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s
void clang_analyzer_eval(int);
void f(int i) {
__builtin_assume(i < 10);
clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
}
// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,debug.ExprInspection %s -std=c++11 -verify
void clang_analyzer_eval(bool); void clang_analyzer_eval(bool);
void clang_analyzer_warnIfReached();
void testAddressof(int x) { void testAddressof(int x) {
clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}} clang_analyzer_eval(&x == __builtin_addressof(x)); // expected-warning{{TRUE}}
...@@ -50,3 +51,16 @@ void test_assume_aligned_4(char *p) { ...@@ -50,3 +51,16 @@ void test_assume_aligned_4(char *p) {
q = (char*) __builtin_assume_aligned(p + 1, 16); q = (char*) __builtin_assume_aligned(p + 1, 16);
clang_analyzer_eval(p == q); // expected-warning{{FALSE}} clang_analyzer_eval(p == q); // expected-warning{{FALSE}}
} }
void f(int i) {
__builtin_assume(i < 10);
clang_analyzer_eval(i < 15); // expected-warning {{TRUE}}
}
void g(int i) {
if (i > 5) {
__builtin_assume(i < 5);
clang_analyzer_warnIfReached(); // Assumtion contradicts constraints.
// We give up the analysis on this path.
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment