Skip to content

[Serialization] Clear moved-from deque to ensure valid state post-move #97221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

smanna12
Copy link
Contributor

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().

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().
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules labels Jun 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 30, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-modules

Author: None (smanna12)

Changes

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 --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();

Copy link
Member

@ChuanqiXu9 ChuanqiXu9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smanna12
Copy link
Contributor Author

smanna12 commented Jul 1, 2024

Thank you @ChuanqiXu9 for reviews!

@smanna12 smanna12 merged commit 035e76f into llvm:main Jul 1, 2024
10 checks passed
@smanna12 smanna12 deleted the FixMoveBug branch July 1, 2024 12:52
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
llvm#97221)

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().
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
llvm#97221)

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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants