[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:09:38 PDT 2024
https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/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().
>From fb5f36ee15bbeaf0d6d181dcf51c2847fc8babc8 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Sun, 30 Jun 2024 09:05:12 -0700
Subject: [PATCH] [Serialization] Clear moved-from deque to ensure valid state
post-move
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().
---
clang/lib/Serialization/ASTReaderDecl.cpp | 1 +
1 file changed, 1 insertion(+)
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();
More information about the cfe-commits
mailing list