[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Analysis / constraint_manager_negate_difference.c
blob0cac576a31ecc0b9c1c289b7569c2ec35bb78478
1 // RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin \
2 // RUN: -analyzer-config eagerly-assume=false \
3 // RUN: -verify %s
5 void clang_analyzer_eval(int);
7 void exit(int);
9 #define UINT_MIN (0U)
10 #define UINT_MAX (~UINT_MIN)
11 #define UINT_MID (UINT_MAX / 2 + 1)
12 #define INT_MAX (UINT_MAX & (UINT_MAX >> 1))
13 #define INT_MIN (UINT_MAX & ~(UINT_MAX >> 1))
15 extern void abort() __attribute__((__noreturn__));
16 #define assert(expr) ((expr) ? (void)(0) : abort())
18 void assert_in_range(int x) {
19 assert(x <= ((int)INT_MAX / 4));
20 assert(x >= -(((int)INT_MAX) / 4));
23 void assert_in_wide_range(int x) {
24 assert(x <= ((int)INT_MAX / 2));
25 assert(x >= -(((int)INT_MAX) / 2));
28 void assert_in_range_2(int m, int n) {
29 assert_in_range(m);
30 assert_in_range(n);
33 void equal(int m, int n) {
34 assert_in_range_2(m, n);
35 assert(m == n);
36 assert_in_wide_range(m - n);
37 clang_analyzer_eval(n == m); // expected-warning{{TRUE}}
40 void non_equal(int m, int n) {
41 assert_in_range_2(m, n);
42 assert(m != n);
43 assert_in_wide_range(m - n);
44 clang_analyzer_eval(n != m); // expected-warning{{TRUE}}
47 void less_or_equal(int m, int n) {
48 assert_in_range_2(m, n);
49 assert(m >= n);
50 assert_in_wide_range(m - n);
51 clang_analyzer_eval(n <= m); // expected-warning{{TRUE}}
54 void less(int m, int n) {
55 assert_in_range_2(m, n);
56 assert(m > n);
57 assert_in_wide_range(m - n);
58 clang_analyzer_eval(n < m); // expected-warning{{TRUE}}
61 void greater_or_equal(int m, int n) {
62 assert_in_range_2(m, n);
63 assert(m <= n);
64 assert_in_wide_range(m - n);
65 clang_analyzer_eval(n >= m); // expected-warning{{TRUE}}
68 void greater(int m, int n) {
69 assert_in_range_2(m, n);
70 assert(m < n);
71 assert_in_wide_range(m - n);
72 clang_analyzer_eval(n > m); // expected-warning{{TRUE}}
75 void negate_positive_range(int m, int n) {
76 assert(m - n > 0);
77 clang_analyzer_eval(n - m < 0); // expected-warning{{TRUE}}
78 clang_analyzer_eval(n - m > INT_MIN); // expected-warning{{TRUE}}
81 _Static_assert(INT_MIN == -INT_MIN, "");
82 void negate_int_min(int m, int n) {
83 assert(m - n == INT_MIN);
84 clang_analyzer_eval(n - m == INT_MIN); // expected-warning{{TRUE}}
87 void negate_mixed(int m, int n) {
88 assert(m - n > 0 || m - n == INT_MIN);
89 clang_analyzer_eval(n - m <= 0); // expected-warning{{TRUE}}
92 void effective_range(int m, int n) {
93 assert(m - n >= 0);
94 assert(n - m >= 0);
95 clang_analyzer_eval(m - n == 0); // expected-warning{{TRUE}}
96 clang_analyzer_eval(n - m == 0); // expected-warning{{TRUE}}
99 _Static_assert(INT_MIN == -INT_MIN, "");
100 void effective_range_2(int m, int n) {
101 assert(m - n <= 0);
102 assert(n - m <= 0);
103 clang_analyzer_eval(m - n == 0 || m - n == INT_MIN); // expected-warning{{TRUE}}
106 void negate_unsigned_min(unsigned m, unsigned n) {
107 assert(m - n == UINT_MIN);
108 clang_analyzer_eval(n - m == UINT_MIN); // expected-warning{{TRUE}}
109 clang_analyzer_eval(n - m != UINT_MIN); // expected-warning{{FALSE}}
110 clang_analyzer_eval(n - m > UINT_MIN); // expected-warning{{FALSE}}
111 clang_analyzer_eval(n - m < UINT_MIN); // expected-warning{{FALSE}}
114 _Static_assert(7u - 3u != 3u - 7u, "");
115 void negate_unsigned_4(unsigned m, unsigned n) {
116 assert(m - n == 4u);
117 clang_analyzer_eval(n - m == 4u); // expected-warning{{FALSE}}
118 clang_analyzer_eval(n - m != 4u); // expected-warning{{TRUE}}
121 _Static_assert(UINT_MID == -UINT_MID, "");
122 void negate_unsigned_mid(unsigned m, unsigned n) {
123 assert(m - n == UINT_MID);
124 clang_analyzer_eval(n - m == UINT_MID); // expected-warning{{TRUE}}
125 clang_analyzer_eval(n - m != UINT_MID); // expected-warning{{FALSE}}
128 void negate_unsigned_mid2(unsigned m, unsigned n) {
129 assert(UINT_MIN < m - n && m - n < UINT_MID);
130 clang_analyzer_eval(n - m > UINT_MID); // expected-warning{{TRUE}}
131 clang_analyzer_eval(n - m <= UINT_MAX); // expected-warning{{TRUE}}
134 _Static_assert(1u - 2u == UINT_MAX, "");
135 _Static_assert(2u - 1u == 1, "");
136 void negate_unsigned_max(unsigned m, unsigned n) {
137 assert(m - n == UINT_MAX);
138 clang_analyzer_eval(n - m == 1); // expected-warning{{TRUE}}
139 clang_analyzer_eval(n - m != 1); // expected-warning{{FALSE}}
142 void negate_unsigned_one(unsigned m, unsigned n) {
143 assert(m - n == 1);
144 clang_analyzer_eval(n - m == UINT_MAX); // expected-warning{{TRUE}}
145 clang_analyzer_eval(n - m < UINT_MAX); // expected-warning{{FALSE}}
148 // The next code is a repro for the bug PR41588
149 void negated_unsigned_range(unsigned x, unsigned y) {
150 clang_analyzer_eval(x - y != 0); // expected-warning{{UNKNOWN}}
151 clang_analyzer_eval(y - x != 0); // expected-warning{{UNKNOWN}}
152 // expected no assertion on the next line
153 clang_analyzer_eval(x - y != 0); // expected-warning{{UNKNOWN}}