This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Aliasing: Add more support for lambda captures.
ClosedPublic

Authored by NoQ on May 3 2021, 2:42 PM.

Details

Summary

D96215 takes care of the situation where the variable is captured into a nearby lambda. This patch takes care of the situation where the current function is the lambda and the variable is one of its captures from an enclosing scope.

The analogous problem for ^{blocks} is already handled automagically by the previous patch. That said, I added two FIXME tests that demonstrate an unrelated (but fairly disturbing) problem: because BlockDecl isn't a FunctionDecl, the forFunction() matcher doesn't behave as expected. This time it manifests through alias analysis analyzing more code than necessary but there are other annoying effects of this bug that I'll get to later.

Diff Detail

Event Timeline

NoQ created this revision.May 3 2021, 2:42 PM
NoQ requested review of this revision.May 3 2021, 2:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 3 2021, 2:42 PM
Eugene.Zelenko added inline comments.
clang-tools-extra/clang-tidy/utils/Aliasing.cpp
76

const auto* could be used because type is spelled in same statement.

NoQ marked an inline comment as done.May 3 2021, 3:37 PM
aaron.ballman added inline comments.May 5 2021, 8:17 AM
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
1

You need to add -fblocks here to enable block support to run the test.

NoQ added inline comments.May 5 2021, 6:35 PM
clang-tools-extra/test/clang-tidy/checkers/bugprone-redundant-branch-condition.cpp
1

I added them in D96215 but didn't rebase this patch on top of that patch.

NoQ updated this revision to Diff 343264.EditedMay 5 2021, 6:36 PM

Rebase to address the comment! (and satisfy pre-merge checks)

This revision is now accepted and ready to land.May 6 2021, 4:27 AM
This revision was automatically updated to reflect the committed changes.