[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / range_casts.c
blobb1967730bf8613bc7529227156a449c8ada1f8b4
1 // This test checks that intersecting ranges does not cause 'system is over constrained' assertions in the case of eg: 32 bits unsigned integers getting their range from 64 bits signed integers.
2 // RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,debug.ExprInspection -verify %s
4 void clang_analyzer_warnIfReached(void);
6 void f1(long foo)
8 unsigned index = -1;
9 if (index < foo) index = foo;
10 if (index + 1 == 0) // because of foo range, index is in range [0; UINT_MAX]
11 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
12 else
13 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
16 void f2(unsigned long foo)
18 int index = -1;
19 if (index < foo) index = foo; // index equals ULONG_MAX
20 if (index + 1 == 0)
21 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
22 else
23 clang_analyzer_warnIfReached(); // no-warning
26 void f3(unsigned long foo)
28 unsigned index = -1;
29 if (index < foo) index = foo;
30 if (index + 1 == 0)
31 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
32 else
33 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
36 void f4(long foo)
38 int index = -1;
39 if (index < foo) index = foo;
40 if (index + 1 == 0)
41 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
42 else
43 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
46 void f5(long foo)
48 unsigned index = -1;
49 if (index < foo) index = foo;
50 if (index == -1)
51 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
52 else
53 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
56 void f6(long foo)
58 unsigned index = -1;
59 if (index < foo) index = foo;
60 if (index == -1)
61 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
62 else
63 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
66 void f7(long foo)
68 unsigned index = -1;
69 if (index < foo) index = foo;
70 if (index - 1 == 0) // Was not reached prior fix.
71 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
72 else
73 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
76 void f8(long foo)
78 unsigned index = -1;
79 if (index < foo) index = foo;
80 if (index + 1L == 0L)
81 clang_analyzer_warnIfReached(); // no-warning
82 else
83 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
86 void f9(long foo)
88 unsigned index = -1;
89 if (index < foo) index = foo;
90 if (index - 1L == 0L) // Was not reached prior fix.
91 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
92 else
93 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
96 void f10(long foo)
98 unsigned index = -1;
99 if (index < foo) index = foo;
100 if (index + 1 == 0L)
101 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
102 else
103 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
106 void f11(long foo)
108 unsigned index = -1;
109 if (index < foo) index = foo;
110 if (index + 1UL == 0L)
111 clang_analyzer_warnIfReached(); // no-warning
112 else
113 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
116 void f12(long foo)
118 unsigned index = -1;
119 if (index < foo) index = foo;
120 if (index - 1UL == 0L) // Was not reached prior fix.
121 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
122 else
123 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
126 void f13(int foo)
128 unsigned short index = -1;
129 if (index < foo) index = foo;
130 if (index + 1 == 0)
131 clang_analyzer_warnIfReached(); // no-warning
132 else
133 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
136 void f14(long foo)
138 unsigned index = -1;
139 if (index < foo) index = foo;
140 long bar = foo;
141 if (index + 1 == 0)
142 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
143 else
144 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
147 void f15(long foo)
149 unsigned index = -1;
150 if (index < foo) index = foo;
151 unsigned int tmp = index + 1;
152 if (tmp == 0)
153 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
154 else
155 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}