[RISCV][FMV] Support target_clones (#85786)
[llvm-project.git] / clang / test / Analysis / constraint_manager_negate.c
blobd955973e1911ed7999aa6c525631cc2e26d1c86b
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);
6 void clang_analyzer_dump(int);
8 void exit(int);
10 #define UINT_MIN (0U)
11 #define UINT_MAX (~UINT_MIN)
12 #define UINT_MID (UINT_MAX / 2 + 1)
13 #define INT_MAX (UINT_MAX & (UINT_MAX >> 1))
14 #define INT_MIN (UINT_MAX & ~(UINT_MAX >> 1))
16 extern void abort() __attribute__((__noreturn__));
17 #define assert(expr) ((expr) ? (void)(0) : abort())
19 void negate_positive_range(int a) {
20 assert(-a > 0);
21 // -a: [1, INT_MAX]
22 // a: [INT_MIN + 1, -1]
23 clang_analyzer_eval(a < 0); // expected-warning{{TRUE}}
24 clang_analyzer_eval(a > INT_MIN); // expected-warning{{TRUE}}
27 void negate_positive_range2(int a) {
28 assert(a > 0);
29 // a: [1, INT_MAX]
30 // -a: [INT_MIN + 1, -1]
31 clang_analyzer_eval(-a < 0); // expected-warning{{TRUE}}
32 clang_analyzer_eval(-a > INT_MIN); // expected-warning{{TRUE}}
35 // INT_MIN equals 0b100...00.
36 // Its two's compelement is 0b011...11 + 1 = 0b100...00 (itself).
37 _Static_assert(INT_MIN == -INT_MIN, "");
38 void negate_int_min(int a) {
39 assert(a == INT_MIN);
40 clang_analyzer_eval(-a == INT_MIN); // expected-warning{{TRUE}}
43 void negate_mixed(int a) {
44 assert(a > 0 || a == INT_MIN);
45 clang_analyzer_eval(-a <= 0); // expected-warning{{TRUE}}
48 void effective_range(int a) {
49 assert(a >= 0);
50 assert(-a >= 0);
51 clang_analyzer_eval(a == 0); // expected-warning{{TRUE}}
52 clang_analyzer_eval(-a == 0); // expected-warning{{TRUE}}
55 _Static_assert(-INT_MIN == INT_MIN, "");
56 void effective_range_2(int a) {
57 assert(a <= 0);
58 assert(-a <= 0);
59 clang_analyzer_eval(a == 0 || a == INT_MIN); // expected-warning{{TRUE}}
62 void negate_symexpr(int a, int b) {
63 assert(3 <= a * b && a * b <= 5);
64 clang_analyzer_eval(-(a * b) >= -5); // expected-warning{{TRUE}}
65 clang_analyzer_eval(-(a * b) <= -3); // expected-warning{{TRUE}}
68 void negate_unsigned_min(unsigned a) {
69 assert(a == UINT_MIN);
70 clang_analyzer_eval(-a == UINT_MIN); // expected-warning{{TRUE}}
71 clang_analyzer_eval(-a != UINT_MIN); // expected-warning{{FALSE}}
72 clang_analyzer_eval(-a > UINT_MIN); // expected-warning{{FALSE}}
73 clang_analyzer_eval(-a < UINT_MIN); // expected-warning{{FALSE}}
76 _Static_assert(7u - 3u != 3u - 7u, "");
77 _Static_assert(-4u == UINT_MAX - 3u, "");
78 void negate_unsigned_4(unsigned a) {
79 assert(a == 4u);
80 clang_analyzer_eval(-a == 4u); // expected-warning{{FALSE}}
81 clang_analyzer_eval(-a != 4u); // expected-warning{{TRUE}}
82 clang_analyzer_eval(-a == UINT_MAX - 3u); // expected-warning{{TRUE}}
85 // UINT_MID equals 0b100...00.
86 // Its two's compelement is 0b011...11 + 1 = 0b100...00 (itself).
87 _Static_assert(UINT_MID == -UINT_MID, "");
88 void negate_unsigned_mid(unsigned a) {
89 assert(a == UINT_MID);
90 clang_analyzer_eval(-a == UINT_MID); // expected-warning{{TRUE}}
91 clang_analyzer_eval(-a != UINT_MID); // expected-warning{{FALSE}}
94 void negate_unsigned_mid2(unsigned a) {
95 assert(UINT_MIN < a && a < UINT_MID);
96 // a: [UINT_MIN+1, UINT_MID-1]
97 // -a: [UINT_MID+1, UINT_MAX]
98 clang_analyzer_eval(-a > UINT_MID); // expected-warning{{TRUE}}
99 clang_analyzer_eval(-a <= UINT_MAX); // expected-warning{{TRUE}}
102 _Static_assert(1u - 2u == UINT_MAX, "");
103 _Static_assert(2u - 1u == 1, "");
104 void negate_unsigned_max(unsigned a) {
105 assert(a == UINT_MAX);
106 clang_analyzer_eval(-a == 1); // expected-warning{{TRUE}}
107 clang_analyzer_eval(-a != 1); // expected-warning{{FALSE}}
109 void negate_unsigned_one(unsigned a) {
110 assert(a == 1);
111 clang_analyzer_eval(-a == UINT_MAX); // expected-warning{{TRUE}}
112 clang_analyzer_eval(-a < UINT_MAX); // expected-warning{{FALSE}}