blob: f056cb85a33fd51fcd978bf690e4399670f9d7e5 [file] [log] [blame]
Pierre Gousseaue961b442016-01-12 10:07:56 +00001// 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_cc1 -triple x86_64-pc-linux-gnu -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify %s
3
4void clang_analyzer_warnIfReached();
5
6void f1(long foo)
7{
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}}
14}
15
16void f2(unsigned long foo)
17{
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
24}
25
26void f3(unsigned long foo)
27{
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}}
34}
35
36void f4(long foo)
37{
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}}
44}
45
46void f5(long foo)
47{
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}}
54}
55
56void f6(long foo)
57{
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}}
64}
65
66void f7(long foo)
67{
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}}
74}
75
76void f9(long foo)
77{
78 unsigned index = -1;
79 if (index < foo) index = foo;
80 if (index - 1L == 0L) // Was not reached prior fix.
81 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
82 else
83 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
84}
85
86void f10(long foo)
87{
88 unsigned index = -1;
89 if (index < foo) index = foo;
90 if (index + 1 == 0L)
91 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
92 else
93 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
94}
95
96void f12(long foo)
97{
98 unsigned index = -1;
99 if (index < foo) index = foo;
100 if (index - 1UL == 0L) // Was not reached prior fix.
101 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
102 else
103 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
104}
105
106void f14(long foo)
107{
108 unsigned index = -1;
109 if (index < foo) index = foo;
110 long bar = foo;
111 if (index + 1 == 0)
112 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
113 else
114 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
115}
116
117void f15(long foo)
118{
119 unsigned index = -1;
120 if (index < foo) index = foo;
121 unsigned int tmp = index + 1;
122 if (tmp == 0)
123 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
124 else
125 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
126}