1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config suppress-null-return-paths=false -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify -DSUPPRESSED=1 %s
4 namespace rdar12676053
{
5 // Delta-reduced from a preprocessed file.
10 T
*operator->() const {
17 class ParserInputState
{
23 void setFilename(const string
& f
) {
24 inputState
->filename
= f
;
26 // expected-warning@-2 {{Called C++ object pointer is null}}
30 RefCount
<ParserInputState
> inputState
;
35 // This is the standard placement new.
36 inline void* operator new(__typeof__(sizeof(int)), void* __p
) throw()
48 namespace References
{
54 int *&getValue(int key
) {
58 int *&newBox
= getNewBox();
64 int *&getValueIndirectly(int key
) {
65 int *&valueBox
= getValue(key
);
70 void testMap(Map
&m
, int i
) {
73 // expected-warning@-2 {{Dereference of null pointer}}
76 *m
.getValueIndirectly(i
) = 1;
78 // expected-warning@-2 {{Dereference of null pointer}}
81 int *&box
= m
.getValue(i
);
82 extern int *getPointer();
84 *box
= 1; // no-warning
86 int *&box2
= m
.getValue(i
);
88 *box2
= 1; // expected-warning {{Dereference of null pointer}}
91 SomeClass
*&getSomeClass() {
93 extern SomeClass
*&opaqueClass();
96 static SomeClass
*sharedClass
;
103 getSomeClass()->doSomething();
105 // expected-warning@-2 {{Called C++ object pointer is null}}
108 // Separate the lvalue-to-rvalue conversion from the subsequent dereference.
109 SomeClass
*object
= getSomeClass();
110 object
->doSomething();
112 // expected-warning@-2 {{Called C++ object pointer is null}}
116 SomeClass
*getNull() {
120 SomeClass
&returnNullReference() {
121 SomeClass
*x
= getNull();
124 // expected-warning@-2 {{Returning null reference}}
138 void deref1(X
*const &p
) {
141 // expected-warning@-2 {{Called C++ object pointer is null}}
146 return deref1(getNull());
152 // expected-warning@-2 {{Called C++ object pointer is null}}
156 void pass2(X
*const &p2
) {
164 void deref3(X
*const &p2
) {
168 // expected-warning@-2 {{Called C++ object pointer is null}}
182 SomeClass
*getNull() {
187 void testImmediate() {
188 NonTrivial().getNull()->doSomething();
190 // expected-warning@-2 {{Called C++ object pointer is null}}
194 void testAssignment() {
195 SomeClass
*ptr
= NonTrivial().getNull();
198 // expected-warning@-2 {{Called C++ object pointer is null}}
202 void testArgumentHelper(SomeClass
*arg
) {
205 // expected-warning@-2 {{Called C++ object pointer is null}}
209 void testArgument() {
210 testArgumentHelper(NonTrivial().getNull());