1 // RUN: %clang_analyze_cc1 -triple hexagon-unknown-linux -verify %s \
2 // RUN: -analyzer-checker=core,valist.Uninitialized,valist.CopyToSelf \
3 // RUN: -analyzer-disable-checker=core.CallAndMessage \
4 // RUN: -analyzer-output=text
6 // RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -verify %s \
7 // RUN: -analyzer-checker=core,valist.Uninitialized,valist.CopyToSelf \
8 // RUN: -analyzer-disable-checker=core.CallAndMessage \
9 // RUN: -analyzer-output=text
11 // RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu %s \
12 // RUN: -analyzer-checker=core,valist.Uninitialized
14 #include "Inputs/system-header-simulator-for-valist.h"
16 void f1(int fst
, ...) {
18 (void)va_arg(va
, int); // expected-warning{{va_arg() is called on an uninitialized va_list}}
19 // expected-note@-1{{va_arg() is called on an uninitialized va_list}}
22 int f2(int fst
, ...) {
24 va_start(va
, fst
); // expected-note{{Initialized va_list}}
25 va_end(va
); // expected-note{{Ended va_list}}
26 return va_arg(va
, int); // expected-warning{{va_arg() is called on an uninitialized va_list}}
27 // expected-note@-1{{va_arg() is called on an uninitialized va_list}}
30 void f3(int fst
, ...) {
35 (void)va_arg(va2
, int);
39 void f4(int cond
, ...) {
41 if (cond
) { // expected-note{{Assuming 'cond' is 0}}
42 // expected-note@-1{{Taking false branch}}
46 va_end(va
); //expected-warning{{va_end() is called on an uninitialized va_list}}
47 // expected-note@-1{{va_end() is called on an uninitialized va_list}}
50 void f5(va_list fst
, ...) {
52 (void)va_arg(fst
, int);
56 void f7(int *fst
, ...) {
64 void f8(int *fst
, ...) {
67 va_start(*y
,fst
); // expected-note{{Initialized va_list}}
68 va_end(x
); // expected-note{{Ended va_list}}
69 (void)va_arg(*y
, int); //expected-warning{{va_arg() is called on an uninitialized va_list}}
70 // expected-note@-1{{va_arg() is called on an uninitialized va_list}}
73 // This only contains problems which are handled by varargs.Unterminated.
74 void reinit(int *fst
, ...) {
78 (void)va_arg(va
, int);
81 void reinitOk(int *fst
, ...) {
84 (void)va_arg(va
, int);
87 (void)va_arg(va
, int);
91 void reinit3(int *fst
, ...) {
93 va_start(va
, fst
); // expected-note{{Initialized va_list}}
94 (void)va_arg(va
, int);
95 va_end(va
); // expected-note{{Ended va_list}}
96 va_start(va
, fst
); // expected-note{{Initialized va_list}}
97 (void)va_arg(va
, int);
98 va_end(va
); // expected-note{{Ended va_list}}
99 (void)va_arg(va
, int); //expected-warning{{va_arg() is called on an uninitialized va_list}}
100 // expected-note@-1{{va_arg() is called on an uninitialized va_list}}
103 void copyself(int fst
, ...) {
105 va_start(va
, fst
); // expected-note{{Initialized va_list}}
106 va_copy(va
, va
); // expected-warning{{va_list 'va' is copied onto itself}}
107 // expected-note@-1{{va_list 'va' is copied onto itself}}
111 void copyselfUninit(int fst
, ...) {
113 va_copy(va
, va
); // expected-warning{{va_list 'va' is copied onto itself}}
114 // expected-note@-1{{va_list 'va' is copied onto itself}}
117 void copyOverwrite(int fst
, ...) {
119 va_start(va
, fst
); // expected-note{{Initialized va_list}}
120 va_copy(va
, va2
); // expected-warning{{Initialized va_list 'va' is overwritten by an uninitialized one}}
121 // expected-note@-1{{Initialized va_list 'va' is overwritten by an uninitialized one}}
124 void copyUnint(int fst
, ...) {
126 va_copy(va
, va2
); // expected-warning{{Uninitialized va_list is copied}}
127 // expected-note@-1{{Uninitialized va_list is copied}}
130 void g1(int fst
, ...) {
132 va_end(va
); // expected-warning{{va_end() is called on an uninitialized va_list}}
133 // expected-note@-1{{va_end() is called on an uninitialized va_list}}
136 void g2(int fst
, ...) {
138 va_start(va
, fst
); // expected-note{{Initialized va_list}}
139 va_end(va
); // expected-note{{Ended va_list}}
140 va_end(va
); // expected-warning{{va_end() is called on an uninitialized va_list}}
141 // expected-note@-1{{va_end() is called on an uninitialized va_list}}
144 void is_sink(int fst
, ...) {
146 va_end(va
); // expected-warning{{va_end() is called on an uninitialized va_list}}
147 // expected-note@-1{{va_end() is called on an uninitialized va_list}}
148 *((volatile int *)0) = 1;
151 // NOTE: this is invalid, as the man page of va_end requires that "Each invocation of va_start()
152 // must be matched by a corresponding invocation of va_end() in the same function."
153 void ends_arg(va_list arg
) {
157 void uses_arg(va_list arg
) {
158 (void)va_arg(arg
, int);
161 void call_vprintf_ok(int isstring
, ...) {
163 va_start(va
, isstring
);
164 vprintf(isstring
? "%s" : "%d", va
);
168 void call_some_other_func(int n
, ...) {
170 some_library_function(n
, va
);
173 void inlined_uses_arg_good(va_list arg
) {
174 (void)va_arg(arg
, int);
177 void call_inlined_uses_arg_good(int fst
, ...) {
180 inlined_uses_arg_good(va
);
184 void va_copy_test(va_list arg
) {