[clang-tools-extra] [DRAFT][clang-tidy] modernize-replace-with-stdcopy (PR #113046)

2024-10-19 Thread Kuba Migdał via cfe-commits

https://github.com/kidq330 edited 
https://github.com/llvm/llvm-project/pull/113046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [DRAFT][clang-tidy] modernize-replace-with-stdcopy (PR #113046)

2024-10-19 Thread Kuba Migdał via cfe-commits

https://github.com/kidq330 created 
https://github.com/llvm/llvm-project/pull/113046

None

From b2753fc81792cf5c3a95eedbf349bac2e461e883 Mon Sep 17 00:00:00 2001
From: Giovanni Martins 
Date: Wed, 6 Dec 2023 11:26:53 -0300
Subject: [PATCH 1/3] replace memcpy with std::copy on clang-tidy

removed typo on files

sort imports

removed some typo

solve linter reports

update modernize-replace-memcpy-with-stdcopy.rst
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/ReplaceMemcpyWithStdCopy.cpp| 119 ++
 .../modernize/ReplaceMemcpyWithStdCopy.h  |  49 
 clang-tools-extra/docs/ReleaseNotes.rst   |   5 +
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../modernize-replace-memcpy-with-stdcopy.rst |  47 +++
 7 files changed, 225 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/modernize-replace-memcpy-with-stdcopy.rst

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index c919d49b42873a..83ebd2f12775e7 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -23,6 +23,7 @@ add_clang_library(clangTidyModernizeModule STATIC
   RedundantVoidArgCheck.cpp
   ReplaceAutoPtrCheck.cpp
   ReplaceDisallowCopyAndAssignMacroCheck.cpp
+  ReplaceMemcpyWithStdCopy.cpp
   ReplaceRandomShuffleCheck.cpp
   ReturnBracedInitListCheck.cpp
   ShrinkToFitCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 18607593320635..257c9373444761 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -24,6 +24,7 @@
 #include "RedundantVoidArgCheck.h"
 #include "ReplaceAutoPtrCheck.h"
 #include "ReplaceDisallowCopyAndAssignMacroCheck.h"
+#include "ReplaceMemcpyWithStdCopy.h"
 #include "ReplaceRandomShuffleCheck.h"
 #include "ReturnBracedInitListCheck.h"
 #include "ShrinkToFitCheck.h"
@@ -91,6 +92,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-replace-auto-ptr");
 CheckFactories.registerCheck(
 "modernize-replace-disallow-copy-and-assign-macro");
+CheckFactories.registerCheck(
+"modernize-replace-memcpy-by-stdcopy");
 CheckFactories.registerCheck(
 "modernize-replace-random-shuffle");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp
new file mode 100644
index 00..af6b365c162517
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyWithStdCopy.cpp
@@ -0,0 +1,119 @@
+//===--- ReplaceMemcpyWithStdCopy.cpp - clang-tidy*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReplaceMemcpyWithStdCopy.h"
+#include "../utils/OptionsUtils.h"
+#include 
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceMemcpyWithStdCopy::ReplaceMemcpyWithStdCopy(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM)) 
{
+}
+
+void ReplaceMemcpyWithStdCopy::registerMatchers(MatchFinder *Finder) {
+  assert(Finder != nullptr);
+
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto MemcpyMatcher =
+  callExpr(hasDeclaration(functionDecl(hasName("memcpy"),
+   isExpansionInSystemHeader())),
+   isExpansionInMainFile())
+  .bind("memcpy_function");
+
+  Finder->addMatcher(MemcpyMatcher, this);
+}
+
+void ReplaceMemcpyWithStdCopy::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Inserter =
+  std::make_unique(SM, getLangOpts(),
+   IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+}
+
+void ReplaceMemcpyWithStdCopy::check(const MatchFinder::MatchResult &Result) {
+  const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function");
+  assert(MemcpyNode !=

[clang-tools-extra] [clang-tidy][modernize] Replace memmove/memcpy with std::copy (PR #122940)

2025-01-15 Thread Kuba Migdał via cfe-commits

kidq330 wrote:

@kadircet Does the file need further changes from what I've already added?

https://github.com/llvm/llvm-project/pull/122940
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][modernize] Replace memmove/memcpy with std::copy (PR #122940)

2025-02-08 Thread Kuba Migdał via cfe-commits

kidq330 wrote:

@kadircet I ran the script but it seems that my check was one of the few that 
did not get updated (see last commit in PR), is this normal?
Here's the cmake command for the build I used:
```
cmake -G Ninja -S llvm -B static  -DBUILD_SHARED_LIBS=false 
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_BUILD_TYPE="Release" 
-DLLVM_USE_LINKER=mold -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_C_COMPILER="gcc" 
-DCMAKE_CXX_COMPILER="g++"
```

https://github.com/llvm/llvm-project/pull/122940
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [DRAFT][clang-tidy] modernize-replace-with-stdcopy (PR #113046)

2025-02-23 Thread Kuba Migdał via cfe-commits

https://github.com/kidq330 closed 
https://github.com/llvm/llvm-project/pull/113046
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits