[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / array-bound-v2-constraint-check.c
blobdc138196b56a946ac7918a3ff5c8be0907cece0e
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.security.ArrayBoundV2,debug.ExprInspection \
2 // RUN: -analyzer-config eagerly-assume=false -verify %s
4 void clang_analyzer_eval(int);
5 void clang_analyzer_printState(void);
7 typedef unsigned long long size_t;
8 const char a[] = "abcd"; // extent: 5 bytes
10 void symbolic_size_t_and_int0(size_t len) {
11 (void)a[len + 1]; // no-warning
12 // We infered that the 'len' must be in a specific range to make the previous indexing valid.
13 // len: [0,3]
14 clang_analyzer_eval(len <= 3); // expected-warning {{TRUE}}
15 clang_analyzer_eval(len <= 2); // expected-warning {{UNKNOWN}}
18 void symbolic_size_t_and_int1(size_t len) {
19 (void)a[len]; // no-warning
20 // len: [0,4]
21 clang_analyzer_eval(len <= 4); // expected-warning {{TRUE}}
22 clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
25 void symbolic_size_t_and_int2(size_t len) {
26 (void)a[len - 1]; // no-warning
27 // len: [1,5]
28 clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
29 clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
30 clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
33 void symbolic_uint_and_int0(unsigned len) {
34 (void)a[len + 1]; // no-warning
35 // len: [0,3]
36 clang_analyzer_eval(0 <= len && len <= 3); // expected-warning {{TRUE}}
37 clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
38 clang_analyzer_eval(len <= 2); // expected-warning {{UNKNOWN}}
41 void symbolic_uint_and_int1(unsigned len) {
42 (void)a[len]; // no-warning
43 // len: [0,4]
44 clang_analyzer_eval(0 <= len && len <= 4); // expected-warning {{TRUE}}
45 clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
46 clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
48 void symbolic_uint_and_int2(unsigned len) {
49 (void)a[len - 1]; // no-warning
50 // len: [1,5]
51 clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
52 clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
53 clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
56 void symbolic_int_and_int0(int len) {
57 (void)a[len + 1]; // no-warning
58 // len: [-1,3]
59 clang_analyzer_eval(-1 <= len && len <= 3); // expected-warning {{TRUE}}
60 clang_analyzer_eval(0 <= len); // expected-warning {{UNKNOWN}}
61 clang_analyzer_eval(len <= 2); // expected-warning {{UNKNOWN}}
63 void symbolic_int_and_int1(int len) {
64 (void)a[len]; // no-warning
65 // len: [0,4]
66 clang_analyzer_eval(0 <= len && len <= 4); // expected-warning {{TRUE}}
67 clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
68 clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
70 void symbolic_int_and_int2(int len) {
71 (void)a[len - 1]; // no-warning
72 // len: [1,5]
73 clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
74 clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
75 clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}
78 void symbolic_longlong_and_int0(long long len) {
79 (void)a[len + 1]; // no-warning
80 // len: [-1,3]
81 clang_analyzer_eval(-1 <= len && len <= 3); // expected-warning {{TRUE}}
82 clang_analyzer_eval(0 <= len); // expected-warning {{UNKNOWN}}
83 clang_analyzer_eval(len <= 2); // expected-warning {{UNKNOWN}}
86 void symbolic_longlong_and_int1(long long len) {
87 (void)a[len]; // no-warning
88 // len: [0,4]
89 clang_analyzer_eval(0 <= len && len <= 4); // expected-warning {{TRUE}}
90 clang_analyzer_eval(1 <= len); // expected-warning {{UNKNOWN}}
91 clang_analyzer_eval(len <= 3); // expected-warning {{UNKNOWN}}
94 void symbolic_longlong_and_int2(long long len) {
95 (void)a[len - 1]; // no-warning
96 // len: [1,5]
97 clang_analyzer_eval(1 <= len && len <= 5); // expected-warning {{TRUE}}
98 clang_analyzer_eval(2 <= len); // expected-warning {{UNKNOWN}}
99 clang_analyzer_eval(len <= 4); // expected-warning {{UNKNOWN}}