[clang] 035e76f - [Serialization] Clear moved-from deque to ensure valid state post-move (#97221)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 05:51:00 PDT 2024


Author: smanna12
Date: 2024-07-01T07:50:57-05:00
New Revision: 035e76ff3706ee3e677fbae67cf47a343cf6eceb

URL: https://github.com/llvm/llvm-project/commit/035e76ff3706ee3e677fbae67cf47a343cf6eceb
DIFF: https://github.com/llvm/llvm-project/commit/035e76ff3706ee3e677fbae67cf47a343cf6eceb.diff

LOG: [Serialization] Clear moved-from deque to ensure valid state post-move (#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().

Added: 
    

Modified: 
    clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 
    


################################################################################
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