Debian Codegraph @

clang/test/Analysis/call-and-message-argpointeeinitializedness.cpp

raw
1 // RUN: %clang_analyze_cc1 %s -verify=initializedness-complete \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true \
4 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializednessComplete=true \
5 // RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false
6
7 // RUN: %clang_analyze_cc1 %s -verify=initializedness-partial \
8 // RUN: -analyzer-checker=core \
9 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true \
10 // RUN: -analyzer-config core.CallAndMessage:ArgInitializedness=false
11
12 struct S1 {
13 char c;
14 };
15
16 struct S {
17 int a;
18 S1 b;
19 };
20
21 S GlobalS;
22
23 void doStuffP(const S *);
24 void doStuffR(const S &);
25
26 void uninit_val_p() {
27 S s;
28 doStuffP(&s); // initializedness-partial-warning{{1st function call argument points to an uninitialized value (e.g., field: 'a')}} \
29 // initializedness-complete-warning{{1st function call argument points to an uninitialized value}}
30 }
31
32 void uninit_val_r() {
33 S s;
34 doStuffR(s); // initializedness-partial-warning{{1st function call argument references an uninitialized value (e.g., field: 'a')}} \
35 // initializedness-complete-warning{{1st function call argument references an uninitialized value}}
36 }
37
38 S *uninit_new() {
39 S *s = new S;
40 doStuffP(s); // initializedness-partial-warning{{1st function call argument points to an uninitialized value (e.g., field: 'a')}} \
41 // initializedness-complete-warning{{1st function call argument points to an uninitialized value}}
42 return s;
43 }
44
45 void uninit_ctr() {
46 S s = S();
47 doStuffP(&s);
48 }
49
50 void uninit_init() {
51 S s{};
52 doStuffP(&s);
53 }
54
55 void uninit_init_val() {
56 S s{1, {2}};
57 doStuffP(&s);
58 }
59
60 void uninit_parm_ptr(S *s) {
61 doStuffP(s);
62 }
63
64 void uninit_parm_val(S s) {
65 doStuffP(&s);
66 }
67
68 void uninit_parm_ref(S &s) {
69 doStuffP(&s);
70 }
71
72 void init_val() {
73 S s;
74 s.a = 1;
75 s.b.c = 1;
76 doStuffP(&s);
77 }
78
79 void uninit_global() {
80 doStuffP(&GlobalS);
81 }
82
83 void uninit_static() {
84 static S s;
85 doStuffP(&s);
86 }
87
88 void uninit_val_partial_1() {
89 S s;
90 s.a = 1;
91 doStuffR(s); // initializedness-partial-warning{{1st function call argument references an uninitialized value (e.g., via the field chain: 'b.c')}}
92 }
93
94 void uninit_val_partial_2() {
95 S s;
96 s.b.c = 1;
97 doStuffR(s); // initializedness-partial-warning{{1st function call argument references an uninitialized value (e.g., field: 'a')}}
98 }