[AST] Initialize local counter
authorVitaly Buka <vitalybuka@google.com>
Fri, 12 May 2023 22:20:58 +0000 (15:20 -0700)
committerVitaly Buka <vitalybuka@google.com>
Thu, 18 May 2023 08:19:11 +0000 (01:19 -0700)
I assume it's optional and ReadAST does not have to set the
counter on success.

Without the patch msan complains that we pass
uninitialized value into noundef parameters of setCounterValue.

Reviewed By: bnbarham, barannikov88

Differential Revision: https://reviews.llvm.org/D150492

clang/lib/Frontend/ASTUnit.cpp

index b1e7db1..14971da 100644 (file)
@@ -822,7 +822,6 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
   // Gather Info for preprocessor construction later on.
 
   HeaderSearch &HeaderInfo = *AST->HeaderInfo;
-  unsigned Counter;
 
   AST->PP = std::make_shared<Preprocessor>(
       AST->PPOpts, AST->getDiagnostics(), *AST->LangOpts,
@@ -846,6 +845,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
       /*isysroot=*/"",
       /*DisableValidationKind=*/disableValid, AllowASTWithCompilerErrors);
 
+  unsigned Counter = 0;
   AST->Reader->setListener(std::make_unique<ASTInfoCollector>(
       *AST->PP, AST->Ctx.get(), *AST->HSOpts, *AST->PPOpts, *AST->LangOpts,
       AST->TargetOpts, AST->Target, Counter));