[clang-tools-extra] [clang] [clang][NFC] Refactor `CXXNewExpr::InitializationStyle` (PR #71322)

2023-11-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

It catches 
(https://buildkite.com/llvm-project/github-pull-requests/builds/12931#018ba4b7-1e05-425f-a30d-46ac33f582b6),
 you just didn't wait for a results (or ignored them) and forced a merge.

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread Piotr Zegar via cfe-commits


@@ -871,8 +871,8 @@ bool IdentifierNamingCheck::matchesStyle(
   llvm::Regex("^[a-z][a-zA-Z0-9]*$"),
   llvm::Regex("^[A-Z][A-Z0-9_]*$"),
   llvm::Regex("^[A-Z][a-zA-Z0-9]*$"),
-  llvm::Regex("^[A-Z]([a-z0-9]*(_[A-Z])?)*"),
-  llvm::Regex("^[a-z]([a-z0-9]*(_[A-Z])?)*"),
+  llvm::Regex("^[A-Z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
+  llvm::Regex("^[a-z]+([a-z0-9]*_[A-Z0-9]+)*[a-z0-9]*$"),
   llvm::Regex("^[A-Z]([a-z0-9_]*[a-z])*$"),

PiotrZSL wrote:

Shouldn't this LeadingUpperSnakeCase also be changed ?

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Improve alternate snake case warnings (PR #71385)

2023-11-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Also update release notes, add one sentence there about this.

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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/71640

Enums without enumerators (empty) are now excluded from analysis as it's not 
possible to peroperly determinate new narrowed type, and such enums can be used 
in diffrent way, like as strong-types.

Closes #71544

>From eeacce5ffae9eca72484a7e51f9e55592fe4ca13 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:02:54 +
Subject: [PATCH] [clang-tidy] Improve performance-enum-size to exclude empty
 enums

Enums without enumerators (empty) are now excluded
from analysis as it's not possible to peroperly determinate
new narrowed type, and such enums can be used in diffrent
way, like as strong-types.
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp   | 5 +
 .../docs/clang-tidy/checks/performance/enum-size.rst | 2 ++
 .../test/clang-tidy/checkers/performance/enum-size.cpp   | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..b1df9d74cf661ee 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,10 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) {
+  return Node.enumerator_begin() != Node.enumerator_end();
+}
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +97,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

No release notes entry, as this check were added in this release.

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


[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

Update release notes, and update pull request description.
Except those two, looks fine for me.

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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/71640

>From eeacce5ffae9eca72484a7e51f9e55592fe4ca13 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:02:54 +
Subject: [PATCH 1/2] [clang-tidy] Improve performance-enum-size to exclude
 empty enums

Enums without enumerators (empty) are now excluded
from analysis as it's not possible to peroperly determinate
new narrowed type, and such enums can be used in diffrent
way, like as strong-types.
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp   | 5 +
 .../docs/clang-tidy/checks/performance/enum-size.rst | 2 ++
 .../test/clang-tidy/checkers/performance/enum-size.cpp   | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..b1df9d74cf661ee 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,10 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) {
+  return Node.enumerator_begin() != Node.enumerator_end();
+}
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +97,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

>From 5fca3fdf781dc849db770975b9f7017b091cd112 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 10:32:51 +0100
Subject: [PATCH 2/2] Update
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp

Use empty()

Co-authored-by: Congcong Cai 
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index b1df9d74cf661ee..182ed49426e5c29 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -24,7 +24,7 @@ namespace clang::tidy::performance {
 namespace {
 
 AST_MATCHER(EnumDecl, hasEnumerators) {
-  return Node.enumerator_begin() != Node.enumerator_end();
+  return !Node.enumerators().empty();
 }
 
 const std::uint64_t Min8 =

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/71640

>From f74559586a11455e2b4c1f2c63076c5c441c527b Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:02:54 +
Subject: [PATCH] [clang-tidy] Improve performance-enum-size to exclude empty
 enums

Enums without enumerators (empty) are now excluded
from analysis as it's not possible to peroperly determinate
new narrowed type, and such enums can be used in diffrent
way, like as strong-types.
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp | 3 +++
 .../docs/clang-tidy/checks/performance/enum-size.rst   | 2 ++
 .../test/clang-tidy/checkers/performance/enum-size.cpp | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..0f3e9d3ef75917b 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,8 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) { return !Node.enumerators().empty(); }
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +95,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Fix handling of functional cast in google-readability-casting (PR #71650)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/71650

Fix issue with constructor call being interpreted as functional cast and 
considered for a replacement
with static cast or being removed as redundant.

Closes #57959

>From b2da54fc89e99d3056ee80d47b8be2874916e02f Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:38:39 +
Subject: [PATCH 1/2] [clang-tidy] Fix handling of functional cast in
 google-readability-casting

Fix issue with constructor call being interpreted
as functional cast and considered for a replacement
with static cast or being removed as redundant.
---
 .../clang-tidy/google/AvoidCStyleCastsCheck.cpp | 13 -
 .../clang-tidy/google/AvoidCStyleCastsCheck.h   |  3 +++
 clang-tools-extra/docs/ReleaseNotes.rst |  4 
 .../checkers/google/readability-casting.cpp | 13 +++--
 4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 714ac0ee54dafb3..3afb93ac7f7dd15 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -18,19 +18,22 @@ namespace clang::tidy::google::readability {
 
 void AvoidCStyleCastsCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
+
   Finder->addMatcher(
   cStyleCastExpr(
   // Filter out (EnumType)IntegerLiteral construct, which is generated
   // for non-type template arguments of enum types.
   // FIXME: Remove this once this is fixed in the AST.
-  unless(hasParent(substNonTypeTemplateParmExpr())),
-  // Avoid matches in template instantiations.
-  unless(isInTemplateInstantiation()))
+  unless(hasParent(substNonTypeTemplateParmExpr(
   .bind("cast"),
   this);
+
   Finder->addMatcher(
-  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
-unless(hasDescendant(initListExpr(
+  cxxFunctionalCastExpr(
+  hasDestinationType(hasCanonicalType(anyOf(
+  builtinType(), references(qualType()), pointsTo(qualType(),
+  unless(
+  hasSourceExpression(anyOf(cxxConstructExpr(), initListExpr()
   .bind("cast"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
index 485640d230280ee..4267b896b6992c6 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
@@ -31,6 +31,9 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace clang::tidy::google::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..f02f4bba8916bb6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -290,6 +290,10 @@ Changes in existing checks
   to ignore unused parameters when they are marked as unused and parameters of
   deleted functions and constructors.
 
+- Improved :doc:`google-readability-casting
+  ` check to ignore constructor
+  calls disguised as functional casts.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
index e25463cf451b741..da49c3943d73222 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
@@ -322,17 +322,10 @@ void conversions() {
 }
 
 template 
-T functional_cast_template_used_by_class(float i) {
+T functional_cast_template(float i) {
   return T(i);
 }
 
-template 
-T functional_cast_template_used_by_int(float i) {
-  return T(i);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast
-  // CHECK-FIXES: return static_cast(i);
-}
-
 struct S2 {
   S2(float);
 };
@@ -356,8 +349,8 @@ void functional_casts() {
   auto s = S(str);
 
   // Functional casts in template functions
-  functional_cast_template_used_by_class(x);
-  functional_cast_template_used_by_int(x);
+  functional_cast_template(x);
+  functional_cast_template(x);
 
   // New expressions are not functional casts
   auto w = new int(x);

>From bdc890dad78c78703e52d82d5d

[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Add AllowImplicitlyDeletedCopyOrMove option to cppcoreguidelines-special-member-functions (PR #71683)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/71683

Improved cppcoreguidelines-special-member-functions check with a new option 
AllowImplicitlyDeletedCopyOrMove, which removes the requirement for explicit 
copy or move special member functions when they are already implicitly deleted.

Closes #62392 

>From 5c6db0ec4850bed27f94839d0f018d66fa1c57f4 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 13:31:28 +
Subject: [PATCH] [clang-tidy] Add AllowImplicitlyDeletedCopyOrMove option to
 cppcoreguidelines-special-member-functions

Improved cppcoreguidelines-special-member-functions check with a
new option AllowImplicitlyDeletedCopyOrMove, which removes the requirement
for explicit copy or move special member functions when they are already
implicitly deleted.
---
 .../SpecialMemberFunctionsCheck.cpp   | 70 ++-
 .../SpecialMemberFunctionsCheck.h |  7 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../special-member-functions.rst  | 28 ++--
 .../special-member-functions-relaxed.cpp  | 26 ++-
 5 files changed, 107 insertions(+), 30 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
index d2117c67a76d0b6..ed76ac665049d1c 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp
@@ -25,7 +25,9 @@ SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
  "AllowMissingMoveFunctions", false)),
   AllowSoleDefaultDtor(Options.get("AllowSoleDefaultDtor", false)),
   AllowMissingMoveFunctionsWhenCopyIsDeleted(
-  Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", false)) {}
+  Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", false)),
+  AllowImplicitlyDeletedCopyOrMove(
+  Options.get("AllowImplicitlyDeletedCopyOrMove", false)) {}
 
 void SpecialMemberFunctionsCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {
@@ -33,17 +35,34 @@ void SpecialMemberFunctionsCheck::storeOptions(
   Options.store(Opts, "AllowSoleDefaultDtor", AllowSoleDefaultDtor);
   Options.store(Opts, "AllowMissingMoveFunctionsWhenCopyIsDeleted",
 AllowMissingMoveFunctionsWhenCopyIsDeleted);
+  Options.store(Opts, "AllowImplicitlyDeletedCopyOrMove",
+AllowImplicitlyDeletedCopyOrMove);
+}
+
+std::optional
+SpecialMemberFunctionsCheck::getCheckTraversalKind() const {
+  return AllowImplicitlyDeletedCopyOrMove ? TK_AsIs
+  : TK_IgnoreUnlessSpelledInSource;
 }
 
 void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
+  auto IsNotImplicitOrDeleted = anyOf(unless(isImplicit()), isDeleted());
+
   Finder->addMatcher(
   cxxRecordDecl(
-  eachOf(has(cxxDestructorDecl().bind("dtor")),
- 
has(cxxConstructorDecl(isCopyConstructor()).bind("copy-ctor")),
- has(cxxMethodDecl(isCopyAssignmentOperator())
+  unless(isImplicit()),
+  eachOf(has(cxxDestructorDecl(unless(isImplicit())).bind("dtor")),
+ has(cxxConstructorDecl(isCopyConstructor(),
+IsNotImplicitOrDeleted)
+ .bind("copy-ctor")),
+ has(cxxMethodDecl(isCopyAssignmentOperator(),
+   IsNotImplicitOrDeleted)
  .bind("copy-assign")),
- 
has(cxxConstructorDecl(isMoveConstructor()).bind("move-ctor")),
- has(cxxMethodDecl(isMoveAssignmentOperator())
+ has(cxxConstructorDecl(isMoveConstructor(),
+IsNotImplicitOrDeleted)
+ .bind("move-ctor")),
+ has(cxxMethodDecl(isMoveAssignmentOperator(),
+   IsNotImplicitOrDeleted)
  .bind("move-assign"
   .bind("class-def"),
   this);
@@ -127,7 +146,8 @@ void SpecialMemberFunctionsCheck::check(
   for (const auto &KV : Matchers)
 if (const auto *MethodDecl =
 Result.Nodes.getNodeAs(KV.first)) {
-  StoreMember({KV.second, MethodDecl->isDeleted()});
+  StoreMember(
+  {KV.second, MethodDecl->isDeleted(), MethodDecl->isImplicit()});
 }
 }
 
@@ -144,7 +164,13 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
 
   auto HasMember = [&](SpecialMemberFunctionKind Kind) {
 return llvm::any_of(DefinedMembers, [Kind](const auto &Data) {
-  return Data.FunctionKind == Kind;
+  return Data.FunctionKind == Kind && !Data.IsImplicit;
+});
+  };
+
+  auto HasImplicitDeletedMember = [&](SpecialMemberFunctionKind Kind) {
+return llvm::any_of(DefinedMembers, 

[clang-tools-extra] [clang-tidy] Add AllowStringArrays option to modernize-avoid-c-arrays (PR #71701)

2023-11-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/71701

Add AllowStringArrays option, enabling the exclusion of array types with 
deduced sizes constructed from string literals. This includes only var 
declarations of array of characters constructed directly from c-strings.

Closes #59475

>From 8301beef04a70e54232cafdb24949e8f961b2aa7 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 16:52:06 +
Subject: [PATCH] [clang-tidy] Add AllowStringArrays option to
 modernize-avoid-c-arrays

Add AllowStringArrays option, enabling the exclusion of array types with deduced
sizes constructed from string literals. This includes only var declarations
of array of characters constructed directly from c-strings.
---
 .../modernize/AvoidCArraysCheck.cpp   | 21 +--
 .../clang-tidy/modernize/AvoidCArraysCheck.h  | 14 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +
 .../checks/modernize/avoid-c-arrays.rst   |  9 
 .../avoid-c-arrays-ignores-strings.cpp|  6 ++
 .../checkers/modernize/avoid-c-arrays.cpp |  3 +++
 6 files changed, 52 insertions(+), 6 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-ignores-strings.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
index d1b15479ffe7a93..ab1cdd62aa2cc01 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
@@ -12,6 +12,8 @@
 
 using namespace clang::ast_matchers;
 
+namespace clang::tidy::modernize {
+
 namespace {
 
 AST_MATCHER(clang::TypeLoc, hasValidBeginLoc) {
@@ -38,16 +40,31 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
 
 } // namespace
 
-namespace clang::tidy::modernize {
+AvoidCArraysCheck::AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  AllowStringArrays(Options.get("AllowStringArrays", false)) {}
+
+void AvoidCArraysCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "AllowStringArrays", AllowStringArrays);
+}
 
 void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
+  ast_matchers::internal::Matcher IgnoreStringArrayIfNeededMatcher =
+  anything();
+  if (AllowStringArrays)
+IgnoreStringArrayIfNeededMatcher =
+unless(typeLoc(loc(hasCanonicalType(incompleteArrayType(
+   hasElementType(isAnyCharacter(),
+   hasParent(varDecl(hasInitializer(stringLiteral());
+
   Finder->addMatcher(
   typeLoc(hasValidBeginLoc(), hasType(arrayType()),
   unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())),
hasParent(varDecl(isExternC())),
hasParent(fieldDecl(
hasParent(recordDecl(isExternCContext(),
-   hasAncestor(functionDecl(isExternC())
+   hasAncestor(functionDecl(isExternC(),
+  std::move(IgnoreStringArrayIfNeededMatcher))
   .bind("typeloc"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h 
b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
index 7099f99c869498f..719e88e4b31662f 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
@@ -19,13 +19,19 @@ namespace clang::tidy::modernize {
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-arrays.html
 class AvoidCArraysCheck : public ClangTidyCheck {
 public:
-  AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus11;
   }
-  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+
+private:
+  const bool AllowStringArrays;
 };
 
 } // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..97e532abbf8c715 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -330,6 +330,11 @@ Changes in existing checks
   ` check to
   not emit a ``return`` for fixes when the function returns ``void``.
 
+- Improved :doc:`modernize-av

[clang] [clang-tools-extra] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)

2023-11-08 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

In tests we usually use `-fno-delayed-template-parsing` to overcome this issue 
with templates and windows.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

Example:
```
llvm/include/llvm/Support/MathExtras.h:59:31: warning: prefer std::numbers math 
constant [modernize-use-std-numbers]
   59 | inv_sqrt3f  = .577350269F, // (0x1.279a74P-1)
  |   ^~~
  |   std::numbers::egamma_v
```

```
egammaf = .577215665F
```

Looks like having this check implemented as an multiple matchers isn't a good 
idea, simply because we pickup first one that match instead a nearest one. This 
leads to bugs when dealing with proper values.

In ideal conditions something like x* 3.14 should be even detected as PI. 
Also warning message should already say what from std::numbers should be used 
and how far are current and proposed values from them self.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-11-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-09 Thread Piotr Zegar via cfe-commits


@@ -3,13 +3,9 @@
 readability-container-data-pointer
 ==
 
-Finds cases where code could use ``data()`` rather than the address of the
-element at index 0 in a container. This pattern is commonly used to materialize
-a pointer to the backing data of a container. ``std::vector`` and
-``std::string`` provide a ``data()`` accessor to retrieve the data pointer 
which
-should be preferred.
+Finds cases where code references the address of the element at index 0 in a 
container and replaces them with calls to ``data()`` or ``c_str()``.

PiotrZSL wrote:

Still not wrapped on 80 collumn

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


[clang-tools-extra] [clang-tidy] Improve `container-data-pointer` check to use `c_str()` (PR #71304)

2023-11-09 Thread Piotr Zegar via cfe-commits


@@ -111,16 +115,18 @@ void ContainerDataPointerCheck::check(const 
MatchFinder::MatchResult &Result) {
MemberExpr>(CE))
 ReplacementText = "(" + ReplacementText + ")";
 
-  if (CE->getType()->isPointerType())
-ReplacementText += "->data()";
-  else
-ReplacementText += ".data()";
+  ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+  ReplacementText += CStrMethod ? "c_str()" : "data()";
+
+  std::string Description =

PiotrZSL wrote:

use llvm::StringRef instead of std::string here

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


[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 8909ff6 - [clang-tidy][NFC] Reduce map lookups in IncludeSorter

2023-11-10 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-11-10T18:11:10Z
New Revision: 8909ff6927f856774a907148cadd3af904361601

URL: 
https://github.com/llvm/llvm-project/commit/8909ff6927f856774a907148cadd3af904361601
DIFF: 
https://github.com/llvm/llvm-project/commit/8909ff6927f856774a907148cadd3af904361601.diff

LOG: [clang-tidy][NFC] Reduce map lookups in IncludeSorter

Part of D117460, reduce multiple lookups on map
in IncludeSorter::addInclude method to one.

Added: 


Modified: 
clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp 
b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
index fe4d2b6d03aa48b..eb21827bdeba3cc 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
@@ -134,12 +134,13 @@ void IncludeSorter::addInclude(StringRef FileName, bool 
IsAngled,
   int Offset = findNextLine(SourceMgr->getCharacterData(EndLocation));
 
   // Record the relevant location information for this inclusion directive.
-  IncludeLocations[FileName].push_back(
+  auto &IncludeLocation = IncludeLocations[FileName];
+  IncludeLocation.push_back(
   SourceRange(HashLocation, EndLocation.getLocWithOffset(Offset)));
-  SourceLocations.push_back(IncludeLocations[FileName].back());
+  SourceLocations.push_back(IncludeLocation.back());
 
   // Stop if this inclusion is a duplicate.
-  if (IncludeLocations[FileName].size() > 1)
+  if (IncludeLocation.size() > 1)
 return;
 
   // Add the included file's name to the appropriate bucket.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

Update documentation of this check to mention this, and update release notes.
Code looks fine.

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits


@@ -41,6 +41,10 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
   }
 
   if (const auto *OpCallExpr = dyn_cast(E)) {
+if (const auto *FuncDecl = OpCallExpr->getDirectCallee())
+  if (const auto *MethodDecl = dyn_cast(FuncDecl))
+return !MethodDecl->isConst();

PiotrZSL wrote:

should it be `if (MethodDecl->isConst()) return false`; otherwise code in line 
49 could be a dead code.

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits


@@ -41,6 +41,10 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
   }
 
   if (const auto *OpCallExpr = dyn_cast(E)) {
+if (const auto *FuncDecl = OpCallExpr->getDirectCallee())

PiotrZSL wrote:

Merge this FuncDecl with MethodDecl by using dyn_cast_or_null

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

One more question, there is option for this check:
"CheckFunctionCalls
Whether to treat non-const member and non-member functions as they produce side 
effects. Disabled by default because it can increase the number of false 
positive warnings."

Won't this overlap this change ?

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits


@@ -41,6 +41,10 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
   }
 
   if (const auto *OpCallExpr = dyn_cast(E)) {
+if (const auto *MethodDecl =
+dyn_cast_or_null(OpCallExpr->getDirectCallee()))
+  return !MethodDecl->isConst();

PiotrZSL wrote:

What if called operator is ->, for example in assert we call -> operator on 
std::shared_ptr just to get member, and then we call const method, this could 
cause false-positive.

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

I'm not sure now if this wont cause too much false-positives, after all this is 
why CheckFunctionCalls option were added. Sometimes object can have 2 same 
operators, one const and one not, in such case depend on "this" type, non-const 
could be used, this would be false-positive.

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


[clang-tools-extra] [clang-tidy] bugprone-assert-side-effect non-const operator methods (PR #71974)

2023-11-10 Thread Piotr Zegar via cfe-commits


@@ -41,6 +41,10 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
   }
 
   if (const auto *OpCallExpr = dyn_cast(E)) {
+if (const auto *MethodDecl =
+dyn_cast_or_null(OpCallExpr->getDirectCallee()))
+  return !MethodDecl->isConst();

PiotrZSL wrote:

On std::shared_ptr yes, but not on std::optional

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


[clang-tools-extra] d867f66 - [clang-tidy] modernize-avoid-bind: Fix handling of operators

2023-11-11 Thread Piotr Zegar via cfe-commits

Author: Joachim Priesner
Date: 2023-11-11T09:56:33Z
New Revision: d867f668672d634d52eaeae4cdcb7f9740890082

URL: 
https://github.com/llvm/llvm-project/commit/d867f668672d634d52eaeae4cdcb7f9740890082
DIFF: 
https://github.com/llvm/llvm-project/commit/d867f668672d634d52eaeae4cdcb7f9740890082.diff

LOG: [clang-tidy] modernize-avoid-bind: Fix handling of operators

When operators are used explicitly with std::bind
invalid fixes were generated, this change fixes it.

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index 2a54eaddccb15cf..51ee35da623f202 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -691,12 +691,15 @@ void AvoidBindCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *MethodDecl = dyn_cast(LP.Callable.Decl);
 const BindArgument &ObjPtr = FunctionCallArgs.front();
 
-if (!isa(ignoreTemporariesAndPointers(ObjPtr.E))) {
-  Stream << ObjPtr.UsageIdentifier;
-  Stream << "->";
+if (MethodDecl->getOverloadedOperator() == OO_Call) {
+  Stream << "(*" << ObjPtr.UsageIdentifier << ')';
+} else {
+  if (!isa(ignoreTemporariesAndPointers(ObjPtr.E))) {
+Stream << ObjPtr.UsageIdentifier;
+Stream << "->";
+  }
+  Stream << MethodDecl->getNameAsString();
 }
-
-Stream << MethodDecl->getName();
   } else {
 switch (LP.Callable.CE) {
 case CE_Var:

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp
index 336b3cb4ee08f94..22b24d45fe63f76 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-bind.cpp
@@ -43,6 +43,7 @@ struct Foo {
 struct D {
   D() = default;
   void operator()(int x, int y) const {}
+  operator bool() const { return true; }
 
   void MemberFunction(int x) {}
   int MemberFunctionWithReturn(int x) {}
@@ -342,6 +343,7 @@ void testCapturedSubexpressions() {
 struct E {
   void MemberFunction(int x) {}
   int MemberFunctionWithReturn(int x) {}
+  int operator()(int x, int y) const { return x + y; }
 
   void testMemberFunctions() {
 D *d;
@@ -379,6 +381,26 @@ struct E {
 auto HHH = std::bind(&D::MemberFunctionWithReturn, _1, 1);
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
 // CHECK-FIXES: auto HHH = [](auto && PH1) { return 
PH1->MemberFunctionWithReturn(1); };
+
+auto III = std::bind(&D::operator(), d, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto III = [d] { (*d)(1, 2); }
+
+auto JJJ = std::bind(&D::operator(), &dd, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto JJJ = [ObjectPtr = &dd] { (*ObjectPtr)(1, 2); }
+
+auto KKK = std::bind(&D::operator(), _1, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto KKK = [](auto && PH1) { (*PH1)(1, 2); };
+
+auto LLL = std::bind(&D::operator bool, d);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto LLL = [d] { return d->operator bool(); }
+
+auto MMM = std::bind(&E::operator(), this, 1, 2);
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: prefer a lambda to std::bind
+// CHECK-FIXES: auto MMM = [this] { return (*this)(1, 2); }
   }
 };
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9311d12 - [clang-tidy][DOC] Add release notes for modernize-avoid-bind

2023-11-11 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-11-11T09:56:33Z
New Revision: 9311d12281c33e0ab8fc19ec956bdb7e13e59303

URL: 
https://github.com/llvm/llvm-project/commit/9311d12281c33e0ab8fc19ec956bdb7e13e59303
DIFF: 
https://github.com/llvm/llvm-project/commit/9311d12281c33e0ab8fc19ec956bdb7e13e59303.diff

LOG: [clang-tidy][DOC] Add release notes for modernize-avoid-bind

Add relase notes for change added in D125949.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c79aafdc0f06e69..673344a70ab0a64 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -329,7 +329,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-avoid-bind
   ` check to
-  not emit a ``return`` for fixes when the function returns ``void``.
+  not emit a ``return`` for fixes when the function returns ``void`` and to
+  provide valid fixes for cases involving bound C++ operators.
 
 - Improved :doc:`modernize-loop-convert
   ` to support for-loops with



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 0e55fef - [clang-tidy] Tweak diag ranges for bugprone-sizeof-expression

2023-11-11 Thread Piotr Zegar via cfe-commits

Author: Nathan James
Date: 2023-11-11T09:56:33Z
New Revision: 0e55fef0e98ff5fc6898f3eda43e02143dbe0748

URL: 
https://github.com/llvm/llvm-project/commit/0e55fef0e98ff5fc6898f3eda43e02143dbe0748
DIFF: 
https://github.com/llvm/llvm-project/commit/0e55fef0e98ff5fc6898f3eda43e02143dbe0748.diff

LOG: [clang-tidy] Tweak diag ranges for bugprone-sizeof-expression

Provide more useful warning locations and diagnostic ranges.

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/clangd/test/diagnostics-tidy.test
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index 62cde11ebb7399c..a1cffbc66619921 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -192,10 +192,12 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
   }
 
   // Detect expression like: sizeof(expr, expr); most likely an error.
-  Finder->addMatcher(sizeOfExpr(has(ignoringParenImpCasts(
-binaryOperator(hasOperatorName(",")
- .bind("sizeof-comma-expr"),
- this);
+  Finder->addMatcher(
+  sizeOfExpr(
+  has(ignoringParenImpCasts(
+  
binaryOperator(hasOperatorName(",")).bind("sizeof-comma-binop"
+  .bind("sizeof-comma-expr"),
+  this);
 
   // Detect sizeof(...) /sizeof(...));
   // FIXME:
@@ -255,51 +257,62 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder 
*Finder) {
   Finder->addMatcher(
   binaryOperator(
   hasAnyOperatorName("==", "!=", "<", "<=", ">", ">=", "+", "-"),
-  hasOperands(
-  anyOf(ignoringParenImpCasts(SizeOfExpr),
-ignoringParenImpCasts(binaryOperator(
-hasOperatorName("*"),
-hasEitherOperand(ignoringParenImpCasts(SizeOfExpr),
-  ignoringParenImpCasts(PtrDiffExpr)))
+  hasOperands(anyOf(ignoringParenImpCasts(
+SizeOfExpr.bind("sizeof-ptr-mul-expr")),
+ignoringParenImpCasts(binaryOperator(
+hasOperatorName("*"),
+hasEitherOperand(ignoringParenImpCasts(
+
SizeOfExpr.bind("sizeof-ptr-mul-expr")),
+  ignoringParenImpCasts(PtrDiffExpr)))
   .bind("sizeof-in-ptr-arithmetic-mul"),
   this);
 
-  Finder->addMatcher(binaryOperator(hasOperatorName("/"),
-hasLHS(ignoringParenImpCasts(PtrDiffExpr)),
-hasRHS(ignoringParenImpCasts(SizeOfExpr)))
- .bind("sizeof-in-ptr-arithmetic-div"),
- this);
+  Finder->addMatcher(
+  binaryOperator(
+  hasOperatorName("/"), hasLHS(ignoringParenImpCasts(PtrDiffExpr)),
+  
hasRHS(ignoringParenImpCasts(SizeOfExpr.bind("sizeof-ptr-div-expr"
+  .bind("sizeof-in-ptr-arithmetic-div"),
+  this);
 }
 
 void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
   const ASTContext &Ctx = *Result.Context;
 
   if (const auto *E = Result.Nodes.getNodeAs("sizeof-constant")) {
-diag(E->getBeginLoc(),
- "suspicious usage of 'sizeof(K)'; did you mean 'K'?");
+diag(E->getBeginLoc(), "suspicious usage of 'sizeof(K)'; did you mean 
'K'?")
+<< E->getSourceRange();
   } else if (const auto *E =
  Result.Nodes.getNodeAs("sizeof-integer-call")) {
 diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
-   "that results in an integer");
+   "that results in an integer")
+<< E->getSourceRange();
   } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-this")) {
 diag(E->getBeginLoc(),
- "suspicious usage of 'sizeof(this)'; did you mean 'sizeof(*this)'");
+ "suspicious usage of 'sizeof(this)'; did you mean 'sizeof(*this)'")
+<< E->getSourceRange();
   } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-charp")) {
 diag(E->getBeginLoc(),
- "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?");
+ "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
+<< E->getSourceRange();
   } else if (const auto *E =
  Result.Node

[clang-tools-extra] bbb7cb8 - [clang-tidy][DOC] Add relase notes for bugprone-sizeof-expression

2023-11-11 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-11-11T09:56:33Z
New Revision: bbb7cb80598de12347204aefa4fe6146512ad4a1

URL: 
https://github.com/llvm/llvm-project/commit/bbb7cb80598de12347204aefa4fe6146512ad4a1
DIFF: 
https://github.com/llvm/llvm-project/commit/bbb7cb80598de12347204aefa4fe6146512ad4a1.diff

LOG: [clang-tidy][DOC] Add relase notes for bugprone-sizeof-expression

Add relase notes for change added in D101617.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 673344a70ab0a64..f49c412118e7d98 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -225,6 +225,10 @@ Changes in existing checks
   ` check, so that it does not
   warn on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`bugprone-sizeof-expression
+  ` check diagnostics to 
precisely
+  highlight specific locations, providing more accurate guidance.
+
 - Improved :doc:`bugprone-unchecked-optional-access
   ` check, so that it 
does
   not crash during handling of optional values.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix macros handling in cppcoreguidelines-prefer-member-initializer (PR #72037)

2023-11-11 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/72037

Produces now valid fixes for a member variables initialized with macros. 
Correctly uses expansion location instead of location inside macro to get init 
code.

Close #70189

>From 4b47913beaecf4f22354b423bbe34411836fb4c6 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 11 Nov 2023 17:58:02 +
Subject: [PATCH] [clang-tidy] Fix macros handling in
 cppcoreguidelines-prefer-member-initializer

Produces now valid fixes for a member variables initialized with macros.
Correctly uses expansion location instead of location inside macro to
get init code.
---
 .../PreferMemberInitializerCheck.cpp  |  8 ++---
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../prefer-member-initializer.cpp | 30 +++
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 23d7303371529da..f79a67819bb8583 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -261,9 +261,9 @@ void PreferMemberInitializerCheck::check(
 
   SmallString<128> Insertion(
   {UseAssignment ? " = " : "{",
-   Lexer::getSourceText(
-   CharSourceRange(InitValue->getSourceRange(), true),
-   *Result.SourceManager, getLangOpts()),
+   Lexer::getSourceText(Result.SourceManager->getExpansionRange(
+InitValue->getSourceRange()),
+*Result.SourceManager, getLangOpts()),
UseAssignment ? "" : "}"});
 
   Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
@@ -346,7 +346,7 @@ void PreferMemberInitializerCheck::check(
   if (InvalidFix)
 continue;
   StringRef NewInit = Lexer::getSourceText(
-  CharSourceRange(InitValue->getSourceRange(), true),
+  Result.SourceManager->getExpansionRange(InitValue->getSourceRange()),
   *Result.SourceManager, getLangOpts());
   if (HasInitAlready) {
 if (InsertPos.isValid())
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f49c412118e7d98..44a8fe56def2c6e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -262,7 +262,8 @@ Changes in existing checks
 - Improved :doc:`cppcoreguidelines-prefer-member-initializer
   ` check to
   ignore delegate constructors and ignore re-assignment for reference or when
-  initialization depend on field that is initialized before.
+  initialization depend on field that is initialized before. Additionally, it
+  now provides valid fixes for member variables initialized with macros.
 
 - Improved :doc:`cppcoreguidelines-pro-bounds-array-to-pointer-decay
   ` 
check
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
index b5603dea316d596..8086caa2aa6f2c3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer.cpp
@@ -586,3 +586,33 @@ struct ReassignmentAfterUnsafetyAssignment {
   }
   int m_i;
 };
+
+namespace PR70189 {
+#define RGB(r,g,b) ((unsigned long)(((unsigned char)(r)|((unsigned 
short)((unsigned char)(g))<<8))|(((unsigned long)(unsigned char)(b))<<16)))
+#define INVALID_HANDLE_VALUE ((void*)(unsigned long long)-1)
+#define SIMPLE 12
+
+class Foo {
+public:
+  Foo() {
+// CHECK-FIXES: Foo() : m_color(RGB(255, 128, 0)), 
m_handle(INVALID_HANDLE_VALUE), m_myval(SIMPLE) {
+m_color = RGB(255, 128, 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm_color' should be initialized in 
a member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+m_handle = INVALID_HANDLE_VALUE;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm_handle' should be initialized 
in a member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+m_myval = SIMPLE;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm_myval' should be initialized in 
a member initializer of the constructor 
[cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+private:
+  unsigned long m_color;
+  void* m_handle;
+  int m_myval;
+};
+
+#undef SIMPLE
+#undef INVALID_HANDLE_VALUE
+#undef RGB
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fixes to readability-implicit-bool-conversion (PR #72050)

2023-11-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/72050

- Fixed issue with invalid code being generated when static_cast is put into 
fix, and no space were added before it.
- Fixed issue with duplicate parentheses being added when double implicit cast 
is used.

Closes #71848 

>From cf2f1aebe660bf8c94486e976f35d474dcc484f0 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 12 Nov 2023 11:31:21 +
Subject: [PATCH] [clang-tidy] Fixes to readability-implicit-bool-conversion

- Fixed issue with invalid code being generated when static_cast
  is put into fix, and no space were added before it.
- Fixed issue with duplicate parentheses being added when double
  implicit cast is used.
---
 .../ImplicitBoolConversionCheck.cpp   | 22 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 ++-
 .../readability/implicit-bool-conversion.cpp  |  9 
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 69e6d73c4fcd7bb..5e71b2fc81de7f0 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -173,16 +173,30 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr 
*Expression,
   return {};
 }
 
+bool needsSpacePrefix(SourceLocation Loc, ASTContext &Context) {
+  SourceRange PrefixRange(Loc.getLocWithOffset(-1), Loc);
+  StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+  CharSourceRange::getCharRange(PrefixRange), Context.getSourceManager(),
+  Context.getLangOpts(), nullptr);
+  if (SpaceBeforeStmtStr.empty())
+return true;
+
+  const StringRef AllowedCharacters(" \t\n\v\f\r(){}[]<>;,+=-|&~!^*/");
+  return SpaceBeforeStmtStr.rtrim(AllowedCharacters).size() ==
+ SpaceBeforeStmtStr.size();
+}
+
 void fixGenericExprCastFromBool(DiagnosticBuilder &Diag,
 const ImplicitCastExpr *Cast,
 ASTContext &Context, StringRef OtherType) {
   const Expr *SubExpr = Cast->getSubExpr();
-  bool NeedParens = !isa(SubExpr);
+  const bool NeedParens = !isa(SubExpr->IgnoreImplicit());
+  const bool NeedSpace = needsSpacePrefix(Cast->getBeginLoc(), Context);
 
   Diag << FixItHint::CreateInsertion(
-  Cast->getBeginLoc(),
-  (Twine("static_cast<") + OtherType + ">" + (NeedParens ? "(" : ""))
-  .str());
+  Cast->getBeginLoc(), (Twine() + (NeedSpace ? " " : "") + "static_cast<" +
+OtherType + ">" + (NeedParens ? "(" : ""))
+   .str());
 
   if (NeedParens) {
 SourceLocation EndLoc = Lexer::getLocForEndOfToken(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f49c412118e7d98..e0353e4344e9b6a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -410,7 +410,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take
   do-while loops into account for the `AllowIntegerConditions` and
-  `AllowPointerConditions` options.
+  `AllowPointerConditions` options. Additionally, an issue with auto-fix
+  suggestions generating invalid code in certain scenarios has been resolved.
 
 - Improved :doc:`readability-non-const-parameter
   ` check to ignore
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
index 323cf813c047000..3929984204905d3 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -478,3 +478,12 @@ namespace PR47000 {
   using IntType = int;
   int to_int2(bool x) { return IntType{x}; }
 }
+
+namespace PR71848 {
+  int fun() {
+bool foo = false;
+return( foo );
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicit conversion bool -> 'int' 
[readability-implicit-bool-conversion]
+// CHECK-FIXES: return static_cast( foo );
+  }
+}

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improved readability-bool-conversion to be more consistent when using parentheses (PR #72068)

2023-11-12 Thread Piotr Zegar via cfe-commits


@@ -412,6 +412,10 @@ Changes in existing checks
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-implicit-bool-conversion

PiotrZSL wrote:

merge release notes, one entry for a check, one sentence for a change

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


[clang-tools-extra] [clang-tidy] Improved readability-bool-conversion to be more consistent when using parentheses (PR #72068)

2023-11-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

Description for a change (commit / PR) needed.
Except that looks fine.

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


[clang] [clang-tools-extra] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)

2023-11-12 Thread Piotr Zegar via cfe-commits


@@ -308,6 +308,11 @@ Changes in existing checks
   ` check to avoid false positive 
when
   using pointer to member function.
 
+- Improved :doc:`misc-const-correctness

PiotrZSL wrote:

there is already entry for this check, just merge changes.

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


[clang] [clang-tools-extra] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)

2023-11-12 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.


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


[clang] [clang-tools-extra] [clang-tidy] fix match for binaryOperator in ExprMutationAnalyzer for misc-const-correctness (PR #70559)

2023-11-12 Thread Piotr Zegar via cfe-commits


@@ -307,11 +307,9 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check to avoid false positive 
when
   using pointer to member function.
-
-- Improved :doc:`misc-const-correctness
-  ` check to not warn on uses in
-  type-dependent binary operators, when the variable that is being
-  looked at, is not the dependent operand.
+  Additionally, the check no longer emits a diagnostic when

PiotrZSL wrote:

Looks fine, but wrap this after "to member function." 

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


[clang] [clang-tools-extra] [clang][tidy] Ensure rewriter has the correct CWD (PR #67839)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -227,6 +227,14 @@ class ErrorReporter {
   llvm::errs() << "Can't apply replacements for file " << File << "\n";
 }
   }
+
+  auto BuildDir = Context.getCurrentBuildDirectory();

PiotrZSL wrote:

I think you may need to do what is done in handleErrors method.
Simply remember old value, change new value to build directory, and after call 
to overwriteChangedFiles restore it.
By default getCurrentWorkingDirectory should return actually current working 
directory.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM, this should be merged so other llvm users could test it.
As check is complicated I expect that there can be some false-positives or 
issues reported when llvm 18 would release.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,58 @@
+.. title:: clang-tidy - modernize-use-std-numbers
+
+modernize-use-std-numbers
+=
+
+Finds constants and function calls to math functions that can be replaced
+with c++20's mathematical constants from the ``numbers`` header and offers
+fix-it hints.
+Does not match the use of variables with that value, and instead,
+offers a replacement at the definition of those variables.
+Function calls that match the pattern of how the constant is calculated are
+matched and replaced with the ``std::numbers`` constant.
+The use of macros gets replaced with the corresponding ``std::numbers``
+constant, instead of changing the macro definition.
+
+The following list of constants from the ``numbers`` header are supported:
+
+* e
+* log2e
+* log10e
+* pi
+* inv_pi
+* inv_sqrtpi
+* ln2
+* ln10
+* sqrt2
+* sqrt3
+* inv_sqrt3
+* egamma
+* phi
+
+The list currently includes all constants as of C++20.
+
+The replacements use the type of the matched constant and can remove explicit 
casts,
+i.e., switching between ``std::numbers::e``, ``std::numbers::e_v`` and 
``std::numbers::e_v``
+where appropriate.
+
+.. code-block:: c++
+
+double sqrt(double);
+double log2(double);
+void sink(auto&&) {}
+void floatSink(float);
+
+#define MY_PI 3.1415926
+
+void foo() {
+const double Pi = 3.141592653589;   // const double Pi = 
std::numbers::pi
+const auto Use = Pi / 2;// no match for Pi
+static constexpr double Euler = 2.7182818;  // static constexpr double 
Euler = std::numbers::e;
+
+log2(exp(1));   // std::numbers::log2e;
+log2(Euler);// std::numbers::log2e;
+1 / sqrt(MY_PI);// 
std::numbers::inv_sqrtpi;
+sink(MY_PI);// sink(std::numbers::pi);
+floatSink(MY_PI);   // 
floatSink(std::numbers::pi);
+floatSink(static_cast(MY_PI));   // 
floatSink(std::numbers::pi_v);
+}

PiotrZSL wrote:

Add documentation for check configuration: IncludeStyle and DiffThreshold

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

Unless you want this to be merged as 
44101708+5chmi...@users.noreply.github.com, correct your github settings, 
squash all commits into one and make sure that author of commit is correct.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,74 @@
+.. title:: clang-tidy - modernize-use-std-numbers
+
+modernize-use-std-numbers
+=
+
+Finds constants and function calls to math functions that can be replaced
+with c++20's mathematical constants from the ``numbers`` header and offers
+fix-it hints.
+Does not match the use of variables with that value, and instead,
+offers a replacement at the definition of those variables.
+Function calls that match the pattern of how the constant is calculated are
+matched and replaced with the ``std::numbers`` constant.
+The use of macros gets replaced with the corresponding ``std::numbers``
+constant, instead of changing the macro definition.
+
+The following list of constants from the ``numbers`` header are supported:
+
+* e
+* log2e
+* log10e
+* pi
+* inv_pi
+* inv_sqrtpi
+* ln2
+* ln10
+* sqrt2
+* sqrt3
+* inv_sqrt3
+* egamma
+* phi
+
+The list currently includes all constants as of C++20.
+
+The replacements use the type of the matched constant and can remove explicit 
casts,
+i.e., switching between ``std::numbers::e``, ``std::numbers::e_v`` and 
``std::numbers::e_v``
+where appropriate.
+
+.. code-block:: c++
+
+double sqrt(double);
+double log2(double);
+void sink(auto&&) {}
+void floatSink(float);
+
+#define MY_PI 3.1415926
+
+void foo() {
+const double Pi = 3.141592653589;   // const double Pi = 
std::numbers::pi
+const auto Use = Pi / 2;// no match for Pi
+static constexpr double Euler = 2.7182818;  // static constexpr double 
Euler = std::numbers::e;
+
+log2(exp(1));   // std::numbers::log2e;
+log2(Euler);// std::numbers::log2e;
+1 / sqrt(MY_PI);// 
std::numbers::inv_sqrtpi;
+sink(MY_PI);// sink(std::numbers::pi);
+floatSink(MY_PI);   // 
floatSink(std::numbers::pi);
+floatSink(static_cast(MY_PI));   // 
floatSink(std::numbers::pi_v);
+}
+
+Options
+---
+
+.. option:: DiffThreshold
+
+A floating point value that sets the detection threshold for when literals
+match a constant.
+A literal matches a constant if

PiotrZSL wrote:

Continue in previous line.

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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,74 @@
+.. title:: clang-tidy - modernize-use-std-numbers
+
+modernize-use-std-numbers
+=
+
+Finds constants and function calls to math functions that can be replaced
+with c++20's mathematical constants from the ``numbers`` header and offers
+fix-it hints.
+Does not match the use of variables with that value, and instead,
+offers a replacement at the definition of those variables.
+Function calls that match the pattern of how the constant is calculated are
+matched and replaced with the ``std::numbers`` constant.
+The use of macros gets replaced with the corresponding ``std::numbers``
+constant, instead of changing the macro definition.
+
+The following list of constants from the ``numbers`` header are supported:
+
+* e
+* log2e
+* log10e
+* pi
+* inv_pi
+* inv_sqrtpi
+* ln2
+* ln10
+* sqrt2
+* sqrt3
+* inv_sqrt3
+* egamma
+* phi
+
+The list currently includes all constants as of C++20.
+
+The replacements use the type of the matched constant and can remove explicit 
casts,
+i.e., switching between ``std::numbers::e``, ``std::numbers::e_v`` and 
``std::numbers::e_v``
+where appropriate.
+
+.. code-block:: c++
+
+double sqrt(double);
+double log2(double);
+void sink(auto&&) {}
+void floatSink(float);
+
+#define MY_PI 3.1415926
+
+void foo() {
+const double Pi = 3.141592653589;   // const double Pi = 
std::numbers::pi
+const auto Use = Pi / 2;// no match for Pi
+static constexpr double Euler = 2.7182818;  // static constexpr double 
Euler = std::numbers::e;
+
+log2(exp(1));   // std::numbers::log2e;
+log2(Euler);// std::numbers::log2e;
+1 / sqrt(MY_PI);// 
std::numbers::inv_sqrtpi;
+sink(MY_PI);// sink(std::numbers::pi);
+floatSink(MY_PI);   // 
floatSink(std::numbers::pi);
+floatSink(static_cast(MY_PI));   // 
floatSink(std::numbers::pi_v);
+}
+
+Options
+---
+
+.. option:: DiffThreshold
+
+A floating point value that sets the detection threshold for when literals
+match a constant.
+A literal matches a constant if
+``abs(literal - constant) < DiffThreshold`` evaluates to true.

PiotrZSL wrote:

true -> `true`

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


[libc] [flang] [openmp] [compiler-rt] [libcxx] [clang] [llvm] [clang-tools-extra] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,49 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// 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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(anyOf(callee(functionDecl(hasName("::std::move"))),
+ callee(unresolvedLookupExpr(hasAnyDeclaration(namedDecl(
+ hasUnderlyingDecl(hasName("::std::move"))),
+   hasArgument(0, anyOf(cxxOperatorCallExpr(
+hasOverloadedOperatorName("*"),
+callee(cxxMethodDecl(ofClass(
+matchers::matchesAnyListedName(
+SharedPointerClasses),
+unaryOperator(hasOperatorName("*")

PiotrZSL wrote:

What you need is something like:
```
callExpr(callee(unresolvedLookupExpr()), hasArgument(0, 
unaryOperator(hasUnaryOperand(expr(hasType(namedDecl().bind("c")))
```

But additionally:
- you need to ignore some implicit code in here, mainly in hasArgument(0, ...)
- you need take into account that type may be typedef to shared_ptr (you need 
to get canonical type)
- you need take into account that type may be a reference to shared_ptr (you 
may need to drop reference)

As for get, it's actually easy to handle:
```
CallExpr 0x55e2d6219a18  ''
|-UnresolvedLookupExpr 0x55e2d6219928  '' lvalue (no ADL) = 'move' 0x55e2d5a7c948 0x55e2d5c63b08
`-UnaryOperator 0x55e2d6219a00  '' 
prefix '*' cannot overflow
  `-CallExpr 0x55e2d62199e0  ''
`-CXXDependentScopeMemberExpr 0x55e2d6219998  
'' lvalue .get
  `-DeclRefExpr 0x55e2d6219978  
'std::shared_ptr':'shared_ptr' lvalue ParmVar 0x55e2d6219608 'p' 
'std::shared_ptr':'shared_ptr'
```

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


[clang] [libcxx] [llvm] [flang] [libc] [openmp] [clang-tools-extra] [compiler-rt] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,49 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// 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 "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(anyOf(callee(functionDecl(hasName("::std::move"))),
+ callee(unresolvedLookupExpr(hasAnyDeclaration(namedDecl(
+ hasUnderlyingDecl(hasName("::std::move"))),
+   hasArgument(0, anyOf(cxxOperatorCallExpr(
+hasOverloadedOperatorName("*"),
+callee(cxxMethodDecl(ofClass(
+matchers::matchesAnyListedName(
+SharedPointerClasses),
+unaryOperator(hasOperatorName("*")

PiotrZSL wrote:

unaryOperator is too wide, it will catch things like:
```
A *a;
std::move(*a);
```

and there is no shared_ptr.

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


[clang] [openmp] [compiler-rt] [libc] [llvm] [libcxx] [clang-tools-extra] [flang] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-04 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Few issues with `unaryOperator` left, after that will be fixed, it would look 
fine.

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


[openmp] [libc] [llvm] [clang-tools-extra] [libcxx] [compiler-rt] [clang] [flang] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-04 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [compiler-rt] [flang] [libcxx] [libc] [llvm] [clang] [openmp] [clang-tidy] Add bugprone-move-shared-pointer-contents check. (PR #67467)

2023-12-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,39 @@
+//===--- MoveSharedPointerContentsCheck.h - 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MOVESHAREDPOINTERCONTENTSCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+namespace clang::tidy::bugprone {
+
+/// Detects calls to move the contents out of a ``std::shared_ptr`` rather than
+/// moving the pointer itself. In other words, calling ``std::move(*p)``.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/move-shared-pointer-contents.html
+class MoveSharedPointerContentsCheck : public ClangTidyCheck {
+public:
+  MoveSharedPointerContentsCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool
+  isLanguageVersionSupported(const LangOptions &LangOptions) const override {
+return LangOptions.CPlusPlus11;
+  }
+

PiotrZSL wrote:

IgnoreUnlessSpelledInSource  matches a headers, it does not match implicit code 
like template instances.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-05 Thread Piotr Zegar via cfe-commits


@@ -261,21 +262,27 @@ void 
UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
  this);
 }
 
+UnnecessaryCopyInitialization::CheckContext::CheckContext(

PiotrZSL wrote:

I'm not a fan of this constructor, it should exist.
instead object of CheckContext should be created as:

```
CheckContext context{*NewVar, *BlockStmt, *OldVar, ...};
```

simply moving functionality of check into helper class isn't nice.
```

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-05 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.


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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-05 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-05 Thread Piotr Zegar via cfe-commits


@@ -290,69 +296,72 @@ void UnnecessaryCopyInitialization::check(
   // instantiations where the types differ and rely on implicit conversion 
would
   // no longer compile if we switched to a reference.
   if (differentReplacedTemplateParams(
-  NewVar->getType(), constructorArgumentType(OldVar, Result.Nodes),
+  Context.Var.getType(), constructorArgumentType(OldVar, Result.Nodes),
   *Result.Context))
 return;
 
   if (OldVar == nullptr) {
-handleCopyFromMethodReturn(*NewVar, *BlockStmt, *Stmt, IssueFix, ObjectArg,
-   *Result.Context);
+// `auto NewVar = functionCall();`
+handleCopyFromMethodReturn(Context, ObjectArg);
   } else {
-handleCopyFromLocalVar(*NewVar, *OldVar, *BlockStmt, *Stmt, IssueFix,
-   *Result.Context);
+// `auto NewVar = OldVar;`
+handleCopyFromLocalVar(Context, *OldVar);
   }
 }
 
-void UnnecessaryCopyInitialization::makeDiagnostic(
-DiagnosticBuilder Diagnostic, const VarDecl &Var, const Stmt &BlockStmt,
-const DeclStmt &Stmt, ASTContext &Context, bool IssueFix) {
-  const bool IsVarUnused = isVariableUnused(Var, BlockStmt, Context);
-  Diagnostic << &Var << IsVarUnused;
-  if (!IssueFix)
-return;
-  if (IsVarUnused)
-recordRemoval(Stmt, Context, Diagnostic);
-  else
-recordFixes(Var, Context, Diagnostic);
-}
-
 void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
-const VarDecl &Var, const Stmt &BlockStmt, const DeclStmt &Stmt,
-bool IssueFix, const VarDecl *ObjectArg, ASTContext &Context) {
-  bool IsConstQualified = Var.getType().isConstQualified();
-  if (!IsConstQualified && !isOnlyUsedAsConst(Var, BlockStmt, Context))
+const CheckContext &Ctx, const VarDecl *ObjectArg) {
+  bool IsConstQualified = Ctx.Var.getType().isConstQualified();
+  if (!IsConstQualified && !Ctx.IsVarOnlyUsedAsConst)
 return;
   if (ObjectArg != nullptr &&
-  !isInitializingVariableImmutable(*ObjectArg, BlockStmt, Context,
+  !isInitializingVariableImmutable(*ObjectArg, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
-
-  auto Diagnostic =
-  diag(Var.getLocation(),
-   "the %select{|const qualified }0variable %1 is copy-constructed "
-   "from a const reference%select{"
-   "%select{ but is only used as const reference|}0"
-   "| but is never used}2; consider "
-   "%select{making it a const reference|removing the statement}2")
-  << IsConstQualified;
-  makeDiagnostic(std::move(Diagnostic), Var, BlockStmt, Stmt, Context,
- IssueFix);
+  diagnoseCopyFromMethodReturn(Ctx, ObjectArg);
 }
 
 void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
-const VarDecl &Var, const VarDecl &OldVar, const Stmt &BlockStmt,
-const DeclStmt &Stmt, bool IssueFix, ASTContext &Context) {
-  if (!isOnlyUsedAsConst(Var, BlockStmt, Context) ||
-  !isInitializingVariableImmutable(OldVar, BlockStmt, Context,
+const CheckContext &Ctx, const VarDecl &OldVar) {
+  if (!Ctx.IsVarOnlyUsedAsConst ||
+  !isInitializingVariableImmutable(OldVar, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
-  auto Diagnostic = diag(Var.getLocation(),
- "local copy %1 of the variable %0 is never modified"
- "%select{| and never used}2; consider "
- "%select{avoiding the copy|removing the statement}2")
-<< &OldVar;
-  makeDiagnostic(std::move(Diagnostic), Var, BlockStmt, Stmt, Context,
- IssueFix);
+  diagnoseCopyFromLocalVar(Ctx, OldVar);
+}
+
+void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
+const CheckContext &Ctx, const VarDecl *ObjectArg) {

PiotrZSL wrote:

then remove name of parameter or comment it out as /*ObjectArg*/

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-05 Thread Piotr Zegar via cfe-commits


@@ -32,14 +32,34 @@ class UnnecessaryCopyInitialization : public ClangTidyCheck 
{
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
 
+protected:
+  // A helper to manipulate the state common to
+  // `CopyFromMethodReturn` and `CopyFromLocalVar`.
+  struct CheckContext {
+CheckContext(const ast_matchers::MatchFinder::MatchResult &Result);
+const VarDecl &Var;
+const Stmt &BlockStmt;
+const DeclStmt &VarDeclStmt;
+clang::ASTContext &ASTCtx;
+const bool IssueFix;
+const bool IsVarUnused;
+const bool IsVarOnlyUsedAsConst;
+  };
+
+  // Create diagnostics. These are virtual so that derived classes can change
+  // behaviour.
+  virtual void diagnoseCopyFromMethodReturn(const CheckContext &Ctx,

PiotrZSL wrote:

do not mix references with pointers, stick to one, specially in functions that 
does similar thing

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


[clang-tools-extra] [clang] [clang][tidy] Ensure rewriter has the correct CWD (PR #67839)

2023-12-05 Thread Piotr Zegar via cfe-commits


@@ -189,9 +191,12 @@ class ErrorReporter {
 
   void finish() {
 if (TotalFixes > 0) {
-  Rewriter Rewrite(SourceMgr, LangOpts);
+  bool AnyNotWritten = false;
   for (const auto &FileAndReplacements : FileReplacements) {
+Rewriter Rewrite(SourceMgr, LangOpts);
 StringRef File = FileAndReplacements.first();
+Files.getVirtualFileSystem().setCurrentWorkingDirectory(

PiotrZSL wrote:

maybe would be nice to restore CurrentWorkingDirectory after this function come 
to the end.

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


[clang-tools-extra] [clang] [clang][tidy] Ensure rewriter has the correct CWD (PR #67839)

2023-12-05 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -133,6 +133,11 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
 "::boost::system::error_code"))),
   AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
 
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
+   ClangTidyContext *Context,
+   std::string CheckedFunctions)
+: ClangTidyCheck(Name, Context), CheckedFunctions(CheckedFunctions) {}

PiotrZSL wrote:

std::move(CheckedFunctions)

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -133,6 +133,11 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
 "::boost::system::error_code"))),
   AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
 
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,

PiotrZSL wrote:

This constructor does not initialize AllowCastToVoid, consider supporting 
AllowCastToVoid option.
Maybe use constructor delegate.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,28 @@
+//===--- IgnoredRemoveResultCheck.cpp - clang-tidy 
===//
+//
+// 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 "IgnoredRemoveResultCheck.h"
+
+namespace clang::tidy::hicpp {
+
+IgnoredRemoveResultCheck::IgnoredRemoveResultCheck(llvm::StringRef Name,
+   ClangTidyContext *Context)
+: UnusedReturnValueCheck(Name, Context,
+ "::std::remove;"
+ "::std::remove_if;"
+ "::std::unique;") {

PiotrZSL wrote:

no need for ; at the end

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Bj=C3=B6rn?= Svensson ,
=?utf-8?q?Bj=C3=B6rn?= Svensson 
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL commented:

Small nits, but looks fine.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Bj=C3=B6rn?= Svensson ,
=?utf-8?q?Bj=C3=B6rn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -28,10 +28,12 @@ class UnusedReturnValueCheck : public ClangTidyCheck {
 return TK_IgnoreUnlessSpelledInSource;
   }
 
-private:
+protected:
+  UnusedReturnValueCheck(StringRef Name, ClangTidyContext *Context,
+ std::string CheckedFunctions);
   std::string CheckedFunctions;

PiotrZSL wrote:

make CheckedFunctions and CheckedReturnTypes private.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,17 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to ``std::erase``.
+
+Suppressing issues by casting to ``void`` is enabled by default and can be
+disabled by setting `AllowCastToVoid` option to ``false``.

PiotrZSL wrote:

Copy AllowCastToVoid documentation from oryginal check and add here.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -133,6 +133,11 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
 "::boost::system::error_code"))),
   AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
 
+UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,

PiotrZSL wrote:

or constructor argument.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Piotr Zegar via cfe-commits


@@ -261,21 +262,27 @@ void 
UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
  this);
 }
 
+UnnecessaryCopyInitialization::CheckContext::CheckContext(

PiotrZSL wrote:

Problem is that code were moved from check method to CheckContext constructor. 
And thats not nice. CheckContext (context by name) shouldn't have any logic.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Last nits, and it will look fine.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Piotr Zegar via cfe-commits


@@ -263,19 +264,26 @@ void 
UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
 
 void UnnecessaryCopyInitialization::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *NewVar = Result.Nodes.getNodeAs("newVarDecl");
+  const auto &NewVar = *Result.Nodes.getNodeAs("newVarDecl");
+  const auto &BlockStmt = *Result.Nodes.getNodeAs("blockStmt");
+  const auto &VarDeclStmt = *Result.Nodes.getNodeAs("declStmt");
+  const CheckContext Context{
+  NewVar, BlockStmt, VarDeclStmt, *Result.Context,
+  // Do not propose fixes if the DeclStmt has multiple VarDecls or in
+  // macros since we cannot place them correctly.
+  /*IssueFix*/ VarDeclStmt.isSingleDecl() &&

PiotrZSL wrote:

Do not call functions in this initialization, simple create local variables 
IssueFix, IsVarUnused, IsVarOnlyUsedAsConst and pass them to Context. In such 
case Context construction will be a simple one liner.

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


[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Piotr Zegar via cfe-commits


@@ -289,74 +297,72 @@ void UnnecessaryCopyInitialization::check(
   // instantiations where the types differ and rely on implicit conversion 
would
   // no longer compile if we switched to a reference.
   if (differentReplacedTemplateParams(
-  NewVar->getType(), constructorArgumentType(OldVar, Result.Nodes),
+  Context.Var.getType(), constructorArgumentType(OldVar, Result.Nodes),
   *Result.Context))
 return;
 
   if (OldVar == nullptr) {
-handleCopyFromMethodReturn(*NewVar, *BlockStmt, *Stmt, IssueFix, ObjectArg,
-   *Result.Context);
+// `auto NewVar = functionCall();`
+handleCopyFromMethodReturn(Context, ObjectArg);
   } else {
-handleCopyFromLocalVar(*NewVar, *OldVar, *BlockStmt, *Stmt, IssueFix,
-   *Result.Context);
+// `auto NewVar = OldVar;`
+handleCopyFromLocalVar(Context, *OldVar);
   }
 }
 
 void UnnecessaryCopyInitialization::handleCopyFromMethodReturn(
-const VarDecl &Var, const Stmt &BlockStmt, const DeclStmt &Stmt,
-bool IssueFix, const VarDecl *ObjectArg, ASTContext &Context) {
-  bool IsConstQualified = Var.getType().isConstQualified();
-  if (!IsConstQualified && !isOnlyUsedAsConst(Var, BlockStmt, Context))
+const CheckContext &Ctx, const VarDecl *ObjectArg) {
+  bool IsConstQualified = Ctx.Var.getType().isConstQualified();
+  if (!IsConstQualified && !Ctx.IsVarOnlyUsedAsConst)
 return;
   if (ObjectArg != nullptr &&
-  !isInitializingVariableImmutable(*ObjectArg, BlockStmt, Context,
+  !isInitializingVariableImmutable(*ObjectArg, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
-  if (isVariableUnused(Var, BlockStmt, Context)) {
-auto Diagnostic =
-diag(Var.getLocation(),
- "the %select{|const qualified }0variable %1 is copy-constructed "
- "from a const reference but is never used; consider "
- "removing the statement")
-<< IsConstQualified << &Var;
-if (IssueFix)
-  recordRemoval(Stmt, Context, Diagnostic);
-  } else {
-auto Diagnostic =
-diag(Var.getLocation(),
- "the %select{|const qualified }0variable %1 is copy-constructed "
- "from a const reference%select{ but is only used as const "
- "reference|}0; consider making it a const reference")
-<< IsConstQualified << &Var;
-if (IssueFix)
-  recordFixes(Var, Context, Diagnostic);
-  }
+  diagnoseCopyFromMethodReturn(Ctx);
 }
 
 void UnnecessaryCopyInitialization::handleCopyFromLocalVar(
-const VarDecl &NewVar, const VarDecl &OldVar, const Stmt &BlockStmt,
-const DeclStmt &Stmt, bool IssueFix, ASTContext &Context) {
-  if (!isOnlyUsedAsConst(NewVar, BlockStmt, Context) ||
-  !isInitializingVariableImmutable(OldVar, BlockStmt, Context,
+const CheckContext &Ctx, const VarDecl &OldVar) {
+  if (!Ctx.IsVarOnlyUsedAsConst ||
+  !isInitializingVariableImmutable(OldVar, Ctx.BlockStmt, Ctx.ASTCtx,
ExcludedContainerTypes))
 return;
+  diagnoseCopyFromLocalVar(Ctx, OldVar);
+}
 
-  if (isVariableUnused(NewVar, BlockStmt, Context)) {
-auto Diagnostic = diag(NewVar.getLocation(),
-   "local copy %0 of the variable %1 is never modified 
"
-   "and never used; "
-   "consider removing the statement")
-  << &NewVar << &OldVar;
-if (IssueFix)
-  recordRemoval(Stmt, Context, Diagnostic);
-  } else {
-auto Diagnostic =
-diag(NewVar.getLocation(),
- "local copy %0 of the variable %1 is never modified; "
- "consider avoiding the copy")
-<< &NewVar << &OldVar;
-if (IssueFix)
-  recordFixes(NewVar, Context, Diagnostic);
+void UnnecessaryCopyInitialization::diagnoseCopyFromMethodReturn(
+const CheckContext &Ctx) {
+  auto Diagnostic =
+  diag(Ctx.Var.getLocation(),
+   "the %select{|const qualified }0variable %1 is "
+   "copy-constructed "
+   "from a const reference%select{%select{ but is only used as const "
+   "reference|}0| but is never used}2; consider "
+   "%select{making it a const reference|removing the statement}2")
+  << Ctx.Var.getType().isConstQualified() << &Ctx.Var << Ctx.IsVarUnused;
+  maybeIssueFixes(Ctx, Diagnostic);
+}
+
+void UnnecessaryCopyInitialization::diagnoseCopyFromLocalVar(
+const CheckContext &Ctx, const VarDecl &OldVar) {
+  auto Diagnostic =
+  diag(Ctx.Var.getLocation(),
+   "local copy %1 of the variable %0 is never modified%select{"
+   "| and never used}2; consider %select{avoiding the copy|removing "
+   "the statement}2")
+  << &OldVar << &Ctx.Var << Ctx.IsVarUnused;
+  maybeIssueFixes(Ctx, Diagnostic);
+}
+
+void UnnecessaryCopyInitialization::maybeIssueFixes(
+const CheckContext &Ctx, D

[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-06 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] bb0b261 - [clang-tidy][NFC] Attemp to fix compliation issue in UseStdNumbersCheck.cpp

2023-12-06 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-06T18:47:59Z
New Revision: bb0b261c2c731f9ceb5a70b2343b892b2ee05f3e

URL: 
https://github.com/llvm/llvm-project/commit/bb0b261c2c731f9ceb5a70b2343b892b2ee05f3e
DIFF: 
https://github.com/llvm/llvm-project/commit/bb0b261c2c731f9ceb5a70b2343b892b2ee05f3e.diff

LOG: [clang-tidy][NFC] Attemp to fix compliation issue in UseStdNumbersCheck.cpp

Attempt to fix issue introduced in #66583

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 1f2b034713ecf..585a1bf27783f 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -62,7 +62,7 @@ AST_MATCHER(clang::QualType, isFloating) {
 }
 
 AST_MATCHER_P(clang::Expr, anyOfExhaustive,
-  llvm::ArrayRef>, Exprs) {
+  llvm::ArrayRef>, Exprs) {
   bool FoundMatch = false;
   for (const auto &InnerMatcher : Exprs) {
 clang::ast_matchers::internal::BoundNodesTreeBuilder Result = *Builder;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 



@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy %s readability-redundant-inline-specifier %t
+
+template  inline T f()
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: function 'f' has inline specifier 
but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: template  T f()
+{
+return T{};
+}
+
+template <> inline double f() = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: function 'f' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: template <> double f() = delete;
+
+inline int g(float a)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'g' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return static_cast(a - 5.F);
+}
+
+inline int g(double) = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: function 'g' has inline specifier 
but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: int g(double) = delete;
+
+class C
+{
+  public:
+inline C& operator=(const C&) = delete;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'operator=' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: C& operator=(const C&) = delete;
+
+constexpr inline C& operator=(int a);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'operator=' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr C& operator=(int a);
+
+inline C() {}
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'C' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: C() {}
+
+constexpr inline C(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: function 'C' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr C(int);
+
+inline int Get42() const { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'Get42' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: int Get42() const { return 42; }
+
+static inline constexpr int C_STATIC = 42;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'C_STATIC' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+// CHECK-FIXES: static constexpr int C_STATIC = 42;
+
+static constexpr int C_STATIC_2 = 42;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: variable 'C_STATIC_2' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+};
+
+constexpr inline int Get42() { return 42; }
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: function 'Get42' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int Get42() { return 42; }
+
+
+static constexpr inline int NAMESPACE_STATIC = 42;
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:18: warning: variable 'NAMESPACE_STATIC' 
has inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+
+inline static int fn0(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:1: warning: function 'fn0' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+static constexpr inline int fn1(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: function 'fn1' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: static constexpr int fn1(int i)
+{
+return i - 1;
+}
+
+namespace
+{
+inline int fn2(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn2' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+inline constexpr int fn3(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn3' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHECK-FIXES: constexpr int fn3(int i)
+{
+return i - 1;
+}
+}
+
+namespace ns
+{
+inline int fn4(int i)
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:5: warning: function 'fn4' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+{
+return i - 1;
+}
+
+inline constexpr int fn5(int i)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: function 'fn5' has inline 
specifier but is implicitly inlined [readability-redundant-inline-specifier]
+// CHEC

[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

2023-12-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang-tools-extra] 7deb41d - Revert "[clang-tidy][NFC] Attemp to fix compliation issue in UseStdNumbersCheck.cpp"

2023-12-06 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-06T18:59:25Z
New Revision: 7deb41db98230938486ad2f22dda353f8950ac95

URL: 
https://github.com/llvm/llvm-project/commit/7deb41db98230938486ad2f22dda353f8950ac95
DIFF: 
https://github.com/llvm/llvm-project/commit/7deb41db98230938486ad2f22dda353f8950ac95.diff

LOG: Revert "[clang-tidy][NFC] Attemp to fix compliation issue in 
UseStdNumbersCheck.cpp"

This reverts commit bb0b261c2c731f9ceb5a70b2343b892b2ee05f3e.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 585a1bf27783f..1f2b034713ecf 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -62,7 +62,7 @@ AST_MATCHER(clang::QualType, isFloating) {
 }
 
 AST_MATCHER_P(clang::Expr, anyOfExhaustive,
-  llvm::ArrayRef>, Exprs) {
+  llvm::ArrayRef>, Exprs) {
   bool FoundMatch = false;
   for (const auto &InnerMatcher : Exprs) {
 clang::ast_matchers::internal::BoundNodesTreeBuilder Result = *Builder;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 1e1e11a - Revert "[clang-tidy] add modernize-use-std-numbers (#66583)"

2023-12-06 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-06T18:59:25Z
New Revision: 1e1e11a4d7c57028953a23deae622acab5eee9ff

URL: 
https://github.com/llvm/llvm-project/commit/1e1e11a4d7c57028953a23deae622acab5eee9ff
DIFF: 
https://github.com/llvm/llvm-project/commit/1e1e11a4d7c57028953a23deae622acab5eee9ff.diff

LOG: Revert "[clang-tidy] add modernize-use-std-numbers (#66583)"

Compilation issue, to be resolved.

This reverts commit 3f73fd774cf8fc2f288767ea077bfa351eb7aa80.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp



diff  --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 28ca52f46943a..c40065358d2dc 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -39,7 +39,6 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
-  UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
   UseTransparentFunctorsCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 654f4bd0c6ba4..e994ffd2a75c8 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -40,7 +40,6 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
-#include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
 #include "UseTransparentFunctorsCheck.h"
@@ -70,8 +69,6 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
-CheckFactories.registerCheck(
-"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
 "modernize-raw-string-literal");

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
deleted file mode 100644
index 1f2b034713ecf..0
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ /dev/null
@@ -1,449 +0,0 @@
-//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
-//
-// 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 "UseStdNumbersCheck.h"
-#include "../ClangTidyDiagnosticConsumer.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/AST/Decl.h"
-#include "clang/AST/Expr.h"
-#include "clang/AST/Stmt.h"
-#include "clang/AST/Type.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/ASTMatchers/ASTMatchersInternal.h"
-#include "clang/ASTMatchers/ASTMatchersMacros.h"
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/LLVM.h"
-#include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Lex/Lexer.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/MathExtras.h"
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-namespace {
-using namespace clang::ast_matchers;
-using clang::ast_matchers::internal::Matcher;
-using llvm::StringRef;
-
-AST_MATCHER_P2(clang::FloatingLiteral, near, double, Value, double,
-   DiffThreshold) {
-  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
-}
-
-AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
-  Matcher, InnerMatcher) {
-  return !Node.isNull() &&
- InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,
-  Builder);
-}
-
-AST_MATCHER(clang::QualType, isArithmetic) {
-  return !Node.isNull() && Node->isArithmeticType();
-}
-AST_MATCHER(clang::QualType, isFloating) {
-  return !Node.isNull() && Node->isFloati

[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-12-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

I will compile this locally and try to fix it & recommit.

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


[clang-tools-extra] 0eb7d53 - [clang-tidy] add modernize-use-std-numbers (#66583)

2023-12-06 Thread Piotr Zegar via cfe-commits

Author: Julian Schmidt
Date: 2023-12-06T20:49:14Z
New Revision: 0eb7d53cfc48f2e9287bb116415620618ca850b7

URL: 
https://github.com/llvm/llvm-project/commit/0eb7d53cfc48f2e9287bb116415620618ca850b7
DIFF: 
https://github.com/llvm/llvm-project/commit/0eb7d53cfc48f2e9287bb116415620618ca850b7.diff

LOG: [clang-tidy] add modernize-use-std-numbers (#66583)

Finds constants and function calls to math functions that can be
replaced with c++20's mathematical constants from the 'numbers' 
header and offers fix-it hints.
Does not match the use of variables with that value, and instead,
offers a replacement at the definition of those variables.

Added: 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index c40065358d2dc..28ca52f46943a 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -39,6 +39,7 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
+  UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
   UseTransparentFunctorsCheck.cpp

diff  --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index e994ffd2a75c8..654f4bd0c6ba4 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -40,6 +40,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
 #include "UseTransparentFunctorsCheck.h"
@@ -69,6 +70,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
 "modernize-raw-string-literal");

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 0..1f2b034713ecf
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,449 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy 
--===//
+//
+// 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 "UseStdNumbersCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using llvm::StringRef;
+
+AST_MATCHER_P2(clang::FloatingLiteral, near, double, Value, double,
+   DiffThreshold) {
+  return std::abs(Node.getValueAsApproximateDouble() - Value) < DiffThreshold;
+}
+
+AST_MATCHER_P(clang::QualType, hasCanonicalTypeUnqualified,
+  Matcher, InnerMatcher) {
+  return !Node.isNull() &&
+ InnerMatcher.matches(Node->getCanonicalTypeUnqualified(), Finder,
+  Builder);
+}
+
+AST_MATCH

[clang-tools-extra] e1fa2fe - [clang-tidy][NFC] Change ArrayRef into std::vector in modernize-use-std-numbers

2023-12-06 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-06T20:50:48Z
New Revision: e1fa2fea03ff94627008054267a244744d76b5c2

URL: 
https://github.com/llvm/llvm-project/commit/e1fa2fea03ff94627008054267a244744d76b5c2
DIFF: 
https://github.com/llvm/llvm-project/commit/e1fa2fea03ff94627008054267a244744d76b5c2.diff

LOG: [clang-tidy][NFC] Change ArrayRef into std::vector in 
modernize-use-std-numbers

To avoid compiler errors on some platforms introduced
by #66583, now using std::vector to pass list of
matchers into main matcher, and removed static variable
as it could introduce some other issues.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 1f2b034713ecf..b299afd540b9a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -61,8 +60,8 @@ AST_MATCHER(clang::QualType, isFloating) {
   return !Node.isNull() && Node->isFloatingType();
 }
 
-AST_MATCHER_P(clang::Expr, anyOfExhaustive,
-  llvm::ArrayRef>, Exprs) {
+AST_MATCHER_P(clang::Expr, anyOfExhaustive, std::vector>,
+  Exprs) {
   bool FoundMatch = false;
   for (const auto &InnerMatcher : Exprs) {
 clang::ast_matchers::internal::BoundNodesTreeBuilder Result = *Builder;
@@ -304,7 +303,7 @@ UseStdNumbersCheck::UseStdNumbersCheck(const StringRef Name,
 
 void UseStdNumbersCheck::registerMatchers(MatchFinder *const Finder) {
   const auto Matches = MatchBuilder{DiffThreshold};
-  static const auto ConstantMatchers = {
+  std::vector> ConstantMatchers = {
   Matches.matchLog2Euler(), Matches.matchLog10Euler(),
   Matches.matchEulerTopLevel(), Matches.matchEgamma(),
   Matches.matchInvSqrtPi(), Matches.matchInvPi(),
@@ -316,7 +315,7 @@ void UseStdNumbersCheck::registerMatchers(MatchFinder 
*const Finder) {
 
   Finder->addMatcher(
   expr(
-  anyOfExhaustive(ConstantMatchers),
+  anyOfExhaustive(std::move(ConstantMatchers)),
   
unless(hasParent(explicitCastExpr(hasDestinationType(isFloating(),
   hasType(qualType(hasCanonicalTypeUnqualified(
   anyOf(qualType(asString("float")).bind("float"),



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,21 @@
+.. title:: clang-tidy - hicpp-ignored-remove-result
+
+hicpp-ignored-remove-result
+===
+
+Ensure that the result of ``std::remove``, ``std::remove_if`` and 
``std::unique``
+are not ignored according to
+`rule 17.5.1 
`_.
+
+The mutating algorithms ``std::remove``, ``std::remove_if`` and both overloads
+of ``std::unique`` operate by swapping or moving elements of the range they are
+operating over. On completion, they return an iterator to the last valid
+element. In the majority of cases the correct behavior is to use this result as
+the first operand in a call to ``std::erase``.
+

PiotrZSL wrote:

Add info that this check is a subset of bugprone-unused-return-value, and if 
that's enabled then this doesn't have to be.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-06 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Bj=C3=B6rn?= Svensson ,
=?utf-8?q?Bj=C3=B6rn?= Svensson ,
=?utf-8?q?Bj=C3=B6rn?= Svensson 
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang-tools-extra] [clang] [llvm] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-06 Thread Piotr Zegar via cfe-commits

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


[llvm] [clang] [clang-tools-extra] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-06 Thread Piotr Zegar via cfe-commits


@@ -318,7 +318,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-using
   ` check to fix function pointer and
-  forward declared ``typedef`` correctly.
+  forward declared ``typedef`` correctly. Ignore ``typedef`` declaration in

PiotrZSL wrote:

Actually release notes should say that new option IgnoreExternC were added to 
control whatever typedefs in extern C should be ignored.

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


[clang] [clang-tools-extra] [llvm] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL approved this pull request.

Loooks, good, minor nit in release notes.

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


[mlir] [lldb] [clang-tools-extra] [llvm] [flang] [libcxx] [openmp] [libc] [compiler-rt] [clang] [clang-tidy] Add performance-move-smart-pointer-contents check. (PR #66139)

2023-12-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Personally I think that check for move out of std::unique_ptr, and check for 
overall heavy moves could be implemented as an separate one, not related to 
unique_ptr. Easiest way to detect heavy moves is to check size of object, and 
above some threshold mark them as heavy. But thats a separate problem. Maybe 
this PR should be abandoned.

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


[clang-tools-extra] [clang-tidy] Add check hicpp-ignored-remove-result (PR #73119)

2023-12-07 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson ,
=?utf-8?q?Björn?= Svensson 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clang-tidy] Fix missing parentheses in readability-implicit-bool-conversion fixes (PR #74891)

2023-12-08 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/74891

Check now more properly add missing parentheses to code like this: 'bool bar = 
true ? 1 : 0 != 0;'.

Closes #71867

>From 8c3b797f1f34d18c1e9211898f7d1a5697251317 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Fri, 8 Dec 2023 22:01:23 +
Subject: [PATCH] [clang-tidy] Fix missing parentheses in
 readability-implicit-bool-conversion fixes

Check now more properly add missing parentheses to
code like this: 'bool bar = true ? 1 : 0 != 0;'.
---
 .../ImplicitBoolConversionCheck.cpp   |  35 +---
 .../clang-tidy/utils/FixItHintUtils.cpp   |  34 
 .../clang-tidy/utils/FixItHintUtils.h |   4 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   2 +-
 ...it-bool-conversion-allow-in-conditions.cpp |   6 +-
 .../implicit-bool-conversion-cxx98.cpp|  12 +-
 .../readability/implicit-bool-conversion.cpp  | 154 ++
 7 files changed, 139 insertions(+), 108 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index f0fca30de3b3c4..e011598cc7c9f9 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "ImplicitBoolConversionCheck.h"
+#include "../utils/FixItHintUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -61,31 +62,6 @@ bool isUnaryLogicalNotOperator(const Stmt *Statement) {
   return UnaryOperatorExpr && UnaryOperatorExpr->getOpcode() == UO_LNot;
 }
 
-bool areParensNeededForOverloadedOperator(OverloadedOperatorKind OperatorKind) 
{
-  switch (OperatorKind) {
-  case OO_New:
-  case OO_Delete: // Fall-through on purpose.
-  case OO_Array_New:
-  case OO_Array_Delete:
-  case OO_ArrowStar:
-  case OO_Arrow:
-  case OO_Call:
-  case OO_Subscript:
-return false;
-
-  default:
-return true;
-  }
-}
-
-bool areParensNeededForStatement(const Stmt *Statement) {
-  if (const auto *OperatorCall = dyn_cast(Statement)) {
-return areParensNeededForOverloadedOperator(OperatorCall->getOperator());
-  }
-
-  return isa(Statement) || isa(Statement);
-}
-
 void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
   const ImplicitCastExpr *Cast, const Stmt *Parent,
   ASTContext &Context) {
@@ -105,9 +81,10 @@ void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
 
   const Expr *SubExpr = Cast->getSubExpr();
 
-  bool NeedInnerParens = areParensNeededForStatement(SubExpr);
+  bool NeedInnerParens =
+  SubExpr != nullptr && 
utils::fixit::areParensNeededForStatement(*SubExpr);
   bool NeedOuterParens =
-  Parent != nullptr && areParensNeededForStatement(Parent);
+  Parent != nullptr && utils::fixit::areParensNeededForStatement(*Parent);
 
   std::string StartLocInsertion;
 
@@ -365,7 +342,7 @@ void ImplicitBoolConversionCheck::handleCastToBool(const 
ImplicitCastExpr *Cast,
 return;
   }
 
-  auto Diag = diag(Cast->getBeginLoc(), "implicit conversion %0 -> bool")
+  auto Diag = diag(Cast->getBeginLoc(), "implicit conversion %0 -> 'bool'")
   << Cast->getSubExpr()->getType();
 
   StringRef EquivalentLiteral =
@@ -382,7 +359,7 @@ void ImplicitBoolConversionCheck::handleCastFromBool(
 ASTContext &Context) {
   QualType DestType =
   NextImplicitCast ? NextImplicitCast->getType() : Cast->getType();
-  auto Diag = diag(Cast->getBeginLoc(), "implicit conversion bool -> %0")
+  auto Diag = diag(Cast->getBeginLoc(), "implicit conversion 'bool' -> %0")
   << DestType;
 
   if (const auto *BoolLiteral =
diff --git a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp 
b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
index 226dd60b5bf5f5..bbdd4326b0bac2 100644
--- a/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FixItHintUtils.cpp
@@ -224,6 +224,40 @@ std::optional addQualifierToVarDecl(const 
VarDecl &Var,
   return std::nullopt;
 }
 
+bool areParensNeededForStatement(const Stmt &Node) {
+  if (isa(&Node))
+return false;
+
+  if (isa(&Node) || isa(&Node))
+return true;
+
+  if (isa(&Node) ||
+  isa(&Node))
+return true;
+
+  if (const auto *Op = dyn_cast(&Node)) {
+switch (Op->getOperator()) {
+case OO_PlusPlus:
+  [[fallthrough]];
+case OO_MinusMinus:
+  return Op->getNumArgs() != 2;
+case OO_Call:
+  [[fallthrough]];
+case OO_Subscript:
+  [[fallthrough]];
+case OO_Arrow:
+  return false;
+default:
+  return true;
+};
+  }
+
+  if (isa(&Node))
+return true;
+
+  return false;
+}
+
 // Return true if expr needs to be put in parens when it is an argument o

[llvm] [clang] [flang] [clang-tools-extra] [libcxx] [openmp] [mlir] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,49 @@
+//===--- ReplaceMemcpyWithStdCopy.h - 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_WITH_STDCOPY_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_WITH_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+// Replace the C memcpy function with std::copy
+class ReplaceMemcpyWithStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyWithStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyWithStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Options) override;
+

PiotrZSL wrote:

Exclude implicit code with:
```
  std::optional getCheckTraversalKind() const override {
return TK_IgnoreUnlessSpelledInSource;
  }
```

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


[libcxx] [clang] [clang-tools-extra] [flang] [mlir] [openmp] [llvm] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -275,6 +275,7 @@ Clang-Tidy Checks
:doc:`modernize-raw-string-literal `, "Yes"
:doc:`modernize-redundant-void-arg `, "Yes"
:doc:`modernize-replace-auto-ptr `, "Yes"
+   :doc:`modernize-replace-memcpy-with-std-copy `, 
"Yes"

PiotrZSL wrote:

wrong link to check, didn't you use 
clang-tools-extra/clang-tidy/add_new_check.py to create a check ?

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


[libcxx] [flang] [clang] [mlir] [llvm] [openmp] [clang-tools-extra] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,47 @@
+.. title:: clang-tidy - modernize-replace-memcpy-with-stdcopy
+
+modernize-replace-memcpy-with-stdcopy
+===
+
+Replaces all occurrences of the C ``memcpy`` function with ``std::copy``

PiotrZSL wrote:

not function, but "calls", if i take address of memcpy then it wont replace

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


[mlir] [clang-tools-extra] [libcxx] [openmp] [llvm] [clang] [flang] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -275,6 +275,7 @@ Clang-Tidy Checks
:doc:`modernize-raw-string-literal `, "Yes"
:doc:`modernize-redundant-void-arg `, "Yes"
:doc:`modernize-replace-auto-ptr `, "Yes"
+   :doc:`modernize-replace-memcpy-with-std-copy `, 
"Yes"

PiotrZSL wrote:

And wrong check name

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


[openmp] [llvm] [flang] [mlir] [clang] [clang-tools-extra] [libcxx] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -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(),

PiotrZSL wrote:

why creating separate inserter ?

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


[clang-tools-extra] [mlir] [libcxx] [llvm] [flang] [openmp] [clang] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -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 != nullptr);
+
+  DiagnosticBuilder Diag =
+  diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void ReplaceMemcpyWithStdCopy::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
+  Options.store(Opts, "IncludeStyle",
+utils::IncludeSorter::toString(IncludeStyle));
+}
+
+void ReplaceMemcpyWithStdCopy::renameFunction(DiagnosticBuilder &Diag,
+  const CallExpr *MemcpyNode) {
+  const CharSourceRange FunctionNameSourceRange = 
CharSourceRange::getCharRange(
+  MemcpyNode->getBeginLoc(), MemcpyNode->getArg(0)->getBeginLoc());

PiotrZSL wrote:

wrong, use MemcpyNode->getCallee()->getSourceRange(), and remove additional "("

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


[clang-tools-extra] [openmp] [mlir] [clang] [llvm] [libcxx] [flang] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -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"),

PiotrZSL wrote:

use callee instead of hasDeclaration

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


[clang] [clang-tools-extra] [llvm] [libcxx] [openmp] [flang] [mlir] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,49 @@
+//===--- ReplaceMemcpyWithStdCopy.h - 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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_WITH_STDCOPY_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_WITH_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 

PiotrZSL wrote:

vector and string is not used.

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


[clang] [libcxx] [flang] [openmp] [clang-tools-extra] [mlir] [llvm] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -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 != nullptr);
+
+  DiagnosticBuilder Diag =
+  diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void ReplaceMemcpyWithStdCopy::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
+  Options.store(Opts, "IncludeStyle",
+utils::IncludeSorter::toString(IncludeStyle));
+}
+
+void ReplaceMemcpyWithStdCopy::renameFunction(DiagnosticBuilder &Diag,
+  const CallExpr *MemcpyNode) {
+  const CharSourceRange FunctionNameSourceRange = 
CharSourceRange::getCharRange(
+  MemcpyNode->getBeginLoc(), MemcpyNode->getArg(0)->getBeginLoc());
+
+  Diag << FixItHint::CreateReplacement(FunctionNameSourceRange, "std::copy(");
+}
+
+void ReplaceMemcpyWithStdCopy::reorderArgs(DiagnosticBuilder &Diag,
+   const CallExpr *MemcpyNode) {
+  std::array arg;
+
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = true;
+  PrintingPolicy Policy(LangOpts);
+
+  // Retrieve all the arguments
+  for (uint8_t i = 0; i < arg.size(); i++) {
+llvm::raw_string_ostream s(arg[i]);
+MemcpyNode->getArg(i)->printPretty(s, nullptr, Policy);
+  }
+
+  // Create lambda that return SourceRange of an argument
+  auto getSourceRange = [MemcpyNode](uint8_t ArgCount) -> SourceRange {
+return SourceRange(MemcpyNode->getArg(ArgCount)->getBeginLoc(),
+   MemcpyNode->getArg(ArgCount)->getEndLoc());
+  };
+
+  // Reorder the arguments
+  Diag << FixItHint::CreateReplacement(getSourceRange(0), arg[1]);
+
+  arg[2] = arg[1] + " + ((" + arg[2] + ") / sizeof(*(" + arg[1] + ")))";
+  Diag << FixItHint::CreateReplacement(getSourceRange(1), arg[2]);
+
+  Diag << FixItHint::CreateReplacement(getSourceRange(2), arg[0]);
+}
+
+void ReplaceMemcpyWithStdCopy::insertHeader(DiagnosticBuilder &Diag,
+const CallExpr *MemcpyNode,
+SourceManager *const SM) {
+  Optional FixInclude = Inserter->CreateIncludeInsertion(
+  /*FileID=*/SM->getMainFileID(), /*Header=*/"algorithm",

PiotrZSL wrote:

wrong file, how do you know that you changing an main file, maybe you change a 
header file.
get file from MemcpyNode

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


[openmp] [libcxx] [llvm] [clang-tools-extra] [flang] [clang] [mlir] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,47 @@
+.. title:: clang-tidy - modernize-replace-memcpy-with-stdcopy
+
+modernize-replace-memcpy-with-stdcopy
+===

PiotrZSL wrote:

should cover check name

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


[libcxx] [llvm] [clang-tools-extra] [mlir] [clang] [openmp] [flang] [clang-tidy] Replace memcpy with std::copy (PR #74663)

2023-12-09 Thread Piotr Zegar via cfe-commits


@@ -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 != nullptr);
+
+  DiagnosticBuilder Diag =
+  diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void ReplaceMemcpyWithStdCopy::storeOptions(ClangTidyOptions::OptionMap &Opts) 
{
+  Options.store(Opts, "IncludeStyle",
+utils::IncludeSorter::toString(IncludeStyle));
+}
+
+void ReplaceMemcpyWithStdCopy::renameFunction(DiagnosticBuilder &Diag,
+  const CallExpr *MemcpyNode) {
+  const CharSourceRange FunctionNameSourceRange = 
CharSourceRange::getCharRange(
+  MemcpyNode->getBeginLoc(), MemcpyNode->getArg(0)->getBeginLoc());
+
+  Diag << FixItHint::CreateReplacement(FunctionNameSourceRange, "std::copy(");
+}
+
+void ReplaceMemcpyWithStdCopy::reorderArgs(DiagnosticBuilder &Diag,
+   const CallExpr *MemcpyNode) {
+  std::array arg;
+
+  LangOptions LangOpts;
+  LangOpts.CPlusPlus = true;
+  PrintingPolicy Policy(LangOpts);
+
+  // Retrieve all the arguments
+  for (uint8_t i = 0; i < arg.size(); i++) {

PiotrZSL wrote:

just read from a source by using tooling::fixit::getText, or way around with:
CreateInsertionFromRange and CreateRemoval


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


  1   2   3   4   5   6   7   8   9   10   >