зеркало из https://github.com/microsoft/clang-1.git
[analyzer] bugreporter::getDerefExpr now takes a Stmt, not an ExplodedNode.
This allows it to be used in places where the interesting statement doesn't match up with the current node. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173546 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
aeca2cc3a6
Коммит
dede2fd56d
|
@ -275,7 +275,7 @@ namespace bugreporter {
|
|||
bool trackNullOrUndefValue(const ExplodedNode *N, const Stmt *S, BugReport &R,
|
||||
bool IsArg = false);
|
||||
|
||||
const Stmt *GetDerefExpr(const ExplodedNode *N);
|
||||
const Expr *getDerefExpr(const Stmt *S);
|
||||
const Stmt *GetDenomExpr(const ExplodedNode *N);
|
||||
const Stmt *GetRetValExpr(const ExplodedNode *N);
|
||||
bool isDeclRefExprToReference(const Expr *E);
|
||||
|
|
|
@ -157,7 +157,7 @@ void DereferenceChecker::reportBug(ProgramStateRef State, const Stmt *S,
|
|||
buf.empty() ? BT_null->getDescription() : buf.str(),
|
||||
N);
|
||||
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::GetDerefExpr(N), *report);
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::getDerefExpr(S), *report);
|
||||
|
||||
for (SmallVectorImpl<SourceRange>::iterator
|
||||
I = Ranges.begin(), E = Ranges.end(); I!=E; ++I)
|
||||
|
@ -176,7 +176,7 @@ void DereferenceChecker::checkLocation(SVal l, bool isLoad, const Stmt* S,
|
|||
|
||||
BugReport *report =
|
||||
new BugReport(*BT_undef, BT_undef->getDescription(), N);
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::GetDerefExpr(N),
|
||||
bugreporter::trackNullOrUndefValue(N, bugreporter::getDerefExpr(S),
|
||||
*report);
|
||||
C.emitReport(report);
|
||||
}
|
||||
|
|
|
@ -38,37 +38,33 @@ bool bugreporter::isDeclRefExprToReference(const Expr *E) {
|
|||
return false;
|
||||
}
|
||||
|
||||
const Stmt *bugreporter::GetDerefExpr(const ExplodedNode *N) {
|
||||
const Expr *bugreporter::getDerefExpr(const Stmt *S) {
|
||||
// Pattern match for a few useful cases (do something smarter later):
|
||||
// a[0], p->f, *p
|
||||
const PostStmt *Loc = N->getLocationAs<PostStmt>();
|
||||
if (!Loc)
|
||||
const Expr *E = dyn_cast<Expr>(S);
|
||||
if (!E)
|
||||
return 0;
|
||||
|
||||
const Expr *S = dyn_cast<Expr>(Loc->getStmt());
|
||||
if (!S)
|
||||
return 0;
|
||||
S = S->IgnoreParenCasts();
|
||||
E = E->IgnoreParenCasts();
|
||||
|
||||
while (true) {
|
||||
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(S)) {
|
||||
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(E)) {
|
||||
assert(B->isAssignmentOp());
|
||||
S = B->getLHS()->IgnoreParenCasts();
|
||||
E = B->getLHS()->IgnoreParenCasts();
|
||||
continue;
|
||||
}
|
||||
else if (const UnaryOperator *U = dyn_cast<UnaryOperator>(S)) {
|
||||
else if (const UnaryOperator *U = dyn_cast<UnaryOperator>(E)) {
|
||||
if (U->getOpcode() == UO_Deref)
|
||||
return U->getSubExpr()->IgnoreParenCasts();
|
||||
}
|
||||
else if (const MemberExpr *ME = dyn_cast<MemberExpr>(S)) {
|
||||
else if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
|
||||
if (ME->isArrow() || isDeclRefExprToReference(ME->getBase())) {
|
||||
return ME->getBase()->IgnoreParenCasts();
|
||||
}
|
||||
}
|
||||
else if (const ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(S)) {
|
||||
else if (const ObjCIvarRefExpr *IvarRef = dyn_cast<ObjCIvarRefExpr>(E)) {
|
||||
return IvarRef->getBase()->IgnoreParenCasts();
|
||||
}
|
||||
else if (const ArraySubscriptExpr *AE = dyn_cast<ArraySubscriptExpr>(S)) {
|
||||
else if (const ArraySubscriptExpr *AE = dyn_cast<ArraySubscriptExpr>(E)) {
|
||||
return AE->getBase();
|
||||
}
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче