blob: 528ac86c142130161b5002daa8ae22560970023c [file] [log] [blame]
Gabor Horvath60eec1a2017-03-13 12:48:26 +00001// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-gnu -analyzer-checker=core,valist.Uninitialized,valist.CopyToSelf -analyzer-output=text -analyzer-store=region -verify %s
Gabor Horvathdbf27902017-03-07 16:04:23 +00002
3#include "Inputs/system-header-simulator-for-valist.h"
4
5// This is called in call_inlined_uses_arg(),
6// and the warning is generated during the analysis of call_inlined_uses_arg().
7void inlined_uses_arg(va_list arg) {
8 (void)va_arg(arg, int); // expected-warning{{va_arg() is called on an uninitialized va_list}}
9 // expected-note@-1{{va_arg() is called on an uninitialized va_list}}
10}
11
12void call_inlined_uses_arg(int fst, ...) {
13 va_list va;
14 inlined_uses_arg(va); // expected-note{{Calling 'inlined_uses_arg'}}
15}
16
17void f6(va_list *fst, ...) {
18 va_start(*fst, fst);
19 // FIXME: There should be no warning for this.
20 (void)va_arg(*fst, int); // expected-warning{{va_arg() is called on an uninitialized va_list}}
21 // expected-note@-1{{va_arg() is called on an uninitialized va_list}}
22 va_end(*fst);
23}
24
25void call_vprintf_bad(int isstring, ...) {
26 va_list va;
27 vprintf(isstring ? "%s" : "%d", va); // expected-warning{{Function 'vprintf' is called with an uninitialized va_list argument}}
28 // expected-note@-1{{Function 'vprintf' is called with an uninitialized va_list argument}}
29 // expected-note@-2{{Assuming 'isstring' is 0}}
30 // expected-note@-3{{'?' condition is false}}
31}
32
33void call_vsprintf_bad(char *buffer, ...) {
34 va_list va;
35 va_start(va, buffer); // expected-note{{Initialized va_list}}
36 va_end(va); // expected-note{{Ended va_list}}
37 vsprintf(buffer, "%s %d %d %lf %03d", va); // expected-warning{{Function 'vsprintf' is called with an uninitialized va_list argument}}
38 // expected-note@-1{{Function 'vsprintf' is called with an uninitialized va_list argument}}
39}
40