[clang-tools-extra] Covrt issue (PR #117769)
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 26 11:13:46 PST 2024
https://github.com/zahiraam created https://github.com/llvm/llvm-project/pull/117769
None
>From 27925c327d9f3164e3ba966ffaed5715681480fd Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Thu, 21 Nov 2024 07:03:46 -0800
Subject: [PATCH 1/3] [NFC] Fix uninitialized pointer field.
---
clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 9161c0e702a28c..6d87a2fba27dcf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -23,7 +23,7 @@ AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
} // namespace
UseStdPrintCheck::UseStdPrintCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context),
+ : ClangTidyCheck(Name, Context), PP(PP),
StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
PrintfLikeFunctions(utils::options::parseStringList(
Options.get("PrintfLikeFunctions", ""))),
>From 6683cdef8060a68fe837b7d2a07cfbd146610698 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Thu, 21 Nov 2024 07:43:19 -0800
Subject: [PATCH 2/3] Addressed review comments.
---
clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
index 6d87a2fba27dcf..4f240982250741 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
@@ -23,7 +23,7 @@ AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
} // namespace
UseStdPrintCheck::UseStdPrintCheck(StringRef Name, ClangTidyContext *Context)
- : ClangTidyCheck(Name, Context), PP(PP),
+ : ClangTidyCheck(Name, Context), PP(nullptr),
StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
PrintfLikeFunctions(utils::options::parseStringList(
Options.get("PrintfLikeFunctions", ""))),
@@ -131,6 +131,7 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) {
utils::FormatStringConverter::Configuration ConverterConfig;
ConverterConfig.StrictMode = StrictMode;
ConverterConfig.AllowTrailingNewlineRemoval = true;
+ assert(PP && "Preprocessor should be set by registerPPCallbacks");
utils::FormatStringConverter Converter(
Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts(),
*Result.SourceManager, *PP);
>From 3daf0ab3dbecc5c598031ed815a2f6ea3e0ab4fe Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Tue, 26 Nov 2024 11:09:30 -0800
Subject: [PATCH 3/3] Fix potential data race condition.
---
clang-tools-extra/clangd/TUScheduler.cpp | 4 ++++
clang-tools-extra/clangd/index/BackgroundRebuild.cpp | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp
index 71548b59cc3088..7a05a3d4613708 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -501,6 +501,8 @@ class PreambleThread {
}
{
+ // Add a lock guard to protect the critical section.
+ std::lock_guard<std::mutex> Lock(Mutex);
WithContext Guard(std::move(CurrentReq->Ctx));
// Note that we don't make use of the ContextProvider here.
// Preamble tasks are always scheduled by ASTWorker tasks, and we
@@ -1329,6 +1331,8 @@ void ASTWorker::startTask(llvm::StringRef Name,
std::optional<UpdateType> Update,
TUScheduler::ASTActionInvalidation Invalidation) {
if (RunSync) {
+ // Add a lock guard to protect the critical section.
+ std::lock_guard<std::mutex> Lock(Mutex);
assert(!Done && "running a task after stop()");
runTask(Name, Task);
return;
diff --git a/clang-tools-extra/clangd/index/BackgroundRebuild.cpp b/clang-tools-extra/clangd/index/BackgroundRebuild.cpp
index 79383be012f836..b8677a32741b2f 100644
--- a/clang-tools-extra/clangd/index/BackgroundRebuild.cpp
+++ b/clang-tools-extra/clangd/index/BackgroundRebuild.cpp
@@ -34,6 +34,8 @@ bool BackgroundIndexRebuilder::enoughTUsToRebuild() const {
void BackgroundIndexRebuilder::indexedTU() {
maybeRebuild("after indexing enough files", [this] {
+ // Add a lock guard to protect the critical section
+ std::lock_guard<std::mutex> Lock(Mu);
++IndexedTUs;
if (Loading)
return false; // rebuild once loading finishes
@@ -64,6 +66,8 @@ void BackgroundIndexRebuilder::loadedShard(size_t ShardCount) {
}
void BackgroundIndexRebuilder::doneLoading() {
maybeRebuild("after loading index from disk", [this] {
+ // Add a lock guard to protect the critical section.
+ std::lock_guard<std::mutex> Lock(Mu);
assert(Loading);
--Loading;
if (Loading) // was loading multiple batches concurrently
More information about the cfe-commits
mailing list