[analyzer] Fix tracking expressions through negation operator

Differential Revision: https://reviews.llvm.org/D50537

llvm-svn: 339476
This commit is contained in:
George Karpenkov 2018-08-10 21:42:19 +00:00
parent 09a9e3abfe
commit b5dd3ccdbd
2 changed files with 19 additions and 0 deletions

View File

@ -1560,6 +1560,10 @@ static const Expr *peelOffOuterExpr(const Expr *Ex,
if (const Expr *SubEx = peelOffPointerArithmetic(BO)) if (const Expr *SubEx = peelOffPointerArithmetic(BO))
return peelOffOuterExpr(SubEx, N); return peelOffOuterExpr(SubEx, N);
if (auto *UO = dyn_cast<UnaryOperator>(Ex))
if (UO->getOpcode() == UO_LNot)
return peelOffOuterExpr(UO->getSubExpr(), N);
return Ex; return Ex;
} }

View File

@ -357,3 +357,18 @@ int forceElementRegionApperence() {
return ((HasFieldB*)&a)->x; // expected-warning{{Undefined or garbage value returned to caller}} return ((HasFieldB*)&a)->x; // expected-warning{{Undefined or garbage value returned to caller}}
// expected-note@-1{{Undefined or garbage value returned to caller}} // expected-note@-1{{Undefined or garbage value returned to caller}}
} }
////////
struct HasForgottenField {
int x;
HasForgottenField() {} // expected-note{{Returning without writing to 'this->x'}}
};
// Test that tracking across exclamation mark works.
bool tracksThroughExclamationMark() {
HasForgottenField a; // expected-note{{Calling default constructor for 'HasForgottenField'}}
// expected-note@-1{{Returning from default constructor for 'HasForgottenField'}}
return !a.x; // expected-warning{{Undefined or garbage value returned to caller}}
// expected-note@-1{{Undefined or garbage value returned to caller}}
}