https://github.com/zahiraam updated https://github.com/llvm/llvm-project/pull/118655
>From 3b93252fa52c4055e8c294784056697e92299b9b Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Wed, 4 Dec 2024 07:24:20 -0800 Subject: [PATCH 1/3] [NFC] Complete proper copying and resource cleanup in classes. --- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h | 3 +++ clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h | 2 ++ clang-tools-extra/clangd/ClangdLSPServer.h | 3 +++ clang-tools-extra/clangd/ParsedAST.h | 3 +++ clang-tools-extra/clangd/TUScheduler.cpp | 5 ++++- clang-tools-extra/clangd/TUScheduler.h | 3 +++ clang-tools-extra/clangd/support/DirectiveTree.cpp | 3 +++ clang-tools-extra/modularize/ModuleAssistant.cpp | 2 ++ 8 files changed, 23 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h index 97e16a12febd04..d9efe42735f2fc 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -81,6 +81,9 @@ class ClangTidyContext { ~ClangTidyContext(); + ClangTidyContext(const ClangTidyContext &) = default; + ClangTidyContext &operator=(const ClangTidyContext &) = default; + /// Report any errors detected using this method. /// /// This is still under heavy development and will likely change towards using diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h index e862195abaabbe..1e7485224de116 100644 --- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h +++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h @@ -31,6 +31,8 @@ class NoLintDirectiveHandler { public: NoLintDirectiveHandler(); ~NoLintDirectiveHandler(); + NoLintDirectiveHandler(const NoLintDirectiveHandler &) = default; + NoLintDirectiveHandler &operator=(const NoLintDirectiveHandler &) = default; bool shouldSuppress(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Diag, llvm::StringRef DiagName, diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 0b8e4720f53236..8b2f4a5f0d8aa8 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -73,6 +73,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks, /// The destructor blocks on any outstanding background tasks. ~ClangdLSPServer(); + ClangdLSPServer(const ClangdLSPServer& other) = default; + ClangdLSPServer &operator=(const ClangdLSPServer &other) = default; + /// Run LSP server loop, communicating with the Transport provided in the /// constructor. This method must not be executed more than once. /// diff --git a/clang-tools-extra/clangd/ParsedAST.h b/clang-tools-extra/clangd/ParsedAST.h index 63e564bd68a78c..b28cf927e4c0c6 100644 --- a/clang-tools-extra/clangd/ParsedAST.h +++ b/clang-tools-extra/clangd/ParsedAST.h @@ -59,6 +59,9 @@ class ParsedAST { ~ParsedAST(); + ParsedAST(const ParsedAST &Other) = default; + ParsedAST &operator=(const ParsedAST &Other) = default; + /// Note that the returned ast will not contain decls from the preamble that /// were not deserialized during parsing. Clients should expect only decls /// from the main file to be in the AST. diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index 71548b59cc3088..791625b17d42dd 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -411,6 +411,8 @@ class PreambleThrottlerRequest { if (Throttler) Throttler->release(ID); } + PreambleThrottlerRequest(const PreambleThrottlerRequest &) = default; + PreambleThrottlerRequest &operator=(const PreambleThrottlerRequest &) = default; private: PreambleThrottler::RequestID ID; @@ -621,7 +623,8 @@ class ASTWorker { AsyncTaskRunner *Tasks, Semaphore &Barrier, const TUScheduler::Options &Opts, ParsingCallbacks &Callbacks); ~ASTWorker(); - + ASTWorker(const ASTWorker &other) = default; + ASTWorker &operator=(const ASTWorker &other) = default; void update(ParseInputs Inputs, WantDiagnostics, bool ContentChanged); void runWithAST(llvm::StringRef Name, diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h index fb936d46bbcf7e..4b8f3c000307ad 100644 --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -242,6 +242,9 @@ class TUScheduler { std::unique_ptr<ParsingCallbacks> ASTCallbacks = nullptr); ~TUScheduler(); + TUScheduler(const TUScheduler &other) = default; + TUScheduler& operator=(const TUScheduler& other) = default; + struct FileStats { std::size_t UsedBytesAST = 0; std::size_t UsedBytesPreamble = 0; diff --git a/clang-tools-extra/clangd/support/DirectiveTree.cpp b/clang-tools-extra/clangd/support/DirectiveTree.cpp index d25da111681afc..f7b9113c92b7b4 100644 --- a/clang-tools-extra/clangd/support/DirectiveTree.cpp +++ b/clang-tools-extra/clangd/support/DirectiveTree.cpp @@ -328,6 +328,9 @@ class Preprocessor { Preprocessor(const TokenStream &In, TokenStream &Out) : In(In), Out(Out) {} ~Preprocessor() { Out.finalize(); } + Preprocessor(const Preprocessor&) = default; // Default copy constructor + Preprocessor& operator=(const Preprocessor&) = default; // Default copy assignment operator + void walk(const DirectiveTree &T) { for (const auto &C : T.Chunks) std::visit(*this, C); diff --git a/clang-tools-extra/modularize/ModuleAssistant.cpp b/clang-tools-extra/modularize/ModuleAssistant.cpp index 5c11ffdb8589d5..b6bb1d5146e560 100644 --- a/clang-tools-extra/modularize/ModuleAssistant.cpp +++ b/clang-tools-extra/modularize/ModuleAssistant.cpp @@ -46,6 +46,8 @@ class Module { public: Module(llvm::StringRef Name, bool Problem); ~Module(); + Module(const Module &other) = default; + Module &operator=(const Module &other) = default; bool output(llvm::raw_fd_ostream &OS, int Indent); Module *findSubModule(llvm::StringRef SubName); >From 8793d4cb4671fa984c43eaba8f5c0e122dcaac2f Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Wed, 4 Dec 2024 07:55:46 -0800 Subject: [PATCH 2/3] Fix format. --- clang-tools-extra/clangd/ClangdLSPServer.h | 2 +- clang-tools-extra/clangd/TUScheduler.cpp | 3 ++- clang-tools-extra/clangd/TUScheduler.h | 2 +- clang-tools-extra/clangd/support/DirectiveTree.cpp | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 8b2f4a5f0d8aa8..607478aa821c87 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -73,7 +73,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks, /// The destructor blocks on any outstanding background tasks. ~ClangdLSPServer(); - ClangdLSPServer(const ClangdLSPServer& other) = default; + ClangdLSPServer(const ClangdLSPServer &other) = default; ClangdLSPServer &operator=(const ClangdLSPServer &other) = default; /// Run LSP server loop, communicating with the Transport provided in the diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index 791625b17d42dd..651e03eced7fb9 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -412,7 +412,8 @@ class PreambleThrottlerRequest { Throttler->release(ID); } PreambleThrottlerRequest(const PreambleThrottlerRequest &) = default; - PreambleThrottlerRequest &operator=(const PreambleThrottlerRequest &) = default; + PreambleThrottlerRequest & + operator=(const PreambleThrottlerRequest &) = default; private: PreambleThrottler::RequestID ID; diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h index 4b8f3c000307ad..70848d2e053413 100644 --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -243,7 +243,7 @@ class TUScheduler { ~TUScheduler(); TUScheduler(const TUScheduler &other) = default; - TUScheduler& operator=(const TUScheduler& other) = default; + TUScheduler &operator=(const TUScheduler &other) = default; struct FileStats { std::size_t UsedBytesAST = 0; diff --git a/clang-tools-extra/clangd/support/DirectiveTree.cpp b/clang-tools-extra/clangd/support/DirectiveTree.cpp index f7b9113c92b7b4..268dde45196493 100644 --- a/clang-tools-extra/clangd/support/DirectiveTree.cpp +++ b/clang-tools-extra/clangd/support/DirectiveTree.cpp @@ -328,8 +328,8 @@ class Preprocessor { Preprocessor(const TokenStream &In, TokenStream &Out) : In(In), Out(Out) {} ~Preprocessor() { Out.finalize(); } - Preprocessor(const Preprocessor&) = default; // Default copy constructor - Preprocessor& operator=(const Preprocessor&) = default; // Default copy assignment operator + Preprocessor(const Preprocessor &other) = default; + Preprocessor &operator=(const Preprocessor &other) = default; void walk(const DirectiveTree &T) { for (const auto &C : T.Chunks) >From 59c5c9517a6ec8cbea066e8023372f89ea8b1d18 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Thu, 5 Dec 2024 05:57:16 -0800 Subject: [PATCH 3/3] Addressed review comments. --- .../clang-tidy/ClangTidyDiagnosticConsumer.h | 4 ++-- clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h | 4 ++-- clang-tools-extra/clangd/ClangdLSPServer.h | 4 ++-- clang-tools-extra/clangd/ParsedAST.h | 4 ++-- clang-tools-extra/clangd/TUScheduler.cpp | 8 ++++---- clang-tools-extra/clangd/TUScheduler.h | 4 ++-- clang-tools-extra/clangd/support/DirectiveTree.cpp | 4 ++-- clang-tools-extra/modularize/ModuleAssistant.cpp | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h index d9efe42735f2fc..ff42f96a0477b4 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h @@ -81,8 +81,8 @@ class ClangTidyContext { ~ClangTidyContext(); - ClangTidyContext(const ClangTidyContext &) = default; - ClangTidyContext &operator=(const ClangTidyContext &) = default; + ClangTidyContext(const ClangTidyContext &) = delete; + ClangTidyContext &operator=(const ClangTidyContext &) = delete; /// Report any errors detected using this method. /// diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h index 1e7485224de116..f66285672d04aa 100644 --- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h +++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.h @@ -31,8 +31,8 @@ class NoLintDirectiveHandler { public: NoLintDirectiveHandler(); ~NoLintDirectiveHandler(); - NoLintDirectiveHandler(const NoLintDirectiveHandler &) = default; - NoLintDirectiveHandler &operator=(const NoLintDirectiveHandler &) = default; + NoLintDirectiveHandler(const NoLintDirectiveHandler &) = delete; + NoLintDirectiveHandler &operator=(const NoLintDirectiveHandler &) = delete; bool shouldSuppress(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Diag, llvm::StringRef DiagName, diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h index 607478aa821c87..dbfff2aef57f1d 100644 --- a/clang-tools-extra/clangd/ClangdLSPServer.h +++ b/clang-tools-extra/clangd/ClangdLSPServer.h @@ -73,8 +73,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks, /// The destructor blocks on any outstanding background tasks. ~ClangdLSPServer(); - ClangdLSPServer(const ClangdLSPServer &other) = default; - ClangdLSPServer &operator=(const ClangdLSPServer &other) = default; + ClangdLSPServer(const ClangdLSPServer &other) = delete; + ClangdLSPServer &operator=(const ClangdLSPServer &other) = delete; /// Run LSP server loop, communicating with the Transport provided in the /// constructor. This method must not be executed more than once. diff --git a/clang-tools-extra/clangd/ParsedAST.h b/clang-tools-extra/clangd/ParsedAST.h index b28cf927e4c0c6..8d9d1e64569267 100644 --- a/clang-tools-extra/clangd/ParsedAST.h +++ b/clang-tools-extra/clangd/ParsedAST.h @@ -59,8 +59,8 @@ class ParsedAST { ~ParsedAST(); - ParsedAST(const ParsedAST &Other) = default; - ParsedAST &operator=(const ParsedAST &Other) = default; + ParsedAST(const ParsedAST &Other) = delete; + ParsedAST &operator=(const ParsedAST &Other) = delete; /// Note that the returned ast will not contain decls from the preamble that /// were not deserialized during parsing. Clients should expect only decls diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index 651e03eced7fb9..035e5e63d8fbb3 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -411,9 +411,9 @@ class PreambleThrottlerRequest { if (Throttler) Throttler->release(ID); } - PreambleThrottlerRequest(const PreambleThrottlerRequest &) = default; + PreambleThrottlerRequest(const PreambleThrottlerRequest &) = delete; PreambleThrottlerRequest & - operator=(const PreambleThrottlerRequest &) = default; + operator=(const PreambleThrottlerRequest &) = delete; private: PreambleThrottler::RequestID ID; @@ -624,8 +624,8 @@ class ASTWorker { AsyncTaskRunner *Tasks, Semaphore &Barrier, const TUScheduler::Options &Opts, ParsingCallbacks &Callbacks); ~ASTWorker(); - ASTWorker(const ASTWorker &other) = default; - ASTWorker &operator=(const ASTWorker &other) = default; + ASTWorker(const ASTWorker &other) = delete; + ASTWorker &operator=(const ASTWorker &other) = delete; void update(ParseInputs Inputs, WantDiagnostics, bool ContentChanged); void runWithAST(llvm::StringRef Name, diff --git a/clang-tools-extra/clangd/TUScheduler.h b/clang-tools-extra/clangd/TUScheduler.h index 70848d2e053413..d0da20310a8b23 100644 --- a/clang-tools-extra/clangd/TUScheduler.h +++ b/clang-tools-extra/clangd/TUScheduler.h @@ -242,8 +242,8 @@ class TUScheduler { std::unique_ptr<ParsingCallbacks> ASTCallbacks = nullptr); ~TUScheduler(); - TUScheduler(const TUScheduler &other) = default; - TUScheduler &operator=(const TUScheduler &other) = default; + TUScheduler(const TUScheduler &other) = delete; + TUScheduler &operator=(const TUScheduler &other) = delete; struct FileStats { std::size_t UsedBytesAST = 0; diff --git a/clang-tools-extra/clangd/support/DirectiveTree.cpp b/clang-tools-extra/clangd/support/DirectiveTree.cpp index 268dde45196493..7ea08add7a107e 100644 --- a/clang-tools-extra/clangd/support/DirectiveTree.cpp +++ b/clang-tools-extra/clangd/support/DirectiveTree.cpp @@ -328,8 +328,8 @@ class Preprocessor { Preprocessor(const TokenStream &In, TokenStream &Out) : In(In), Out(Out) {} ~Preprocessor() { Out.finalize(); } - Preprocessor(const Preprocessor &other) = default; - Preprocessor &operator=(const Preprocessor &other) = default; + Preprocessor(const Preprocessor &other) = delete; + Preprocessor &operator=(const Preprocessor &other) = delete; void walk(const DirectiveTree &T) { for (const auto &C : T.Chunks) diff --git a/clang-tools-extra/modularize/ModuleAssistant.cpp b/clang-tools-extra/modularize/ModuleAssistant.cpp index b6bb1d5146e560..c7259d70bd58f8 100644 --- a/clang-tools-extra/modularize/ModuleAssistant.cpp +++ b/clang-tools-extra/modularize/ModuleAssistant.cpp @@ -46,8 +46,8 @@ class Module { public: Module(llvm::StringRef Name, bool Problem); ~Module(); - Module(const Module &other) = default; - Module &operator=(const Module &other) = default; + Module(const Module &other) = delete; + Module &operator=(const Module &other) = delete; bool output(llvm::raw_fd_ostream &OS, int Indent); Module *findSubModule(llvm::StringRef SubName); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits