1 // RUN: %clang_analyze_cc1 -analyzer-output=text -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=cplusplus.NewDelete \
4 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true
6 // RUN: %clang_analyze_cc1 -analyzer-output=text -verify %s \
7 // RUN: -DTEST_INLINABLE_ALLOCATORS \
8 // RUN: -analyzer-checker=core \
9 // RUN: -analyzer-checker=cplusplus.NewDelete \
10 // RUN: -analyzer-config core.CallAndMessage:ArgPointeeInitializedness=true
12 // Passing uninitialized const data to unknown function
14 #include "Inputs/system-header-simulator-cxx.h"
16 void doStuff6(const int& c
);
17 void doStuff4(const int y
);
18 void doStuff3(int& g
);
19 void doStuff_uninit(const int *u
);
24 // FIXME: The message is misleading -- we should state that
25 // a pointer to an uninitialized value is stored.
26 ptr
= new int; // expected-note{{Storing uninitialized value}}
27 if(*ptr
) { // expected-warning{{Branch condition evaluates to a garbage value [core.uninitialized.Branch]}}
28 // expected-note@-1 {{Branch condition evaluates to a garbage value}}
37 // FIXME: The message is misleading -- we should state that
38 // a pointer to an uninitialized value is stored.
39 ptr
= new int; // expected-note{{Storing uninitialized value}}
40 // expected-note@-1{{Value assigned to 'ptr'}}
41 doStuff_uninit(ptr
); // expected-warning{{1st function call argument is a pointer to uninitialized value [core.CallAndMessage]}}
42 // expected-note@-1{{1st function call argument is a pointer to uninitialized value}}
53 doStuff_uninit(ptr
); // no warning?
60 doStuff6(m
); // no warning
64 int& f6_1_sub(int &p
) {
65 return p
; // expected-note{{Returning without writing to 'p'}}
66 // expected-note@-1{{Returning pointer (reference to 't')}}
70 int t
; // expected-note{{'t' declared without an initial value}}
71 int p
= f6_1_sub(t
); //expected-warning {{Assigned value is garbage or undefined}}
72 //expected-note@-1 {{Passing value via 1st parameter 'p'}}
73 //expected-note@-2 {{Calling 'f6_1_sub'}}
74 //expected-note@-3 {{Returning from 'f6_1_sub'}}
75 //expected-note@-4 {{Assigned value is garbage or undefined}}
81 int t
; //expected-note {{'t' declared without an initial value}}
82 int &p
= t
; //expected-note {{'p' initialized here}}
83 int &s
= p
; //expected-note {{'s' initialized to the value of 'p'}}
84 int &q
= s
; //expected-note {{'q' initialized to the value of 's'}}
85 doStuff6(q
); //expected-warning {{1st function call argument is an uninitialized value}}
86 //expected-note@-1 {{1st function call argument is an uninitialized value}}
89 void doStuff6_3(int& q_
, int *ptr_
) {}
92 int *ptr
; //expected-note {{'ptr' declared without an initial value}}
97 doStuff6_3(q
,ptr
); //expected-warning {{2nd function call argument is an uninitialized value}}
98 //expected-note@-1 {{2nd function call argument is an uninitialized value}}
103 int k
; // expected-note {{'k' declared without an initial value}}
104 doStuff6(k
); // expected-warning {{1st function call argument is an uninitialized value}}
105 // expected-note@-1 {{1st function call argument is an uninitialized value}}
112 int t
; // expected-note {{'t' declared without an initial value}}
113 int* tp
= &t
; // expected-note {{'tp' initialized here}}
114 doStuff_uninit(tp
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
115 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
120 int y
; // expected-note {{'y' declared without an initial value}}
121 doStuff4(y
); // expected-warning {{1st function call argument is an uninitialized value}}
122 // expected-note@-1 {{1st function call argument is an uninitialized value}}
127 doStuff3(g
); // no warning
132 doStuff_uninit(&z
); // no warning
137 doStuff_uninit(&x_
); // no warning
140 void f_uninit(void) {
141 int x
; // expected-note {{'x' declared without an initial value}}
142 doStuff_uninit(&x
); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
143 // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}