[analyzer] Look through ExprWhenCleanups when trying to track a NULL.

Silences a few false positives in LLVM.

llvm-svn: 177186
This commit is contained in:
Jordan Rose 2013-03-15 21:41:46 +00:00
parent 755a2ffd79
commit ecaa7d2c3d
2 changed files with 43 additions and 6 deletions

View File

@ -778,7 +778,8 @@ bool bugreporter::trackNullOrUndefValue(const ExplodedNode *N,
if (!S || !N)
return false;
// Peel off OpaqueValueExpr.
if (const ExprWithCleanups *EWC = dyn_cast<ExprWithCleanups>(S))
S = EWC->getSubExpr();
if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(S))
S = OVE->getSourceExpr();

View File

@ -40,6 +40,11 @@ inline void* operator new(__typeof__(sizeof(int)), void* __p) throw()
extern bool coin();
class SomeClass {
public:
void doSomething();
};
namespace References {
class Map {
int *&getNewBox();
@ -83,11 +88,6 @@ namespace References {
*box = 1; // expected-warning {{Dereference of null pointer}}
}
class SomeClass {
public:
void doSomething();
};
SomeClass *&getSomeClass() {
if (coin()) {
extern SomeClass *&opaqueClass();
@ -174,3 +174,39 @@ void test3() {
}
namespace Cleanups {
class NonTrivial {
public:
~NonTrivial();
SomeClass *getNull() {
return 0;
}
};
void testImmediate() {
NonTrivial().getNull()->doSomething();
#ifndef SUPPRESSED
// expected-warning@-2 {{Called C++ object pointer is null}}
#endif
}
void testAssignment() {
SomeClass *ptr = NonTrivial().getNull();
ptr->doSomething();
#ifndef SUPPRESSED
// expected-warning@-2 {{Called C++ object pointer is null}}
#endif
}
void testArgumentHelper(SomeClass *arg) {
arg->doSomething();
#ifndef SUPPRESSED
// expected-warning@-2 {{Called C++ object pointer is null}}
#endif
}
void testArgument() {
testArgumentHelper(NonTrivial().getNull());
}
}