Thread safety analysis: Fix crash for function pointers

For function pointers, the FunctionDecl of the callee is unknown, so
getDirectCallee will return nullptr. We have to catch that case to avoid
crashing. We assume there is no attribute then.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342519 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Aaron Puchert 2018-09-19 00:19:38 +00:00
parent 30d3f201ef
commit 4a9b0e9a58
2 changed files with 16 additions and 9 deletions

View File

@ -354,15 +354,17 @@ til::SExpr *SExprBuilder::translateCallExpr(const CallExpr *CE,
const Expr *SelfE) { const Expr *SelfE) {
if (CapabilityExprMode) { if (CapabilityExprMode) {
// Handle LOCK_RETURNED // Handle LOCK_RETURNED
const FunctionDecl *FD = CE->getDirectCallee()->getMostRecentDecl(); if (const FunctionDecl *FD = CE->getDirectCallee()) {
if (LockReturnedAttr* At = FD->getAttr<LockReturnedAttr>()) { FD = FD->getMostRecentDecl();
CallingContext LRCallCtx(Ctx); if (LockReturnedAttr *At = FD->getAttr<LockReturnedAttr>()) {
LRCallCtx.AttrDecl = CE->getDirectCallee(); CallingContext LRCallCtx(Ctx);
LRCallCtx.SelfArg = SelfE; LRCallCtx.AttrDecl = CE->getDirectCallee();
LRCallCtx.NumArgs = CE->getNumArgs(); LRCallCtx.SelfArg = SelfE;
LRCallCtx.FunArgs = CE->getArgs(); LRCallCtx.NumArgs = CE->getNumArgs();
return const_cast<til::SExpr *>( LRCallCtx.FunArgs = CE->getArgs();
translateAttrExpr(At->getArg(), &LRCallCtx).sexpr()); return const_cast<til::SExpr *>(
translateAttrExpr(At->getArg(), &LRCallCtx).sexpr());
}
} }
} }

View File

@ -2323,6 +2323,7 @@ Foo& getBarFoo(Bar &bar, int c) { return bar.getFoo2(c); }
void test() { void test() {
Foo foo; Foo foo;
Foo *fooArray; Foo *fooArray;
Foo &(*fooFuncPtr)();
Bar bar; Bar bar;
int a; int a;
int b; int b;
@ -2359,6 +2360,10 @@ void test() {
(a > 0 ? fooArray[1] : fooArray[b]).mu_.Lock(); (a > 0 ? fooArray[1] : fooArray[b]).mu_.Lock();
(a > 0 ? fooArray[1] : fooArray[b]).a = 0; (a > 0 ? fooArray[1] : fooArray[b]).a = 0;
(a > 0 ? fooArray[1] : fooArray[b]).mu_.Unlock(); (a > 0 ? fooArray[1] : fooArray[b]).mu_.Unlock();
fooFuncPtr().mu_.Lock();
fooFuncPtr().a = 0;
fooFuncPtr().mu_.Unlock();
} }