File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
include/clang/Analysis/FlowSensitive
lib/Analysis/FlowSensitive Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -146,9 +146,9 @@ struct ReferencedDecls {
146146 // / Free functions and member functions which are referenced (but not
147147 // / necessarily called).
148148 llvm::DenseSet<const FunctionDecl *> Functions;
149- // / Parameters of other functions, captured by reference by a lambda. This is
150- // / empty except when ReferencedDecls are computed for a lambda's call
151- // / operator .
149+ // / When analyzing a lambda's call operator, the set of all parameters (from
150+ // / the surrounding function) that the lambda captures. Captured local
151+ // / variables are already included in `Locals` above .
152152 llvm::DenseSet<const ParmVarDecl *> LambdaCapturedParams;
153153};
154154
Original file line number Diff line number Diff line change @@ -282,6 +282,17 @@ ReferencedDecls getReferencedDecls(const FunctionDecl &FD) {
282282 Visitor.TraverseStmt (FD.getBody ());
283283 if (const auto *CtorDecl = dyn_cast<CXXConstructorDecl>(&FD))
284284 Visitor.traverseConstructorInits (CtorDecl);
285+
286+ // If analyzing a lambda call operator, collect all captures of parameters (of
287+ // the surrounding function). This collects them even if they are not
288+ // referenced in the body of the lambda call operator. Non-parameter local
289+ // variables that are captured are already collected into
290+ // `ReferencedDecls.Locals` when traversing the call operator body, but we
291+ // collect parameters here to avoid needing to check at each referencing node
292+ // whether the parameter is a lambda capture from a surrounding function or is
293+ // a parameter of the current function. If it becomes necessary to limit this
294+ // set to the parameters actually referenced in the body, alternative
295+ // optimizations can be implemented to minimize duplicative work.
285296 if (const auto *Method = dyn_cast<CXXMethodDecl>(&FD);
286297 Method && isLambdaCallOperator (Method)) {
287298 for (const auto &Capture : Method->getParent ()->captures ()) {
You can’t perform that action at this time.
0 commit comments