Skip to content

Commit

Permalink
[static analyzer] Fix crash in LiveVariables and Environment::getSVal…
Browse files Browse the repository at this point in the history
…() when analyzing C++ pointer-to-member calls. Fixes <rdar://problem/10243398>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@141312 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Oct 6, 2011
1 parent 8052a4f commit c808503
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/Analysis/LiveVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,10 @@ void TransferFunctions::Visit(Stmt *S) {
case Stmt::CXXMemberCallExprClass: {
// Include the implicit "this" pointer as being live.
CXXMemberCallExpr *CE = cast<CXXMemberCallExpr>(S);
val.liveStmts =
LV.SSetFact.add(val.liveStmts,
CE->getImplicitObjectArgument()->IgnoreParens());
if (Expr *ImplicitObj = CE->getImplicitObjectArgument()) {
ImplicitObj = ImplicitObj->IgnoreParens();
val.liveStmts = LV.SSetFact.add(val.liveStmts, ImplicitObj);
}
break;
}
case Stmt::DeclStmtClass: {
Expand Down
8 changes: 7 additions & 1 deletion lib/StaticAnalyzer/Core/ObjCMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ SVal CallOrObjCMessage::getCXXCallee() const {
const CallExpr *ActualCall = CallE.get<const CallExpr *>();
const Expr *callee =
cast<CXXMemberCallExpr>(ActualCall)->getImplicitObjectArgument();
return State->getSVal(callee);

// FIXME: Will eventually need to cope with member pointers. This is
// a limitation in getImplicitObjectArgument().
if (!callee)
return UnknownVal();

return State->getSVal(callee);
}

SVal
Expand Down
12 changes: 12 additions & 0 deletions test/Analysis/misc-ps-cxx0x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ void test_analyzer_working() {
*p = 0xDEADBEEF; // expected-warning {{null}}
}

// Test that pointer-to-member functions don't cause the analyzer
// to crash.
struct RDar10243398 {
void bar(int x);
};

typedef void (RDar10243398::*RDar10243398MemberFn)(int x);

void test_rdar10243398(RDar10243398 *p) {
RDar10243398MemberFn q = &RDar10243398::bar;
((*p).*(q))(1);
}

0 comments on commit c808503

Please sign in to comment.