forked from OSchip/llvm-project
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. llvm-svn: 342519
This commit is contained in:
parent
b64f71b029
commit
f6ccde7810
|
@ -354,7 +354,8 @@ til::SExpr *SExprBuilder::translateCallExpr(const CallExpr *CE,
|
|||
const Expr *SelfE) {
|
||||
if (CapabilityExprMode) {
|
||||
// Handle LOCK_RETURNED
|
||||
const FunctionDecl *FD = CE->getDirectCallee()->getMostRecentDecl();
|
||||
if (const FunctionDecl *FD = CE->getDirectCallee()) {
|
||||
FD = FD->getMostRecentDecl();
|
||||
if (LockReturnedAttr *At = FD->getAttr<LockReturnedAttr>()) {
|
||||
CallingContext LRCallCtx(Ctx);
|
||||
LRCallCtx.AttrDecl = CE->getDirectCallee();
|
||||
|
@ -365,6 +366,7 @@ til::SExpr *SExprBuilder::translateCallExpr(const CallExpr *CE,
|
|||
translateAttrExpr(At->getArg(), &LRCallCtx).sexpr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
til::SExpr *E = translate(CE->getCallee(), Ctx);
|
||||
for (const auto *Arg : CE->arguments()) {
|
||||
|
|
|
@ -2323,6 +2323,7 @@ Foo& getBarFoo(Bar &bar, int c) { return bar.getFoo2(c); }
|
|||
void test() {
|
||||
Foo foo;
|
||||
Foo *fooArray;
|
||||
Foo &(*fooFuncPtr)();
|
||||
Bar bar;
|
||||
int a;
|
||||
int b;
|
||||
|
@ -2359,6 +2360,10 @@ void test() {
|
|||
(a > 0 ? fooArray[1] : fooArray[b]).mu_.Lock();
|
||||
(a > 0 ? fooArray[1] : fooArray[b]).a = 0;
|
||||
(a > 0 ? fooArray[1] : fooArray[b]).mu_.Unlock();
|
||||
|
||||
fooFuncPtr().mu_.Lock();
|
||||
fooFuncPtr().a = 0;
|
||||
fooFuncPtr().mu_.Unlock();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue