Skip to content

Commit e38f44d

Browse files
committed
Expand and update comments.
1 parent cc7305a commit e38f44d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clang/include/clang/Analysis/FlowSensitive/ASTOps.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

clang/lib/Analysis/FlowSensitive/ASTOps.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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()) {

0 commit comments

Comments
 (0)