[clang-tools-extra] 8a1eba4 - [clangd] Fix use-after-free issues in TidyProvider.cpp (#114808)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 03:01:08 PST 2024
Author: Haojian Wu
Date: 2024-11-05T12:01:04+01:00
New Revision: 8a1eba48edc8a9668123a6b925c6dbb7f45a363a
URL: https://github.com/llvm/llvm-project/commit/8a1eba48edc8a9668123a6b925c6dbb7f45a363a
DIFF: https://github.com/llvm/llvm-project/commit/8a1eba48edc8a9668123a6b925c6dbb7f45a363a.diff
LOG: [clangd] Fix use-after-free issues in TidyProvider.cpp (#114808)
Added:
Modified:
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/clangd/TidyProvider.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp
index a87238e0c0938c..2ac123246a4cb8 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -46,7 +46,7 @@ class DotClangTidyCache : private FileCache {
[this](std::optional<llvm::StringRef> Data) {
Value.reset();
if (Data && !Data->empty()) {
- tidy::DiagCallback Diagnostics = [](const llvm::SMDiagnostic &D) {
+ auto Diagnostics = [](const llvm::SMDiagnostic &D) {
switch (D.getKind()) {
case llvm::SourceMgr::DK_Error:
elog("tidy-config error at {0}:{1}:{2}: {3}", D.getFilename(),
@@ -149,7 +149,7 @@ static void mergeCheckList(std::optional<std::string> &Checks,
*Checks = llvm::join_items(",", *Checks, List);
}
-TidyProviderRef provideEnvironment() {
+TidyProvider provideEnvironment() {
static const std::optional<std::string> User = [] {
std::optional<std::string> Ret = llvm::sys::Process::GetEnv("USER");
#ifdef _WIN32
@@ -167,7 +167,7 @@ TidyProviderRef provideEnvironment() {
return [](tidy::ClangTidyOptions &, llvm::StringRef) {};
}
-TidyProviderRef provideDefaultChecks() {
+TidyProvider provideDefaultChecks() {
// These default checks are chosen for:
// - low false-positive rate
// - providing a lot of value
@@ -251,7 +251,7 @@ TidyProvider disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks) {
};
}
-TidyProviderRef provideClangdConfig() {
+TidyProvider provideClangdConfig() {
return [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
const auto &CurTidyConfig = Config::current().Diagnostics.ClangTidy;
if (!CurTidyConfig.Checks.empty())
diff --git a/clang-tools-extra/clangd/TidyProvider.h b/clang-tools-extra/clangd/TidyProvider.h
index 7d849d340f3aa4..8424f5e62d448e 100644
--- a/clang-tools-extra/clangd/TidyProvider.h
+++ b/clang-tools-extra/clangd/TidyProvider.h
@@ -30,11 +30,11 @@ using TidyProviderRef = llvm::function_ref<void(tidy::ClangTidyOptions &,
TidyProvider combine(std::vector<TidyProvider> Providers);
/// Provider that just sets the defaults.
-TidyProviderRef provideEnvironment();
+TidyProvider provideEnvironment();
/// Provider that will enable a nice set of default checks if none are
/// specified.
-TidyProviderRef provideDefaultChecks();
+TidyProvider provideDefaultChecks();
/// Provider the enables a specific set of checks and warnings as errors.
TidyProvider addTidyChecks(llvm::StringRef Checks,
@@ -51,7 +51,7 @@ disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks = {});
TidyProvider provideClangTidyFiles(ThreadsafeFS &);
// Provider that uses clangd configuration files.
-TidyProviderRef provideClangdConfig();
+TidyProvider provideClangdConfig();
tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider,
llvm::StringRef Filename);
More information about the cfe-commits
mailing list