1 // RUN: %clang_analyze_cc1 -triple hexagon-unknown-linux -analyzer-checker=core,valist.Unterminated,valist.CopyToSelf -analyzer-output=text -verify %s
2 // RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,valist.Unterminated,valist.CopyToSelf -analyzer-output=text -verify %s
4 #include "Inputs/system-header-simulator-for-valist.h"
6 void f1(int fst
, ...) {
8 va_start(va
, fst
); // expected-note{{Initialized va_list}}
9 return; // expected-warning{{Initialized va_list 'va' is leaked}}
10 // expected-note@-1{{Initialized va_list 'va' is leaked}}
13 void f2(int fst
, ...) {
15 va_start(va
, fst
); // expected-note{{Initialized va_list}}
16 va_end(va
); // expected-note{{Ended va_list}}
17 va_start(va
, fst
); // expected-note{{Initialized va_list}}
18 } // expected-warning{{Initialized va_list 'va' is leaked}}
19 // expected-note@-1{{Initialized va_list 'va' is leaked}}
21 void f3(int fst
, ...) {
24 va_copy(va2
, va
); // expected-note{{Initialized va_list}}
25 va_end(va
); // expected-warning{{Initialized va_list 'va2' is leaked}}
26 // expected-note@-1{{Initialized va_list 'va2' is leaked}}
29 void f4(va_list *fst
, ...) {
30 va_start(*fst
, fst
); // expected-note{{Initialized va_list}}
31 return; // expected-warning{{Initialized va_list is leaked}}
32 // expected-note@-1{{Initialized va_list is leaked}}
35 void f5(va_list fst
, ...) {
36 va_start(fst
, fst
); // expected-note{{Initialized va_list}}
37 } // expected-warning{{Initialized va_list}}
38 // expected-note@-1{{Initialized va_list}}
40 void f6(va_list *fst
, ...) {
41 va_start(*fst
, fst
); // expected-note{{Initialized va_list}}
42 (void)va_arg(*fst
, int);
43 //FIXME: this should NOT cause a warning
44 va_end(*fst
); // expected-warning{{Initialized va_list is leaked}}
45 // expected-note@-1{{Initialized va_list is leaked}}
48 void f7(int *fst
, ...) {
51 va_start(*y
,fst
); // expected-note{{Initialized va_list}}
52 } // expected-warning{{Initialized va_list 'x' is leaked}}
53 // expected-note@-1{{Initialized va_list 'x' is leaked}}
55 void f8(int *fst
, ...) {
62 void reinit(int *fst
, ...) {
64 va_start(va
, fst
); // expected-note{{Initialized va_list}}
65 // expected-note@-1{{Initialized va_list}}
66 va_start(va
, fst
); // expected-warning{{Initialized va_list 'va' is initialized again}}
67 // expected-note@-1{{Initialized va_list 'va' is initialized again}}
68 } // expected-warning{{Initialized va_list 'va' is leaked}}
69 // expected-note@-1{{Initialized va_list 'va' is leaked}}
71 void reinitOk(int *fst
, ...) {
79 void copyself(int fst
, ...) {
81 va_start(va
, fst
); // expected-note{{Initialized va_list}}
82 va_copy(va
, va
); // expected-warning{{va_list 'va' is copied onto itself}}
83 // expected-note@-1{{va_list 'va' is copied onto itself}}
87 void copyselfUninit(int fst
, ...) {
89 va_copy(va
, va
); // expected-warning{{va_list 'va' is copied onto itself}}
90 // expected-note@-1{{va_list 'va' is copied onto itself}}
93 void copyOverwrite(int fst
, ...) {
95 va_start(va
, fst
); // expected-note{{Initialized va_list}}
96 va_copy(va
, va2
); // expected-warning{{Initialized va_list 'va' is overwritten by an uninitialized one}}
97 // expected-note@-1{{Initialized va_list 'va' is overwritten by an uninitialized one}}
100 //This only generates a warning for the valist.Uninitialized checker
101 void copyUnint(int fst
, ...) {
106 void recopy(int fst
, ...) {
109 va_copy(va2
, va
); // expected-note{{Initialized va_list}}
110 va_copy(va2
, va
); // expected-warning{{Initialized va_list 'va2' is initialized again}}
111 // expected-note@-1{{Initialized va_list 'va2' is initialized again}}
116 void doublemsg(int fst
, ...) {
118 va_start(va
, fst
), va_start(va2
, fst
); // expected-warning{{Initialized va_list 'va' is leaked}}
119 // expected-warning@-1{{Initialized va_list 'va2' is leaked}}
120 // expected-note@-2{{Initialized va_list}}
121 // expected-note@-3{{Initialized va_list}}
122 // expected-note@-4{{Initialized va_list}}
123 // expected-note@-5{{Initialized va_list 'va' is leaked}}
126 void in_array(int fst
, ...) {
128 va_start(va_array
[3], fst
); // expected-note{{Initialized va_list}}
129 } // expected-warning{{Initialized va_list 'va_array[3]' is leaked}}
130 // expected-note@-1{{Initialized va_list 'va_array[3]' is leaked}}
132 struct containing_a_valist
{
137 void in_struct(int fst
, ...) {
138 struct containing_a_valist s
;
139 va_start(s
.vafield
, fst
); // expected-note{{Initialized va_list}}
140 } // expected-warning{{Initialized va_list 's.vafield' is leaked}}
141 // expected-note@-1{{Initialized va_list 's.vafield' is leaked}}
143 void casting(int fst
, ...) {
144 char mem
[sizeof(va_list)];
145 va_start(*(va_list *) mem
, fst
); // expected-note{{Initialized va_list}}
146 } // expected-warning{{Initialized va_list 'mem[0]' is leaked}}
147 // expected-note@-1{{Initialized va_list 'mem[0]' is leaked}}
150 void castingOk(int fst
, ...) {
151 char mem
[sizeof(va_list)];
152 va_start(*(va_list *) mem
, fst
);
153 va_end(*(va_list *) mem
);