[cfe-dev] ParentMap: add support for BlockExpr

Xavier Chantry via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 21 05:27:22 PST 2016


On 18/01/2016 18:53, Xavier Chantry via cfe-dev wrote:
> We wanted to write the following check in clang-tidy: find all alloca
> calls inside a loop, but not those captured by a block.
>
> Finding all alloca calls inside a loop is very easy with the matcher,
> but to exclude those in a block, we wanted to walk the AST from the
> alloca call to the loop in the checker.
>
> One way to achieve that was to patch ParentMap, because it didn't go
> inside blocks. See the attached patch.
>
> Is that approach correct or does anyone have a better suggestion ?
>

An alternative without patching clang is to check whether the matched 
statement has a parent. If not, it is probably in a block. This supposes 
ParentMap will never be patched to support BlockExpr.



More information about the cfe-dev mailing list