[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / infeasible-sink.c
blob9cb66fcac0b6be8a23e8226f517787ba02e1e793
1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=debug.ExprInspection \
4 // RUN: -analyzer-config eagerly-assume=false \
5 // RUN: -verify
7 // Here we test that if it turns out that the parent state is infeasible then
8 // both children States (more precisely the ExplodedNodes) are marked as a
9 // Sink.
10 // We rely on existing defects of the underlying constraint solver. However,
11 // in the future we might strengthen the solver to discover the infeasibility
12 // right when we create the parent state. At that point some of these tests
13 // will fail, and either we shall find another solver weakness to have the test
14 // case functioning, or we shall simply remove that.
16 void clang_analyzer_warnIfReached();
17 void clang_analyzer_eval(int);
19 void test1(int x) {
20 if (x * x != 4)
21 return;
22 if (x < 0 || x > 1)
23 return;
25 // { x^2 == 4 and x:[0,1] }
26 // This state is already infeasible.
28 // Perfectly constraining 'x' will trigger constant folding,
29 // when we realize we were already infeasible.
30 // The same happens for the 'else' branch.
31 if (x == 0) {
32 clang_analyzer_warnIfReached(); // no-warning
33 } else {
34 clang_analyzer_warnIfReached(); // no-warning
36 clang_analyzer_warnIfReached(); // no-warning
37 (void)x;
40 int a, b, c, d, e;
41 void test2() {
43 if (a == 0)
44 return;
46 if (e != c)
47 return;
49 d = e - c;
50 b = d;
51 a -= d;
53 if (a != 0)
54 return;
56 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
58 /* The BASELINE passes these checks ('wrning' is used to avoid lit to match)
59 // The parent state is already infeasible, look at this contradiction:
60 clang_analyzer_eval(b > 0); // expected-wrning{{FALSE}}
61 clang_analyzer_eval(b <= 0); // expected-wrning{{FALSE}}
62 // Crashes with expensive checks.
63 if (b > 0) {
64 clang_analyzer_warnIfReached(); // no-warning, OK
65 return;
67 // Should not be reachable.
68 clang_analyzer_warnIfReached(); // expected-wrning{{REACHABLE}}
71 // The parent state is already infeasible, but we realize that only if b is
72 // constrained.
73 clang_analyzer_eval(b > 0); // expected-warning{{UNKNOWN}}
74 clang_analyzer_eval(b <= 0); // expected-warning{{UNKNOWN}}
75 if (b > 0) {
76 clang_analyzer_warnIfReached(); // no-warning
77 return;
79 clang_analyzer_warnIfReached(); // no-warning