xref: /llvm-project/clang/test/Analysis/std-c-library-functions-arg-constraints-tracking-notes.c (revision 1ea584377e7897f7df5302ed9cd378d17be14fbf)
1 // Check the bugpath related to the reports.
2 // RUN: %clang_analyze_cc1 %s \
3 // RUN:   -analyzer-checker=core \
4 // RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
5 // RUN:   -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \
6 // RUN:   -analyzer-checker=debug.StdCLibraryFunctionsTester \
7 // RUN:   -analyzer-checker=debug.ExprInspection \
8 // RUN:   -triple x86_64-unknown-linux-gnu \
9 // RUN:   -analyzer-output=text \
10 // RUN:   -verify=bugpath
11 
12 typedef typeof(sizeof(int)) size_t;
13 
14 int __buf_size_arg_constraint(const void *, size_t);
15 void test_buf_size_concrete(void) {
16   char buf[3];                       // bugpath-note{{'buf' initialized here}}
17   int s = 4;                         // bugpath-note{{'s' initialized to 4}}
18   __buf_size_arg_constraint(buf, s); // \
19   // bugpath-warning{{Function argument constraint is not satisfied}} \
20   // bugpath-note{{}} \
21   // bugpath-note{{Function argument constraint is not satisfied}}
22 }
23 
24 int __buf_size_arg_constraint_mul(const void *, size_t, size_t);
25 void test_buf_size_concrete_with_multiplication(void) {
26   short buf[3];                               // bugpath-note{{'buf' initialized here}}
27   int s1 = 4;                                 // bugpath-note{{'s1' initialized to 4}}
28   int s2 = sizeof(short);                     // bugpath-note{{'s2' initialized to}}
29   __buf_size_arg_constraint_mul(buf, s1, s2); // \
30   // bugpath-warning{{Function argument constraint is not satisfied}} \
31   // bugpath-note{{}} \
32   // bugpath-note{{Function argument constraint is not satisfied}}
33 }
34