[clang] [Serialization] Clear moved-from deque to ensure valid state post-move (PR #97221)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 30 09:10:07 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules
Author: None (smanna12)
<details>
<summary>Changes</summary>
This patch addresses a use-after-move issue, reported by static analyzer tool, by clearing the `PotentiallyInterestingDecls` deque after it has been moved to `MaybeInterestingDecls`.
The fix ensures that the subsequent assert statement correctly checks for an empty state, preventing any undefined behavior in ASTReader::PassInterestingDeclsToConsumer().
---
Full diff: https://github.com/llvm/llvm-project/pull/97221.diff
1 Files Affected:
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1)
``````````diff
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index 6afb18f932e72..cf3737c5a501d 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4215,6 +4215,7 @@ void ASTReader::PassInterestingDeclsToConsumer() {
};
std::deque<Decl *> MaybeInterestingDecls =
std::move(PotentiallyInterestingDecls);
+ PotentiallyInterestingDecls.clear();
assert(PotentiallyInterestingDecls.empty());
while (!MaybeInterestingDecls.empty()) {
Decl *D = MaybeInterestingDecls.front();
``````````
</details>
https://github.com/llvm/llvm-project/pull/97221
More information about the cfe-commits
mailing list