[PATCH] D138329: [-Wunsafe-buffer-usage] Add a new recursive matcher to replace `forEachDescendant` in unsafe buffer check

Ziqing Luo via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 18 17:12:06 PST 2022


ziqingluo-90 added a comment.

In D138329#3938351 <https://reviews.llvm.org/D138329#3938351>, @xazax.hun wrote:

> Is the problem `forEachDescendant` matching statements inside blocks and lambdas? I wonder if this behavior would surprise people, so I think it would be better to:
>
> - Potentially add a template bool parameter to `forEachDescendant` controlling this behavior.
> - Review existing uses because I am not entirely sure if the current behavior is the right default.

Let me try to describe the problem in more detail.   The goal is to recursively visit every descendant of a node `n` but skip all nested callable declarations in `n`.  With `forEachDescendant`, one needs to explicitly test and skip, using `forCallable`,  if a descendant does not belong to the same "callable" as `n`.  `forCallable` looks for ancestors of a node through the AST so it requires the AST to be complete.  But in our case, the AST is under construction.   Given a node, we want the visitor only strictly look at descendants of the node.

For the questions,  I think blocks and lambdas are the only cases we will have in analyzing "C/C++" + "blocks" programs.   Our plan is to generalize this matcher to be an optional mode of `forEachDescendant` once it becomes stable.  So this implementation also skips other declarations.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138329/new/

https://reviews.llvm.org/D138329



More information about the cfe-commits mailing list