tbaeder created this revision. tbaeder added reviewers: delesley, aaronpuchert, Eugene.Zelenko, aaron.ballman. Herald added a reviewer: NoQ. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
When we're calling a function pointer, try to get the currently known value of the variable and analyze calling that instead. I think ideally we would get all possible values at this point and analyze them all(?), but I'm not sure how to implement this. I've not added a test case because of the above issue/uncertainty, so I'd like some advice on how to implement that //or// if it's not what should happen. (I've added everyone with >100 lines in this file as a reviewer, except Caitlin Sadowski, who I can't find in Phabricator.) Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D152246 Files: clang/lib/Analysis/ThreadSafety.cpp Index: clang/lib/Analysis/ThreadSafety.cpp =================================================================== --- clang/lib/Analysis/ThreadSafety.cpp +++ clang/lib/Analysis/ThreadSafety.cpp @@ -2063,8 +2063,21 @@ examineArguments(Exp->getDirectCallee(), Exp->arg_begin(), Exp->arg_end()); } - auto *D = dyn_cast_or_null<NamedDecl>(Exp->getCalleeDecl()); - if(!D || !D->hasAttrs()) + const auto *CD = Exp->getCalleeDecl(); + if (!CD) + return; + + const auto *D = dyn_cast<NamedDecl>(CD); + // For function pointers, try to get the currently known + // value of the pointer. + if (const auto *VD = dyn_cast<VarDecl>(CD)) { + if (const Expr *E = Analyzer->LocalVarMap.lookupExpr(D, LVarCtx)) { + if (const auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) + D = DRE->getDecl(); + } + } + + if (!D->hasAttrs()) return; handleCall(Exp, D); }
Index: clang/lib/Analysis/ThreadSafety.cpp =================================================================== --- clang/lib/Analysis/ThreadSafety.cpp +++ clang/lib/Analysis/ThreadSafety.cpp @@ -2063,8 +2063,21 @@ examineArguments(Exp->getDirectCallee(), Exp->arg_begin(), Exp->arg_end()); } - auto *D = dyn_cast_or_null<NamedDecl>(Exp->getCalleeDecl()); - if(!D || !D->hasAttrs()) + const auto *CD = Exp->getCalleeDecl(); + if (!CD) + return; + + const auto *D = dyn_cast<NamedDecl>(CD); + // For function pointers, try to get the currently known + // value of the pointer. + if (const auto *VD = dyn_cast<VarDecl>(CD)) { + if (const Expr *E = Analyzer->LocalVarMap.lookupExpr(D, LVarCtx)) { + if (const auto *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParenImpCasts())) + D = DRE->getDecl(); + } + } + + if (!D->hasAttrs()) return; handleCall(Exp, D); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits