@@ -183,17 +183,6 @@ static void insertIfFunction(const Decl &D,
183183 Funcs.insert (FD);
184184}
185185
186- static void insertIfParamOfNotThePrimaryFunction (
187- const Decl &D, llvm::SetVector<const ParmVarDecl *> &Locals,
188- const FunctionDecl *PrimaryFunction) {
189- if (auto *PVD = dyn_cast<ParmVarDecl>(&D)) {
190- if (!PrimaryFunction ||
191- PVD->getParentFunctionOrMethod () != PrimaryFunction) {
192- Locals.insert (PVD);
193- }
194- }
195- }
196-
197186static MemberExpr *getMemberForAccessor (const CXXMemberCallExpr &C) {
198187 // Use getCalleeDecl instead of getMethodDecl in order to handle
199188 // pointer-to-member calls.
@@ -212,8 +201,8 @@ static MemberExpr *getMemberForAccessor(const CXXMemberCallExpr &C) {
212201class ReferencedDeclsVisitor : public AnalysisASTVisitor {
213202public:
214203 ReferencedDeclsVisitor (ReferencedDecls &Referenced,
215- const FunctionDecl *PrimaryFunction )
216- : Referenced(Referenced), PrimaryFunction(PrimaryFunction ) {}
204+ const FunctionDecl *AnalyzedFunction )
205+ : Referenced(Referenced), AnalyzedFunction(AnalyzedFunction ) {}
217206
218207 void traverseConstructorInits (const CXXConstructorDecl *Ctor) {
219208 for (const CXXCtorInitializer *Init : Ctor->inits ()) {
@@ -247,8 +236,17 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
247236 insertIfGlobal (*E->getDecl (), Referenced.Globals );
248237 insertIfLocal (*E->getDecl (), Referenced.Locals );
249238 insertIfFunction (*E->getDecl (), Referenced.Functions );
250- insertIfParamOfNotThePrimaryFunction (
251- *E->getDecl (), Referenced.LambdaCapturedParams , PrimaryFunction);
239+
240+ // Collect referenced parameters of functions other than the function being
241+ // analyzed, or of any function if we are analyzing a standalone statement.
242+ // See comments on `LambdaCapturedParams` for motivations.
243+ if (auto *P = dyn_cast<ParmVarDecl>(E->getDecl ())) {
244+ if (!AnalyzedFunction ||
245+ P->getParentFunctionOrMethod () != AnalyzedFunction) {
246+ Referenced.LambdaCapturedParams .insert (P);
247+ }
248+ }
249+
252250 return true ;
253251 }
254252
@@ -286,7 +284,7 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
286284private:
287285 ReferencedDecls &Referenced;
288286 // May be null, if we are visiting a statement that is not a function body.
289- const FunctionDecl *const PrimaryFunction ;
287+ const FunctionDecl *const AnalyzedFunction ;
290288};
291289
292290ReferencedDecls getReferencedDecls (const FunctionDecl &FD) {
0 commit comments