xref: /llvm-project/clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c (revision c202a17d024068c70364116f2d06535d79535b30)
1 // Check the bugpath related to the reports.
2 // RUN: %clang_analyze_cc1 %s \
3 // RUN:   -analyzer-checker=core \
4 // RUN:   -analyzer-checker=unix.StdCLibraryFunctions \
5 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
6 // RUN:   -analyzer-checker=debug.ExprInspection \
7 // RUN:   -triple x86_64-unknown-linux-gnu \
8 // RUN:   -analyzer-output=text \
9 // RUN:   -verify=bugpath
10 
11 typedef typeof(sizeof(int)) size_t;
12 
13 int __buf_size_arg_constraint(const void *, size_t);
test_buf_size_concrete(void)14 void test_buf_size_concrete(void) {
15   char buf[3];                       // bugpath-note{{'buf' initialized here}}
16   int s = 4;                         // bugpath-note{{'s' initialized to 4}}
17   __buf_size_arg_constraint(buf, s); // \
18   // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument}} \
19   // bugpath-note{{The 1st argument to '__buf_size_arg_constraint' is a buffer with size 3 but should be a buffer with size equal to or greater than the value of the 2nd argument}}
20 }
21 
22 int __buf_size_arg_constraint_mul(const void *, size_t, size_t);
test_buf_size_concrete_with_multiplication(void)23 void test_buf_size_concrete_with_multiplication(void) {
24   short buf[3];                               // bugpath-note{{'buf' initialized here}}
25   int s1 = 4;                                 // bugpath-note{{'s1' initialized to 4}}
26   int s2 = sizeof(short);                     // bugpath-note{{'s2' initialized to}}
27   __buf_size_arg_constraint_mul(buf, s1, s2); // \
28   // bugpath-warning{{The 1st argument to '__buf_size_arg_constraint_mul' is a buffer with size 6 but should be a buffer with size equal to or greater than the value of the 2nd argument (which is 4) times the 3rd argument (which is 2)}} \
29   // bugpath-note{{The 1st argument to '__buf_size_arg_constraint_mul' is a buffer with size 6 but should be a buffer with size equal to or greater than the value of the 2nd argument (which is 4) times the 3rd argument (which is 2)}}
30 }
31