1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \
4 // RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
5 // RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \
6 // RUN: -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
7 // RUN: -analyzer-checker=debug.ExprInspection \
8 // RUN: -analyzer-config eagerly-assume=false \
9 // RUN: -triple i686-unknown-linux \
12 // In this test we verify that each argument constraints are described properly.
14 // Check NotNullConstraint violation notes.
15 int __not_null(int *);
16 void test_not_null(int *x
) {
17 __not_null(nullptr); // \
18 // expected-note{{The 1st arg should not be NULL}} \
19 // expected-warning{{}}
22 // Check the BufferSizeConstraint violation notes.
23 using size_t = decltype(sizeof(int));
24 int __buf_size_arg_constraint_concrete(const void *); // size <= 10
25 int __buf_size_arg_constraint(const void *, size_t); // size <= Arg1
26 int __buf_size_arg_constraint_mul(const void *, size_t, size_t); // size <= Arg1 * Arg2
27 void test_buffer_size(int x
) {
31 __buf_size_arg_constraint_concrete(buf
); // \
32 // expected-note{{The size of the 1st arg should be equal to or less than the value of 10}} \
33 // expected-warning{{}}
38 __buf_size_arg_constraint(buf
, 4); // \
39 // expected-note{{The size of the 1st arg should be equal to or less than the value of the 2nd arg}} \
40 // expected-warning{{}}
45 __buf_size_arg_constraint_mul(buf
, 4, 2); // \
46 // expected-note{{The size of the 1st arg should be equal to or less than the value of the 2nd arg times the 3rd arg}} \
47 // expected-warning{{}}
53 // Check the RangeConstraint violation notes.
54 int __single_val_1(int); // [1, 1]
55 int __range_1_2(int); // [1, 2]
56 int __range_1_2__4_5(int); // [1, 2], [4, 5]
57 void test_range(int x
) {
58 __single_val_1(2); // \
59 // expected-note{{The 1st arg should be within the range [1, 1]}} \
60 // expected-warning{{}}
62 // Do more specific check against the range strings.
63 void test_range_values(int x
) {
66 __single_val_1(2); // expected-note{{[1, 1]}} \
67 // expected-warning{{}}
70 __range_1_2(3); // expected-note{{[1, 2]}} \
71 // expected-warning{{}}
74 __range_1_2__4_5(3); // expected-note{{[[1, 2], [4, 5]]}} \
75 // expected-warning{{}}
79 // Do more specific check against the range kinds.
80 int __within(int); // [1, 1]
81 int __out_of(int); // [1, 1]
82 void test_range_kind(int x
) {
85 __within(2); // expected-note{{within}} \
86 // expected-warning{{}}
89 __out_of(1); // expected-note{{out of}} \
90 // expected-warning{{}}