[all-commits] [llvm/llvm-project] 915372: [clang-tidy] In C++17, callee is guaranteed to be ...
Kefu Chai via All-commits
all-commits at lists.llvm.org
Mon Jul 8 09:44:43 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 915372a8db7a8d7a1af19cc9ec6ccb5a0d592d1f
https://github.com/llvm/llvm-project/commit/915372a8db7a8d7a1af19cc9ec6ccb5a0d592d1f
Author: Kefu Chai <tchaikov at gmail.com>
Date: 2024-07-08 (Mon, 08 Jul 2024)
Changed paths:
M clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
M clang-tools-extra/clang-tidy/utils/ExprSequence.cpp
M clang-tools-extra/docs/ReleaseNotes.rst
M clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
Log Message:
-----------
[clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (#93623)
This eliminates false positives in bugprone-use-after-move where a
variable
is used in the callee and moved from in the arguments.
We introduce one special case: If the callee is a MemberExpr with a
DeclRefExpr as its base, we consider it to be sequenced after the
arguments. This is because the variable referenced in the base will only
actually be accessed when the call happens, i.e. once all of the
arguments have been evaluated. This has no basis in the C++ standard,
but it reflects actual behavior that is relevant to a use-after-move
scenario:
```c++
a.bar(consumeA(std::move(a));
```
In this example, we end up accessing a after it has been moved from,
even though nominally the callee a.bar is evaluated before the argument
consumeA(std::move(a)).
Treating this scenario correctly has required rewriting the logic in
bugprone-use-after-move that governs whether the use happens in a later
loop iteration than the move. This was previously based on an unsound
heuristic (does the use come lexically before the move?); we now use a
more rigourous criterion based on reachability in the CFG.
Fixes #57758
Fixes #59612
Co-authored-by: martinboehme <mboehme at google.com>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list