[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-08-02 Thread Piotr Zegar via cfe-commits
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,137 @@
+//===--- ProBoundsAvoidUncheckedContainerAccesses.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 "ProBoundsAvoidUncheckedContainerAccesses.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::cppcoreguidelines {
+
+static constexpr std::array SubscriptDefaultExclusions = {
+llvm::StringRef("::std::map"), llvm::StringRef("::std::unordered_map"),
+llvm::StringRef("::std::flat_map")};
+
+ProBoundsAvoidUncheckedContainerAccesses::
+ProBoundsAvoidUncheckedContainerAccesses(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context) {
+
+  SubscriptExcludedClasses = clang::tidy::utils::options::parseStringList(
+  Options.get("ExcludeClasses", ""));
+  SubscriptExcludedClasses.insert(SubscriptExcludedClasses.end(),
+  SubscriptDefaultExclusions.begin(),
+  SubscriptDefaultExclusions.end());
+}
+
+void ProBoundsAvoidUncheckedContainerAccesses::storeOptions(
+ClangTidyOptions::OptionMap ) {
+
+  if (SubscriptExcludedClasses.size() == SubscriptDefaultExclusions.size()) {
+Options.store(Opts, "ExcludeClasses", "");
+return;
+  }
+
+  // Sum up the sizes of the defaults ( + semicolons), so we can remove them
+  // from the saved options
+  size_t DefaultsStringLength = std::transform_reduce(
+  SubscriptDefaultExclusions.begin(), SubscriptDefaultExclusions.end(),
+  SubscriptDefaultExclusions.size(), std::plus<>(),
+  [](llvm::StringRef Name) { return Name.size(); });
+
+  std::string Serialized = clang::tidy::utils::options::serializeStringList(
+  SubscriptExcludedClasses);
+
+  Options.store(Opts, "ExcludeClasses",
+Serialized.substr(0, Serialized.size() - 
DefaultsStringLength));
+}
+
+static const CXXMethodDecl *
+findAlternative(const CXXMethodDecl *MatchedOperator) {
+  const CXXRecordDecl *Parent = MatchedOperator->getParent();
+  const QualType SubscriptThisObjType =
+  MatchedOperator->getFunctionObjectParameterReferenceType();
+
+  for (const CXXMethodDecl *Method : Parent->methods()) {
+// Require 'Method' to be as accessible as 'MatchedOperator' or more
+if (MatchedOperator->getAccess() < Method->getAccess())
+  continue;
+
+if (MatchedOperator->isConst() != Method->isConst())
+  continue;
+
+const QualType AtThisObjType =
+Method->getFunctionObjectParameterReferenceType();
+if (SubscriptThisObjType != AtThisObjType)
+  continue;
+
+const bool CorrectName = Method->getNameInfo().getAsString() == "at";
+if (!CorrectName)
+  continue;
+
+const bool SameReturnType =
+Method->getReturnType() == MatchedOperator->getReturnType();
+if (!SameReturnType)
+  continue;
+
+const bool SameNumberOfArguments =
+Method->getNumParams() == MatchedOperator->getNumParams();
+if (!SameNumberOfArguments)
+  continue;
+
+for (unsigned ArgInd = 0; ArgInd < Method->getNumParams(); ArgInd++) {
+  const bool SameArgType =
+  Method->parameters()[ArgInd]->getOriginalType() ==
+  MatchedOperator->parameters()[ArgInd]->getOriginalType();
+  if (!SameArgType)
+continue;
+}
+
+return Method;
+  }
+  return nullptr;
+}
+
+void ProBoundsAvoidUncheckedContainerAccesses::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  

[clang-tools-extra] [clang-tidy] Fix smart pointers handling in bugprone-use-after-move (PR #94869)

2024-08-01 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Rebase, bump

https://github.com/llvm/llvm-project/pull/94869
___
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 smart pointers handling in bugprone-use-after-move (PR #94869)

2024-08-01 Thread Piotr Zegar via cfe-commits

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

>From 51e3a4bb1601157416f543ba2a8ba193876ce595 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 16 Jul 2024 18:34:25 +
Subject: [PATCH] [clang-tidy] Fix smart pointers handling in
 bugprone-use-after-move

Removed custom handling of smart pointers and
added option IgnoreNonDerefSmartPtrs to restore
previous behavior if needed.
---
 .../clang-tidy/bugprone/UseAfterMoveCheck.cpp | 23 +--
 .../clang-tidy/bugprone/UseAfterMoveCheck.h   |  7 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../checks/bugprone/use-after-move.rst| 14 +++-
 .../bugprone/use-after-move-smart-ptr.cpp | 59 +
 .../checkers/bugprone/use-after-move.cpp  | 65 ++-
 .../modernize/Inputs/smart-ptr/shared_ptr.h   |  2 +
 .../modernize/Inputs/smart-ptr/unique_ptr.h   | 42 
 8 files changed, 150 insertions(+), 67 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move-smart-ptr.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 8f4b5e8092dda..954b6324e9674 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -48,7 +48,7 @@ struct UseAfterMove {
 /// various internal helper functions).
 class UseAfterMoveFinder {
 public:
-  UseAfterMoveFinder(ASTContext *TheContext);
+  UseAfterMoveFinder(ASTContext *TheContext, bool IgnoreNonDerefSmartPtrs);
 
   // Within the given code block, finds the first use of 'MovedVariable' that
   // occurs after 'MovingCall' (the expression that performs the move). If a
@@ -71,6 +71,7 @@ class UseAfterMoveFinder {
   llvm::SmallPtrSetImpl *DeclRefs);
 
   ASTContext *Context;
+  const bool IgnoreNonDerefSmartPtrs;
   std::unique_ptr Sequence;
   std::unique_ptr BlockMap;
   llvm::SmallPtrSet Visited;
@@ -92,8 +93,9 @@ static StatementMatcher inDecltypeOrTemplateArg() {
hasAncestor(expr(hasUnevaluatedContext(;
 }
 
-UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)
-: Context(TheContext) {}
+UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext,
+   bool IgnoreNonDerefSmartPtrs)
+: Context(TheContext), IgnoreNonDerefSmartPtrs(IgnoreNonDerefSmartPtrs) {}
 
 std::optional
 UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
@@ -275,11 +277,13 @@ void UseAfterMoveFinder::getDeclRefs(
 DeclRefs](const ArrayRef Matches) {
   for (const auto  : Matches) {
 const auto *DeclRef = Match.getNodeAs("declref");
-const auto *Operator = 
Match.getNodeAs("operator");
 if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) {
   // Ignore uses of a standard smart pointer that don't dereference the
   // pointer.
-  if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) {
+  const auto *Operator =
+  Match.getNodeAs("operator");
+  if (Operator || !IgnoreNonDerefSmartPtrs ||
+  !isStandardSmartPointer(DeclRef->getDecl())) {
 DeclRefs->insert(DeclRef);
   }
 }
@@ -429,6 +433,13 @@ static void emitDiagnostic(const Expr *MovingCall, const 
DeclRefExpr *MoveArg,
 << IsMove;
   }
 }
+UseAfterMoveCheck::UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreNonDerefSmartPtrs(Options.get("IgnoreNonDerefSmartPtrs", false)) {}
+
+void UseAfterMoveCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IgnoreNonDerefSmartPtrs", IgnoreNonDerefSmartPtrs);
+}
 
 void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
   // try_emplace is a common maybe-moving function that returns a
@@ -520,7 +531,7 @@ void UseAfterMoveCheck::check(const 
MatchFinder::MatchResult ) {
   }
 
   for (Stmt *CodeBlock : CodeBlocks) {
-UseAfterMoveFinder Finder(Result.Context);
+UseAfterMoveFinder Finder(Result.Context, IgnoreNonDerefSmartPtrs);
 if (auto Use = Finder.find(CodeBlock, MovingCall, Arg))
   emitDiagnostic(MovingCall, Arg, *Use, this, Result.Context,
  determineMoveType(MoveDecl));
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
index c14e802847415..ace97c58c1966 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
@@ -20,13 +20,16 @@ namespace clang::tidy::bugprone {
 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html
 class UseAfterMoveCheck : public ClangTidyCheck {
 public:
-  UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, 

[clang-tools-extra] [clang-tidy] Fix handling --driver-mode= (PR #66553)

2024-08-01 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Rebased, bump

https://github.com/llvm/llvm-project/pull/66553
___
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 --driver-mode= (PR #66553)

2024-08-01 Thread Piotr Zegar via cfe-commits

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

>From 8c9f81796c93d4309eb8711ff35d897b2088dbe4 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Fri, 15 Sep 2023 21:39:17 +
Subject: [PATCH 1/3] [clang-tidy] Fix handling --driver-mode=

Driver mode passed as an extra argument (command line or config)
were not utilized for removing invalid arguments in
stripPositionalArgs function, and even if passed as config
driver mode were not used for dependency file striping
leading to invalid handling of -MD. Additionally driver mode
were needed even if user already added cl.exe after --.
---
 .../clang-tidy/tool/ClangTidyMain.cpp | 96 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 +
 .../clang-tidy/infrastructure/driver-mode.cpp | 57 +++
 3 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/driver-mode.cpp

diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index d42dafa8ffc36..95ee4894a91ca 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -19,6 +19,7 @@
 #include "../ClangTidyForceLinker.h"
 #include "../GlobList.h"
 #include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/PluginLoader.h"
@@ -26,7 +27,11 @@
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/WithColor.h"
+#include 
+#include 
 #include 
+#include 
+#include 
 
 using namespace clang::tooling;
 using namespace llvm;
@@ -476,7 +481,7 @@ static StringRef closest(StringRef Value, const StringSet<> 
) {
   return Closest;
 }
 
-static constexpr StringLiteral VerifyConfigWarningEnd = " [-verify-config]\n";
+static constexpr StringRef VerifyConfigWarningEnd = " [-verify-config]\n";
 
 static bool verifyChecks(const StringSet<> , StringRef CheckGlob,
  StringRef Source) {
@@ -551,9 +556,91 @@ static llvm::IntrusiveRefCntPtr 
createBaseFS() {
   return BaseFS;
 }
 
+static llvm::Expected
+recreateOptionsParserIfNeeded(llvm::ArrayRef Args,
+  llvm::Expected 
OptionsParser,
+  const ClangTidyOptions ) {
+
+  auto DoubleDashIt = std::find(Args.begin(), Args.end(), StringRef("--"));
+
+  // Exit if we don't have any compiler arguments
+  if (DoubleDashIt == Args.end() || Args.empty() ||
+  Args.back() == StringRef("--"))
+return OptionsParser;
+
+  auto IsDriverMode = [](StringRef Argument) {
+return Argument.startswith("--driver-mode=");
+  };
+
+  // Exit if --driver-mode= is explicitly passed in compiler arguments
+  if (Args.end() !=
+  std::find_if(std::next(DoubleDashIt), Args.end(), IsDriverMode))
+return OptionsParser;
+
+  std::vector CommandArguments(std::next(DoubleDashIt),
+Args.end());
+
+  // Add clang-tool as program name if not added
+  if (CommandArguments.empty() ||
+  llvm::StringRef(CommandArguments.front()).startswith("-"))
+CommandArguments.insert(CommandArguments.begin(), "clang-tool");
+
+  // Apply --extra-arg and --extra-arg-before to compiler arguments
+  CommandArguments =
+  OptionsParser->getArgumentsAdjuster()(CommandArguments, "");
+
+  // Apply ExtraArgsBefore from clang-tidy config to compiler arguments
+  if (EffectiveOptions.ExtraArgsBefore)
+CommandArguments = tooling::getInsertArgumentAdjuster(
+*EffectiveOptions.ExtraArgsBefore,
+tooling::ArgumentInsertPosition::BEGIN)(CommandArguments, "");
+
+  // Apply ExtraArgs from clang-tidy config to compiler arguments
+  if (EffectiveOptions.ExtraArgs)
+CommandArguments = tooling::getInsertArgumentAdjuster(
+*EffectiveOptions.ExtraArgs,
+tooling::ArgumentInsertPosition::END)(CommandArguments, "");
+
+  // Check if now we have --driver-mode=
+  auto DriverModeIt = std::find_if(CommandArguments.begin(),
+   CommandArguments.end(), IsDriverMode);
+  if (DriverModeIt == CommandArguments.end()) {
+// Try to detect and add --driver-mode=
+std::string ExeName = CommandArguments.front();
+tooling::addTargetAndModeForProgramName(CommandArguments, ExeName);
+DriverModeIt = std::find_if(CommandArguments.begin(),
+CommandArguments.end(), IsDriverMode);
+  }
+
+  // Exit if there is no --driver-mode= at this stage
+  if (DriverModeIt == CommandArguments.end())
+return OptionsParser;
+
+  std::vector NewArgs(Args.begin(), Args.end());
+
+  // Find place to insert --driver-mode= into new args, best after program 
name.
+  auto InsertIt =
+  NewArgs.begin() + std::distance(Args.begin(), DoubleDashIt) + 1U;
+  if (!StringRef(*InsertIt).startswith("-"))
+

[clang] [clang-tools-extra] [clang-tidy] bugprone-implicit-widening ignores unsigned consts (PR #101073)

2024-08-01 Thread Piotr Zegar via cfe-commits

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

Changes made to AST classes should be tested in clang also.
Mainly here clang/test/AST/

https://github.com/llvm/llvm-project/pull/101073
___
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] Add support for bsl::optional (PR #101450)

2024-08-01 Thread Piotr Zegar via cfe-commits

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

I'm fine with change, but at the same time this check should be made 
configurable.
Also please update check documentation before committing.

https://github.com/llvm/llvm-project/pull/101450
___
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 crash in C language in readability-non-const-parameter (PR #100461)

2024-07-25 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Fix crash in modernize-use-ranges (PR #100427)

2024-07-25 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Fix crash in modernize-use-ranges (PR #100427)

2024-07-25 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Fix is reported to work, so lets merge it.

https://github.com/llvm/llvm-project/pull/100427
___
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 crash in C language in readability-non-const-parameter (PR #100461)

2024-07-24 Thread Piotr Zegar via cfe-commits

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

Fix crash that happen when redeclaration got
different number of parameters than definition.

No release notes, as this will be backported.

Fixes #100340



>From 253e132b022a4f2b454869eed416fd6966f35dd3 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 24 Jul 2024 20:20:37 +
Subject: [PATCH] [clang-tidy] Fix crash in C language in
 readability-non-const-parameter

Fix crash that happen when redeclaration got
diffrent number of parameters than definition.

Fixes #100340
---
 .../clang-tidy/readability/NonConstParameterCheck.cpp |  5 -
 .../checkers/readability/non-const-parameter.c| 11 +++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c

diff --git 
a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index 95a3a5165e2e8..43b69a24bdb16 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -157,9 +157,12 @@ void NonConstParameterCheck::diagnoseNonConstParameters() {
 if (!Function)
   continue;
 unsigned Index = Par->getFunctionScopeIndex();
-for (FunctionDecl *FnDecl : Function->redecls())
+for (FunctionDecl *FnDecl : Function->redecls()) {
+  if (FnDecl->getNumParams() <= Index)
+continue;
   Fixes.push_back(FixItHint::CreateInsertion(
   FnDecl->getParamDecl(Index)->getBeginLoc(), "const "));
+}
 
 diag(Par->getLocation(), "pointer parameter '%0' can be pointer to const")
 << Par->getName() << Fixes;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c 
b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
new file mode 100644
index 0..db50467f3dd94
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/non-const-parameter.c
@@ -0,0 +1,11 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+static int f();
+
+int f(p)
+  int *p;
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: pointer parameter 'p' can be 
pointer to const [readability-non-const-parameter]
+// CHECK-FIXES: {{^}}  const int *p;{{$}}
+{
+return *p;
+}

___
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-redundant-smartptr-get does not remove (#97964) (PR #100177)

2024-07-24 Thread Piotr Zegar via cfe-commits


@@ -104,6 +104,296 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`bugprone-assert-side-effect
+  ` check by detecting side
+  effect from calling a method with non-const reference parameters.

PiotrZSL wrote:

still incorrectly rebased code, that stuff shoudn't be here
just rebase your changes on top of main branch, and then do force push, or 
cleanup this fill manually

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


[clang-tools-extra] Fix crash in modernize-use-ranges (PR #100427)

2024-07-24 Thread Piotr Zegar via cfe-commits


@@ -123,32 +108,34 @@ makeMatcherPair(StringRef State, const 
UseRangesCheck::Indexes ,
 }
 
 void UseRangesCheck::registerMatchers(MatchFinder *Finder) {
-  Replaces = getReplacerMap();
+  auto Replaces = getReplacerMap();
   ReverseDescriptor = getReverseDescriptor();
   auto BeginEndNames = getFreeBeginEndMethods();
   llvm::SmallVector BeginNames{
   llvm::make_first_range(BeginEndNames)};
   llvm::SmallVector EndNames{
   llvm::make_second_range(BeginEndNames)};
-  llvm::DenseSet> Seen;
+  Replacers.clear();

PiotrZSL wrote:

Note: that Replaces vs Replacers is confusing, consider changing a name of one 
later on main.

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


[clang-tools-extra] Fix crash in modernize-use-ranges (PR #100427)

2024-07-24 Thread Piotr Zegar via cfe-commits

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


https://github.com/llvm/llvm-project/pull/100427
___
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-redundant-smartptr-get does not remove (#97964) (PR #100177)

2024-07-23 Thread Piotr Zegar via cfe-commits


@@ -498,6 +498,10 @@ Changes in existing checks
   false-positives when type of the member does not match the type of the
   initializer.
 
+- Improved :doc:`readability-redundant-smartptr-get

PiotrZSL wrote:

you may need to rebase, as release notes has been cleared after branch out

https://github.com/llvm/llvm-project/pull/100177
___
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-redundant-smartptr-get does not remove (#97964) (PR #100177)

2024-07-23 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/100177
___
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-redundant-smartptr-get does not remove (#97964) (PR #100177)

2024-07-23 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Except release notes, looks fine.

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


[clang-tools-extra] Extend support for specifying languages and version in add_new_check.py (PR #100129)

2024-07-23 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] Extend support for specifying languages and version in add_new_check.py (PR #100129)

2024-07-23 Thread Piotr Zegar via cfe-commits


@@ -53,7 +55,18 @@ def adapt_cmake(module_path, check_name_camel):
 
 
 # Adds a header for the new check.
-def write_header(module_path, module, namespace, check_name, check_name_camel):
+def write_header(
+module_path, module, namespace, check_name, check_name_camel, lang_restrict
+):
+if lang_restrict:
+override_supported = """
+  bool isLanguageVersionSupported(const LangOptions ) const override {

PiotrZSL wrote:

would be nice to add also getCheckTraversalKind with a 
TK_IgnoreUnlessSpelledInSource used by default

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


[clang-tools-extra] Add a description parameter to the add_new_check script (PR #100111)

2024-07-23 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] 26c99c4 - [clang-tidy] fix misc-const-correctness to work with function-try-blocks (#99925)

2024-07-23 Thread Piotr Zegar via cfe-commits

Author: Thomas Schenker
Date: 2024-07-23T07:38:49Z
New Revision: 26c99c421794902b0d929fd9eff81314da55675c

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

LOG: [clang-tidy] fix misc-const-correctness to work with function-try-blocks 
(#99925)

Make the clang-tidy check misc-const-correctness work with
function-try-blocks.

Fixes #99860.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index 8b500de0c028c..e20cf6fbcb55a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -93,13 +93,12 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // shall be run.
   const auto FunctionScope =
   functionDecl(
-  hasBody(
-  compoundStmt(forEachDescendant(
-   declStmt(containsAnyDeclaration(
-LocalValDecl.bind("local-value")),
-unless(has(decompositionDecl(
-   .bind("decl-stmt")))
-  .bind("scope")))
+  hasBody(stmt(forEachDescendant(
+   declStmt(containsAnyDeclaration(
+LocalValDecl.bind("local-value")),
+unless(has(decompositionDecl(
+   .bind("decl-stmt")))
+  .bind("scope")))
   .bind("function-decl");
 
   Finder->addMatcher(FunctionScope, this);
@@ -109,7 +108,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
 enum class VariableCategory { Value, Reference, Pointer };
 
 void ConstCorrectnessCheck::check(const MatchFinder::MatchResult ) {
-  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
+  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
 
@@ -198,7 +197,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult ) {
   }
 }
 
-void ConstCorrectnessCheck::registerScope(const CompoundStmt *LocalScope,
+void ConstCorrectnessCheck::registerScope(const Stmt *LocalScope,
   ASTContext *Context) {
   auto  = ScopesCache[LocalScope];
   if (!Analyzer)

diff  --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index 08ffde524522a..bba060e555d00 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -32,10 +32,10 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 
 private:
-  void registerScope(const CompoundStmt *LocalScope, ASTContext *Context);
+  void registerScope(const Stmt *LocalScope, ASTContext *Context);
 
   using MutationAnalyzer = std::unique_ptr;
-  llvm::DenseMap ScopesCache;
+  llvm::DenseMap ScopesCache;
   llvm::DenseSet TemplateDiagnosticsCache;
 
   const bool AnalyzeValues;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0b2c04c23761c..083b098d05d4a 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -381,7 +381,8 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check by avoiding infinite 
recursion
   for recursive functions with forwarding reference parameters and reference
-  variables which refer to themselves.
+  variables which refer to themselves. Also adapted the check to work with
+  function-try-blocks.
 
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index cb6bfcc1dccba..2af4bfb0bd449 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -56,6 +56,15 @@ void some_function(double np_arg0, wchar_t np_arg1) {
   np_local6--;
 }
 
+int function_try_block() try {
+  int p_local0 = 0;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: 

[clang-tools-extra] 2dd82c5 - [clang-tidy][NFC] Added -fexceptions to const-correctness-values.cp

2024-07-23 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2024-07-23T07:38:49Z
New Revision: 2dd82c5ac56623d38de977ef027b252b4908e4c5

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

LOG: [clang-tidy][NFC] Added -fexceptions to const-correctness-values.cp

Related to #99925.

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 2af4bfb0bd449..0d1ff0db58371 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -3,7 +3,7 @@
 // RUN: misc-const-correctness.TransformValues: true, \
 // RUN: misc-const-correctness.WarnPointersAsValues: false, \
 // RUN: misc-const-correctness.TransformPointersAsValues: false \
-// RUN:   }}" -- -fno-delayed-template-parsing
+// RUN:   }}" -- -fno-delayed-template-parsing -fexceptions
 
 // --- Provide test samples for primitive builtins -
 // - every 'p_*' variable is a 'potential_const_*' variable



___
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 misc-const-correctness to work with function-try-blocks (PR #99925)

2024-07-23 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Looks like missing -fexceptions

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


[clang-tools-extra] Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (PR #100069)

2024-07-23 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Revert "[clang-tidy] fix misc-const-correctness to work with function-try-blocks" (PR #100069)

2024-07-23 Thread Piotr Zegar via cfe-commits

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

Reverts llvm/llvm-project#99925

>From a96af6c18ea45269c4d2e1fd762a14d763be0358 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 23 Jul 2024 08:46:14 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang-tidy]=20fix=20misc-const-corre?=
 =?UTF-8?q?ctness=20to=20work=20with=20function-try-blo=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit cd9e42cb0f2fdf1834e2e6ad2befdba0d7cc84b5.
---
 .../clang-tidy/misc/ConstCorrectnessCheck.cpp   | 17 +
 .../clang-tidy/misc/ConstCorrectnessCheck.h |  4 ++--
 clang-tools-extra/docs/ReleaseNotes.rst |  3 +--
 .../checkers/misc/const-correctness-values.cpp  |  9 -
 4 files changed, 12 insertions(+), 21 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index e20cf6fbcb55a..8b500de0c028c 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -93,12 +93,13 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
   // shall be run.
   const auto FunctionScope =
   functionDecl(
-  hasBody(stmt(forEachDescendant(
-   declStmt(containsAnyDeclaration(
-LocalValDecl.bind("local-value")),
-unless(has(decompositionDecl(
-   .bind("decl-stmt")))
-  .bind("scope")))
+  hasBody(
+  compoundStmt(forEachDescendant(
+   declStmt(containsAnyDeclaration(
+LocalValDecl.bind("local-value")),
+unless(has(decompositionDecl(
+   .bind("decl-stmt")))
+  .bind("scope")))
   .bind("function-decl");
 
   Finder->addMatcher(FunctionScope, this);
@@ -108,7 +109,7 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder 
*Finder) {
 enum class VariableCategory { Value, Reference, Pointer };
 
 void ConstCorrectnessCheck::check(const MatchFinder::MatchResult ) {
-  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
+  const auto *LocalScope = Result.Nodes.getNodeAs("scope");
   const auto *Variable = Result.Nodes.getNodeAs("local-value");
   const auto *Function = Result.Nodes.getNodeAs("function-decl");
 
@@ -197,7 +198,7 @@ void ConstCorrectnessCheck::check(const 
MatchFinder::MatchResult ) {
   }
 }
 
-void ConstCorrectnessCheck::registerScope(const Stmt *LocalScope,
+void ConstCorrectnessCheck::registerScope(const CompoundStmt *LocalScope,
   ASTContext *Context) {
   auto  = ScopesCache[LocalScope];
   if (!Analyzer)
diff --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
index bba060e555d00..08ffde524522a 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
@@ -32,10 +32,10 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
   void check(const ast_matchers::MatchFinder::MatchResult ) override;
 
 private:
-  void registerScope(const Stmt *LocalScope, ASTContext *Context);
+  void registerScope(const CompoundStmt *LocalScope, ASTContext *Context);
 
   using MutationAnalyzer = std::unique_ptr;
-  llvm::DenseMap ScopesCache;
+  llvm::DenseMap ScopesCache;
   llvm::DenseSet TemplateDiagnosticsCache;
 
   const bool AnalyzeValues;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 083b098d05d4a..0b2c04c23761c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -381,8 +381,7 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check by avoiding infinite 
recursion
   for recursive functions with forwarding reference parameters and reference
-  variables which refer to themselves. Also adapted the check to work with
-  function-try-blocks.
+  variables which refer to themselves.
 
 - Improved :doc:`misc-definitions-in-headers
   ` check by replacing the local
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 2af4bfb0bd449..cb6bfcc1dccba 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -56,15 +56,6 @@ void some_function(double np_arg0, wchar_t np_arg1) {
   np_local6--;
 }
 
-int function_try_block() try {
-  int p_local0 = 0;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 

[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -235,3 +276,13 @@ void Negative() {
   if (MACRO(x) == nullptr)
 ;
 }
+
+void test_redundant_get() {
+  std::vector> v;
+  auto f = [](int) {};
+  for (auto i = v.begin(); i != v.end(); ++i) {
+f(*i->get());

PiotrZSL wrote:

Try with:
f((*i).get()->get()->getValue());

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


[clang-tools-extra] d48d480 - [clang-tidy][NFC] Fix tiny bug in areStatementsIdentical

2024-07-22 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2024-07-22T20:46:48Z
New Revision: d48d4805f792adbdac58d480f890449def4964ea

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

LOG: [clang-tidy][NFC] Fix tiny bug in areStatementsIdentical

Function areStatementsIdentical had an early exit
when classes of stmt does not match. That if were
added to speed up checking and do not calculate
hash id of both objects if they are not the same
type. Due to some bug, wrong pointer were used
and this resulted with comparing self to self.

This patch fixes this issue.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp 
b/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
index fd5dadc9b01db..0cdc7d08abc99 100644
--- a/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
@@ -96,7 +96,7 @@ bool areStatementsIdentical(const Stmt *FirstStmt, const Stmt 
*SecondStmt,
   if (FirstStmt == SecondStmt)
 return true;
 
-  if (FirstStmt->getStmtClass() != FirstStmt->getStmtClass())
+  if (FirstStmt->getStmtClass() != SecondStmt->getStmtClass())
 return false;
 
   if (isa(FirstStmt) && isa(SecondStmt)) {



___
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 misc-const-correctness to work with function-try-blocks (PR #99925)

2024-07-22 Thread Piotr Zegar via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/99925
___
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 misc-const-correctness to work with function-try-blocks (PR #99925)

2024-07-22 Thread Piotr Zegar via cfe-commits

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

Release notes need small fix, except that looks fine

https://github.com/llvm/llvm-project/pull/99925
___
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 misc-const-correctness to work with function-try-blocks (PR #99925)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -120,6 +120,9 @@ Improvements to clang-tidy
 - Improved :program:`check_clang_tidy.py` script. Added argument 
`-export-fixes`
   to aid in clang-tidy and test development.
 
+- Improved :doc:`misc-const-correctness

PiotrZSL wrote:

wrong place, this should be in line 375

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


[clang-tools-extra] 04d5003 - [clang-tidy][DOC] Update check documentation

2024-07-22 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2024-07-22T19:31:00Z
New Revision: 04d5003f59c1ef10a036d2158f1aa61de506e707

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

LOG: [clang-tidy][DOC] Update check documentation

Fix issues in list.rst, addapt add_new_check.py to new
format of that file, and run gen-static-analyzer-docs.py
to generate missing documentation for clang-analyzer.

Added: 

clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/optin.taint.TaintedAlloc.rst

clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.PutenvStackArray.rst

clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.BlockInCriticalSection.rst

Modified: 
clang-tools-extra/clang-tidy/add_new_check.py
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.Move.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/add_new_check.py 
b/clang-tools-extra/clang-tidy/add_new_check.py
index 3b14d5d158d2d..3a62df1f510ba 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -552,8 +552,8 @@ def format_link_alias(doc_file):
 f.write('   :header: "Name", "Offers fixes"\n\n')
 f.writelines(checks)
 # and the aliases
-f.write("\n\n")
-f.write(".. csv-table:: Aliases..\n")
+f.write("\nCheck aliases\n-\n\n")
+f.write(".. csv-table::\n")
 f.write('   :header: "Name", "Redirect", "Offers fixes"\n\n')
 f.writelines(checks_alias)
 break

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.Move.rst 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.Move.rst
index e723f21f6bc60..f478598bb4e6c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.Move.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.Move.rst
@@ -1,9 +1,13 @@
 .. title:: clang-tidy - clang-analyzer-cplusplus.Move
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-move
 
 clang-analyzer-cplusplus.Move
 =
 
 Find use-after-move bugs in C++.
 
-The clang-analyzer-cplusplus.Move check is an alias of
-Clang Static Analyzer cplusplus.Move.
+The `clang-analyzer-cplusplus.Move` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/optin.taint.TaintedAlloc.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/optin.taint.TaintedAlloc.rst
new file mode 100644
index 0..9732333c61aa7
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/optin.taint.TaintedAlloc.rst
@@ -0,0 +1,14 @@
+.. title:: clang-tidy - clang-analyzer-optin.taint.TaintedAlloc
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#optin-taint-taintedalloc
+
+clang-analyzer-optin.taint.TaintedAlloc
+===
+
+Check for memory allocations, where the size parameter might be a tainted
+(attacker controlled) value.
+
+The `clang-analyzer-optin.taint.TaintedAlloc` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.PutenvStackArray.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.PutenvStackArray.rst
new file mode 100644
index 0..0a5feff8d3ca8
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.PutenvStackArray.rst
@@ -0,0 +1,10 @@
+.. title:: clang-tidy - clang-analyzer-security.PutenvStackArray
+
+clang-analyzer-security.PutenvStackArray
+
+
+Finds calls to the function 'putenv' which pass a pointer to an automatic
+(stack-allocated) array as the argument.
+
+The clang-analyzer-security.PutenvStackArray check is an alias of
+Clang Static Analyzer security.PutenvStackArray.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.BlockInCriticalSection.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.BlockInCriticalSection.rst
new file mode 100644
index 0..40d2d3d8b8aac
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.BlockInCriticalSection.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - 

[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -235,3 +276,13 @@ void Negative() {
   if (MACRO(x) == nullptr)
 ;
 }
+
+void test_redundant_get() {
+  std::vector> v;
+  auto f = [](int) {};
+  for (auto i = v.begin(); i != v.end(); ++i) {
+f(*i->get());

PiotrZSL wrote:

`f(i->get()->get()->getValue());`


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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-22 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Draft: Create a new check to look for mis-use in calls that take iterators (PR #99917)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -400,15 +401,14 @@ Clang-Tidy Checks
:doc:`readability-use-std-min-max `, "Yes"
:doc:`zircon-temporary-objects `,
 
-Check aliases
--
 
-.. csv-table::
+.. csv-table:: Aliases..
:header: "Name", "Redirect", "Offers fixes"
 
:doc:`bugprone-narrowing-conversions `, 
:doc:`cppcoreguidelines-narrowing-conversions 
`,
:doc:`cert-con36-c `, 
:doc:`bugprone-spuriously-wake-up-functions 
`,
:doc:`cert-con54-cpp `, 
:doc:`bugprone-spuriously-wake-up-functions 
`,
+   :doc:`cert-ctr56-cpp `, 
:doc:`bugprone-pointer-arithmetic-on-polymorphic-object 
`,

PiotrZSL wrote:

thx, for pointing those issues. I will correct them.

https://github.com/llvm/llvm-project/pull/99917
___
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 bugprone-move-shared-pointer-contents check. (PR #67467)

2024-07-22 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Looks like there are still some merge conflicts, duplicated lines and so on.

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-value-param] Make `handleMoveFix` virtual (PR #99867)

2024-07-22 Thread Piotr Zegar via cfe-commits

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

Please note that at any time in future those
functions could be changed no non-virtual again,
as there are no tests to guard this.

I'm fine with the change, as it provides tiny refactoring.

https://github.com/llvm/llvm-project/pull/99867
___
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-exception-escape` didn't detech catching of an exception with pointer type by `void *` exception handler (PR #99773)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -245,6 +245,10 @@ Changes in existing checks
   where source is already a ``void``` pointer, making middle ``void`` pointer
   casts bug-free.
 
+- Improved :doc:`exception-escape 
`
+  check to correctly detect exception handler of type ``CV void *`` as 
catching all 
+  ``CV`` compatible pointer types.

PiotrZSL wrote:

```suggestion
- Improved :doc:`bugprone-exception-escape
  `  check to correctly detect 
exception 
  handler of type ``CV void *`` as catching all  ``CV`` compatible pointer 
types.
```

https://github.com/llvm/llvm-project/pull/99773
___
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-exception-escape` didn't detech catching of an exception with pointer type by `void *` exception handler (PR #99773)

2024-07-22 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/99773
___
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-exception-escape` didn't detech catching of an exception with pointer type by `void *` exception handler (PR #99773)

2024-07-22 Thread Piotr Zegar via cfe-commits

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

Except bug in release notes looks fine for me.

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -235,3 +276,13 @@ void Negative() {
   if (MACRO(x) == nullptr)
 ;
 }
+
+void test_redundant_get() {
+  std::vector> v;
+  auto f = [](int) {};
+  for (auto i = v.begin(); i != v.end(); ++i) {
+f(*i->get());

PiotrZSL wrote:

add method getValue in example ... or use get()

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -38,3 +38,14 @@ Example:
 This check implements `F.19
 `_
 from the C++ Core Guidelines.
+
+
+Options
+---
+
+.. option:: IgnoreStaticCasts
+
+Boolean flag to allow users who want to use the forwarding reference as an
+lvalue reference to convey he intention by using ``static_cast(t)`` to
+disable warning. Default value is `false`.

PiotrZSL wrote:

I think that options should be indented

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-22 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -129,15 +131,25 @@ void MissingStdForwardCheck::registerMatchers(MatchFinder 
*Finder) {
   unless(anyOf(hasAncestor(typeLoc()),
hasAncestor(expr(hasUnevaluatedContext());
 
+  auto StaticCast =
+  Options.get("IgnoreStaticCasts", false)

PiotrZSL wrote:

thats not a valid way to add options, please move this to constructor, and 
change storeOptions.

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-22 Thread Piotr Zegar via cfe-commits

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

Option should be implemented properly, except that,  looks fine

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


[clang] [clang-tools-extra] [llvm] [mlir] [clang][lldb][mlir] Fix some identical sub-expressions warnings (NFC) (PR #95715)

2024-07-22 Thread Piotr Zegar via cfe-commits


@@ -96,7 +96,7 @@ bool areStatementsIdentical(const Stmt *FirstStmt, const Stmt 
*SecondStmt,
   if (FirstStmt == SecondStmt)
 return true;
 
-  if (FirstStmt->getStmtClass() != FirstStmt->getStmtClass())
+  if (FirstStmt->getStmtClass() != SecondStmt->getStmtClass())

PiotrZSL wrote:

Thx for info, that were a bug.

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


[clang-tools-extra] Ensure functions are anchored in the global namespace (for cert-err-33) (PR #99380)

2024-07-22 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [run-clang-tidy.py] Refactor, add progress indicator, add type hints (PR #89490)

2024-07-22 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [run-clang-tidy.py] Refactor, add progress indicator, add type hints (PR #89490)

2024-07-21 Thread Piotr Zegar via cfe-commits

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


https://github.com/llvm/llvm-project/pull/89490
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,38 @@
+//===--- UseCppStyleCommentsCheck.h - 
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
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_CPP_STYLE_COMMENTS_CHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_CPP_STYLE_COMMENTS_CHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::modernize {
+/// detects C-style comments and suggests to use C++ style comments instead
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-cpp-style-comments.html
+class UseCppStyleCommentsCheck : public ClangTidyCheck {
+public:
+  UseCppStyleCommentsCheck(StringRef Name, ClangTidyContext *Context);
+  ~UseCppStyleCommentsCheck() override;

PiotrZSL wrote:

Looks to be due to private handler class

https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits


@@ -172,6 +172,11 @@ New checks
   Detects variables and functions that can be marked as static or moved into
   an anonymous namespace to enforce internal linkage.
 
+- New :doc:`modernize-use-cpp-style-comments
+  ` check.
+
+  Find C Style comments and suggests to use C++ style comments instead

PiotrZSL wrote:

missing dot at the end

https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,67 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck )
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}

PiotrZSL wrote:

what about \r ?

https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,67 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck )
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}
+
+  bool HandleComment(Preprocessor , SourceRange Range) override {
+
+if (Range.getBegin().isMacroID() ||
+PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+  return false;
+
+const StringRef Text =
+Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+ PP.getSourceManager(), PP.getLangOpts());
+
+SmallVector Matches;
+if (!CStyleCommentMatch.match(Text, )) {
+  return false;
+}
+
+Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'")
+<< FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));

PiotrZSL wrote:

modernize check shouldn't remove comments, it should transform them to proper 
one

https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,16 @@
+// RUN: %check_clang_tidy -std=c++11 %s modernize-use-cpp-style-comments %t
+
+static auto PI = 3.14159265; /* value of pi upto 8 decimal places */
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: use C++ style comments '//' 
instead of C style comments '/*...*/' [modernize-use-cpp-style-comments]
+

PiotrZSL wrote:

missing test for example for:
```int a = /*some value */ 5;```

https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,12 @@
+.. title:: clang-tidy - modernize-use-cpp-style-comments
+
+modernize-use-cpp-style-comments
+
+
+Finds C-style comments and suggests to use C++ style comments `//`.

PiotrZSL wrote:

this line should be synchronized with release notes and class description

https://github.com/llvm/llvm-project/pull/99713
___
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-cpp-style-comments check (PR #99713)

2024-07-20 Thread Piotr Zegar via cfe-commits

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

Except nits:
- check should fix comments, not delete them.
- few tests are missing, with comments in a middle of code

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


[clang-tools-extra] [run-clang-tidy.py] Refactor, add progress indicator, add type hints (PR #89490)

2024-07-18 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

Note: 4 days to branch-out

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


[clang-tools-extra] [clang-tidy][cppcoreguidelines-missing-std-forward] Do not warn when the parameter is used in a `static_cast`. (PR #99477)

2024-07-18 Thread Piotr Zegar via cfe-commits

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

This shouldn't be default behavior. 
Add support for this behavior under dedicated option that need to be opt-in.

For context, we had problem in our project with some other check recently. 
Simply check allowed to ignore return value by casting it to void, and 
developer added blindly that cast and hide an issue. There is nothing wrong 
with allowing to silent issues in other way than NOLINT, but that should be 
always put into configuration, so an default behavior would be an more safe one.

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


[clang-tools-extra] [clang-tidy][NFC] Fix gsl::not_null template parameter (PR #99472)

2024-07-18 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC] Fix gsl::not_null template parameter (PR #99472)

2024-07-18 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] 507c18b - [clang-tidy] Few tiny fixes after #99084

2024-07-18 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2024-07-18T18:19:37Z
New Revision: 507c18b445ef88d985d95181db8107f669aed998

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

LOG: [clang-tidy] Few tiny fixes after #99084

Update documentation, and correct configuration

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 955a9b94dfaf6..1da5b222c2e8f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -138,13 +138,13 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
   "^::sigismember$;"
   "^::strcasecmp$;"
   "^::strsignal$;"
-  "^::ttyname"))),
+  "^::ttyname$"))),
   CheckedReturnTypes(utils::options::parseStringList(
-  Options.get("CheckedReturnTypes", "::std::error_code$;"
-"::std::error_condition$;"
-"::std::errc$;"
-"::std::expected$;"
-"::boost::system::error_code"))),
+  Options.get("CheckedReturnTypes", "^::std::error_code$;"
+"^::std::error_condition$;"
+"^::std::errc$;"
+"^::std::expected$;"
+"^::boost::system::error_code$"))),
   AllowCastToVoid(Options.get("AllowCastToVoid", false)) {}
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
index 9205ba98729c4..10ae0fe3243a0 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
@@ -16,23 +16,26 @@ Options
This parameter supports regexp. The function is checked if the name
and scope matches, with any arguments.
By default the following functions are checked:
-   ``::std::async$, ::std::launder$, ::std::remove$, ::std::remove_if$, 
::std::unique$,
-   ::std::unique_ptr::release$, ::std::basic_string::empty$, 
::std::vector::empty$,
-   ::std::back_inserter$, ::std::distance$, ::std::find$, ::std::find_if$, 
::std::inserter$,
-   ::std::lower_bound$, ::std::make_pair$, ::std::map::count$, 
::std::map::find$,
-   ::std::map::lower_bound$, ::std::multimap::equal_range$, 
::std::multimap::upper_bound$,
-   ::std::set::count$, ::std::set::find$, ::std::setfill$, 
::std::setprecision$,
-   ::std::setw$, ::std::upper_bound$, ::std::vector::at$, ::bsearch$, 
::ferror$,
-   ::feof$, ::isalnum$, ::isalpha$, ::isblank$, ::iscntrl$, ::isdigit$, 
::isgraph$,
-   ::islower$, ::isprint$, ::ispunct$, ::isspace$, ::isupper$, ::iswalnum$, 
::iswprint$,
-   ::iswspace$, ::isxdigit$, ::memchr$, ::memcmp$, ::strcmp$, ::strcoll$, 
::strncmp$,
-   ::strpbrk$, ::strrchr$, ::strspn$, ::strstr$, ::wcscmp$, ::access$, ::bind$,
-   ::connect$, ::
diff time$, ::dlsym$, ::fnmatch$, ::getaddrinfo$, ::getopt$,
-   ::htonl$, ::htons$, ::iconv_open$, ::inet_addr$, isascii$, isatty$, ::mmap$,
-   ::newlocale$, ::openat$, ::pathconf$, ::pthread_equal$, 
::pthread_getspecific$,
-   ::pthread_mutex_trylock$, ::readdir$, ::readlink$, ::recvmsg$, ::regexec$, 
::scandir$,
-   ::semget$, ::setjmp$, ::shm_open$, ::shmget$, ::sigismember$, 
::strcasecmp$, ::strsignal$,
-   ::ttyname$``
+   ``^::std::async$, ^::std::launder$, ^::std::remove$, ^::std::remove_if$,
+   ^::std::unique$, ^::std::unique_ptr::release$, ^::std::basic_string::empty$,
+   ^::std::vector::empty$, ^::std::back_inserter$, ^::std::distance$,
+   ^::std::find$, ^::std::find_if$, ^::std::inserter$, ^::std::lower_bound$,
+   ^::std::make_pair$, ^::std::map::count$, ^::std::map::find$,
+   ^::std::map::lower_bound$, ^::std::multimap::equal_range$,
+   ^::std::multimap::upper_bound$, ^::std::set::count$, ^::std::set::find$,
+   ^::std::setfill$, ^::std::setprecision$, ^::std::setw$, 
^::std::upper_bound$,
+   ^::std::vector::at$, ^::bsearch$, ^::ferror$, ^::feof$, ^::isalnum$,
+   ^::isalpha$, ^::isblank$, ^::iscntrl$, ^::isdigit$, ^::isgraph$, 
^::islower$,
+   ^::isprint$, 

[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-17 Thread Piotr Zegar via cfe-commits


@@ -235,3 +276,13 @@ void Negative() {
   if (MACRO(x) == nullptr)
 ;
 }
+
+void test_redundant_get() {
+  std::vector> v;
+  auto f = [](int) {};
+  for (auto i = v.begin(); i != v.end(); ++i) {
+f(*i->get());

PiotrZSL wrote:

try also do a test with something like: f(*i->get()->something())

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-17 Thread Piotr Zegar via cfe-commits


@@ -502,6 +502,12 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`readability-redundant-smartptr-get
+  ` identify

PiotrZSL wrote:

and this change log does not describe what you changes, and should teel about 
improved fixits and -> leftover.

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-17 Thread Piotr Zegar via cfe-commits


@@ -502,6 +502,12 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`readability-redundant-smartptr-get
+  ` identify

PiotrZSL wrote:

and remove this entry, leave only one that you added at line 496.

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-17 Thread Piotr Zegar via cfe-commits


@@ -502,6 +502,12 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`readability-redundant-smartptr-get
+  ` identify

PiotrZSL wrote:

you got "readability/readability-redundant" when should be 
"readability/redundant"

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


[clang-tools-extra] Ensure functions are anchored in the global namespace (PR #99084)

2024-07-17 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/99084
___
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 modernize-use-std-print/format for fmt (PR #99021)

2024-07-17 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Ensure functions are anchored in the global namespace (PR #99084)

2024-07-17 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] Add support for std::rotate(_copy) and inplace_merge to modernize-use-ranges (PR #99057)

2024-07-17 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/99057
___
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 smart pointers handling in bugprone-use-after-move (PR #94869)

2024-07-16 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/94869
___
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 smart pointers handling in bugprone-use-after-move (PR #94869)

2024-07-16 Thread Piotr Zegar via cfe-commits

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

>From ceeb4006d54b40a226a7a1f4f78f7f5f9d9dd7a1 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 16 Jul 2024 18:34:25 +
Subject: [PATCH] [clang-tidy] Fix smart pointers handling in
 bugprone-use-after-move

Removed custom handling of smart pointers and
added option IgnoreNonDerefSmartPtrs to restore
previous behavior if needed.
---
 .../clang-tidy/bugprone/UseAfterMoveCheck.cpp | 23 +--
 .../clang-tidy/bugprone/UseAfterMoveCheck.h   |  7 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +-
 .../checks/bugprone/use-after-move.rst| 14 +++-
 .../bugprone/use-after-move-smart-ptr.cpp | 59 +
 .../checkers/bugprone/use-after-move.cpp  | 65 ++-
 .../modernize/Inputs/smart-ptr/shared_ptr.h   |  2 +
 .../modernize/Inputs/smart-ptr/unique_ptr.h   | 42 
 8 files changed, 148 insertions(+), 68 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move-smart-ptr.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 8f4b5e8092dda..954b6324e9674 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -48,7 +48,7 @@ struct UseAfterMove {
 /// various internal helper functions).
 class UseAfterMoveFinder {
 public:
-  UseAfterMoveFinder(ASTContext *TheContext);
+  UseAfterMoveFinder(ASTContext *TheContext, bool IgnoreNonDerefSmartPtrs);
 
   // Within the given code block, finds the first use of 'MovedVariable' that
   // occurs after 'MovingCall' (the expression that performs the move). If a
@@ -71,6 +71,7 @@ class UseAfterMoveFinder {
   llvm::SmallPtrSetImpl *DeclRefs);
 
   ASTContext *Context;
+  const bool IgnoreNonDerefSmartPtrs;
   std::unique_ptr Sequence;
   std::unique_ptr BlockMap;
   llvm::SmallPtrSet Visited;
@@ -92,8 +93,9 @@ static StatementMatcher inDecltypeOrTemplateArg() {
hasAncestor(expr(hasUnevaluatedContext(;
 }
 
-UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext)
-: Context(TheContext) {}
+UseAfterMoveFinder::UseAfterMoveFinder(ASTContext *TheContext,
+   bool IgnoreNonDerefSmartPtrs)
+: Context(TheContext), IgnoreNonDerefSmartPtrs(IgnoreNonDerefSmartPtrs) {}
 
 std::optional
 UseAfterMoveFinder::find(Stmt *CodeBlock, const Expr *MovingCall,
@@ -275,11 +277,13 @@ void UseAfterMoveFinder::getDeclRefs(
 DeclRefs](const ArrayRef Matches) {
   for (const auto  : Matches) {
 const auto *DeclRef = Match.getNodeAs("declref");
-const auto *Operator = 
Match.getNodeAs("operator");
 if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) {
   // Ignore uses of a standard smart pointer that don't dereference the
   // pointer.
-  if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) {
+  const auto *Operator =
+  Match.getNodeAs("operator");
+  if (Operator || !IgnoreNonDerefSmartPtrs ||
+  !isStandardSmartPointer(DeclRef->getDecl())) {
 DeclRefs->insert(DeclRef);
   }
 }
@@ -429,6 +433,13 @@ static void emitDiagnostic(const Expr *MovingCall, const 
DeclRefExpr *MoveArg,
 << IsMove;
   }
 }
+UseAfterMoveCheck::UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreNonDerefSmartPtrs(Options.get("IgnoreNonDerefSmartPtrs", false)) {}
+
+void UseAfterMoveCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IgnoreNonDerefSmartPtrs", IgnoreNonDerefSmartPtrs);
+}
 
 void UseAfterMoveCheck::registerMatchers(MatchFinder *Finder) {
   // try_emplace is a common maybe-moving function that returns a
@@ -520,7 +531,7 @@ void UseAfterMoveCheck::check(const 
MatchFinder::MatchResult ) {
   }
 
   for (Stmt *CodeBlock : CodeBlocks) {
-UseAfterMoveFinder Finder(Result.Context);
+UseAfterMoveFinder Finder(Result.Context, IgnoreNonDerefSmartPtrs);
 if (auto Use = Finder.find(CodeBlock, MovingCall, Arg))
   emitDiagnostic(MovingCall, Arg, *Use, this, Result.Context,
  determineMoveType(MoveDecl));
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
index c14e802847415..ace97c58c1966 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.h
@@ -20,13 +20,16 @@ namespace clang::tidy::bugprone {
 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html
 class UseAfterMoveCheck : public ClangTidyCheck {
 public:
-  UseAfterMoveCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, 

[clang-tools-extra] Add support for std::rotate(_copy) and inplace_merge to modernize-use-ranges (PR #99057)

2024-07-16 Thread Piotr Zegar via cfe-commits

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

LGTM, some tests for rotate_copy and implace_merge would be welcome but it 
isn't must as it work similar to rotate.

https://github.com/llvm/llvm-project/pull/99057
___
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 modernize-use-std-print/format for fmt (PR #99021)

2024-07-16 Thread Piotr Zegar via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/99021
___
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 false in unnecessary-value-param inside templates (PR #98488)

2024-07-15 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL commented:

Release notes entry is missing.

https://github.com/llvm/llvm-project/pull/98488
___
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-implicit-widening ignores const exprs that fit (PR #98352)

2024-07-15 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/98352
___
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-implicit-widening ignores const exprs that fit (PR #98352)

2024-07-15 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,56 @@
+// RUN: %check_clang_tidy %s 
bugprone-implicit-widening-of-multiplication-result %t -- \
+// RUN: -config='{CheckOptions: { \
+// RUN: 
bugprone-implicit-widening-of-multiplication-result.IgnoreConstantIntExpr: true 
\
+// RUN: }}' -- -target x86_64-unknown-unknown -x c++
+
+long t0() {
+  return 1 * 4;
+}
+
+unsigned long t1() {
+  const int a = 2;
+  const int b = 3;
+  return a * b;
+}
+
+long t2() {
+  constexpr int a = 16383; // ~1/2 of int16_t max
+  constexpr int b = 2;
+  return a * b;
+}
+
+constexpr int global_value() {
+  return 16;
+}
+
+unsigned long t3() {
+  constexpr int a = 3;
+  return a * global_value();
+}
+
+long t4() {
+  const char a = 3;
+  const short b = 2;
+  const int c = 5;
+  return c * b * a;
+}
+
+long t5() {
+  constexpr int min_int = (-2147483647 - 1); // A literal of -2147483648 
evaluates to long
+  return 1 * min_int;
+}
+
+unsigned long n0() {
+  const int a = 1073741824; // 1/2 of int32_t max
+  const int b = 3;
+  return a * b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: performing an implicit widening 
conversion to type 'unsigned long' of a multiplication performed in type 'int'
+  // CHECK-MESSAGES: :[[@LINE-2]]:10: note: make conversion explicit to 
silence this warning
+  // CHECK-MESSAGES:  static_cast( )

PiotrZSL wrote:

actually you should use CHECK-FIXES for this.

https://github.com/llvm/llvm-project/pull/98352
___
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-implicit-widening ignores const exprs that fit (PR #98352)

2024-07-15 Thread Piotr Zegar via cfe-commits

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

I will merge this, as change looks fine at first glance. Any new fixes/changes 
please push in separate review.

https://github.com/llvm/llvm-project/pull/98352
___
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-implicit-widening ignores const exprs that fit (PR #98352)

2024-07-15 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/98352
___
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-implicit-widening ignores const exprs that fit (PR #98352)

2024-07-15 Thread Piotr Zegar via cfe-commits


@@ -50,7 +50,7 @@ Options
If the multiplication operands are compile-time constants (like literals or
are ``constexpr``) and fit within the source expression type, do not emit a
diagnostic or suggested fix.  Only considers expressions where the source
-   expression is a signed integer type.
+   expression is a signed integer type.  Defaults to ``false``.

PiotrZSL wrote:

those options are invalid, but that can be fixed in general for all options at 
once anyway

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-15 Thread Piotr Zegar via cfe-commits


@@ -18,7 +18,6 @@ add_entrypoint_object(
   SRCS
 libc_errno.cpp
   HDRS
-errno.h

PiotrZSL wrote:

not related change, revert

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-15 Thread Piotr Zegar via cfe-commits


@@ -502,6 +502,12 @@ Changes in existing checks
   usages of ``std::string_view::compare``. Added a `StringLikeClasses` option
   to detect usages of ``compare`` method in custom string-like classes.
 
+- Improved :doc:`readability-redundant-smartptr-get
+  ` identify

PiotrZSL wrote:

duplicated readability, put check list in alphabetical order. and instead of 
duplicating check description, put information what were changed/fixed in check 
behavior.



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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [libc] clang-tidy: readability-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-15 Thread Piotr Zegar via cfe-commits

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

Fix release notes, and remove not related changed to errno (i assume due to 
merge).
fell free to rebase branch if needed

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


[clang-tools-extra] Allow unnecessary-value-param to match templated functions including lambdas with auto. (PR #97767)

2024-07-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-15 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-15 Thread Piotr Zegar via cfe-commits


@@ -166,6 +166,15 @@ utils::UseRangesCheck::ReplacerMap 
UseRangesCheck::getReplacerMap() const {
   return Result;
 }
 
+UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
+: utils::UseRangesCheck(Name, Context),
+  UseReversePipe(Options.get("UseReversePipe", false)) {}

PiotrZSL wrote:

ok

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


[clang-tools-extra] Allow unnecessary-value-param to match templated functions including lambdas with auto. (PR #97767)

2024-07-15 Thread Piotr Zegar via cfe-commits

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


https://github.com/llvm/llvm-project/pull/97767
___
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-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-14 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> can you tell me where to add test case and release notes entry

Tests:
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-smartptr-get.cpp

Release notes:
clang-tools-extra/docs/ReleaseNotes.rst

https://github.com/llvm/llvm-project/pull/98757
___
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-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/98757
___
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-redundant-smartptr-get does not remove -> (#97964) (PR #98757)

2024-07-13 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

> I am not sure if I need to write a test case for clang-tidy

Yes, and release notes entry,

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits


@@ -166,6 +166,15 @@ utils::UseRangesCheck::ReplacerMap 
UseRangesCheck::getReplacerMap() const {
   return Result;
 }
 
+UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
+: utils::UseRangesCheck(Name, Context),
+  UseReversePipe(Options.get("UseReversePipe", false)) {}

PiotrZSL wrote:

this option could be moved to utils::UseRangesCheck to avoid duplications

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits


@@ -170,3 +170,18 @@ Options
If `true` (default value) the boost headers are included as system headers
with angle brackets (`#include `), otherwise quotes are used
(`#include "boost.hpp"`).
+
+.. option:: UseReversePipe
+
+  When `true` (default `false`), fixes which involve reverse ranges will use 
the
+  pipe adaptor syntax instead of the function syntax.

PiotrZSL wrote:

Note: most of options put default value at the end of description

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits

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

Looks fine, even in this state

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


[clang-tools-extra] Allow specifying pipe syntax for use-ranges checks (PR #98696)

2024-07-13 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Ignore requires expr in bugprone-assignment-in-if-condition (PR #98079)

2024-07-12 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Fix the docs for the boost/modernize use-ranges checks (PR #98662)

2024-07-12 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] Fix the docs for the boost/modernize use-ranges checks (PR #98662)

2024-07-12 Thread Piotr Zegar via cfe-commits

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

Those functions could be listed as an bullet points.
But anyway lest, merge this and check if this fixes issues.

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


[clang-tools-extra] [libc] Update libc namespace clang-tidy checks (PR #98424)

2024-07-11 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang-tools-extra] [libc] Update libc namespace clang-tidy checks (PR #98424)

2024-07-11 Thread Piotr Zegar via cfe-commits


@@ -30,20 +30,35 @@ void ImplementationInNamespaceCheck::check(
   const auto *MatchedDecl =
   Result.Nodes.getNodeAs("child_of_translation_unit");
   const auto *NS = dyn_cast(MatchedDecl);
+
+  // LLVM libc declarations should be inside of a non-anonymous namespace.
   if (NS == nullptr || NS->isAnonymousNamespace()) {
 diag(MatchedDecl->getLocation(),
  "declaration must be enclosed within the '%0' namespace")
-<< RequiredNamespaceMacroName;
+<< RequiredNamespaceDeclMacroName;
 return;
   }
+
+  // Enforce that the namespace is the result of macro expansion
   if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
 diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
-<< RequiredNamespaceMacroName;
+<< RequiredNamespaceDeclMacroName;
 return;
   }
-  if (NS->getName().starts_with(RequiredNamespaceStart) == false) {
+
+  // We want the macro to have [[gnu::visibility("hidden")]] as a prefix, but
+  // visibility is just an attribute in the AST construct, so we check that
+  // instead.
+  if (NS->getVisibility() != Visibility::HiddenVisibility) {
 diag(NS->getLocation(), "the '%0' macro should start with '%1'")
-<< RequiredNamespaceMacroName << RequiredNamespaceStart;
+<< RequiredNamespaceDeclMacroName << RequiredNamespaceDeclStart;
+return;
+  }
+
+  // Lastly, make sure the namespace name actually has the __llvm_libc prefix
+  if (NS->getName().starts_with(RequiredNamespaceRefStart) == false) {

PiotrZSL wrote:

would be nice to exclude anonymous namespace here, i just fear that getName() 
could assert

https://github.com/llvm/llvm-project/pull/98424
___
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-implicit-widening ignores const exprs that fit (PR #98352)

2024-07-10 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

You could also mention in documentation of option that those issues are 
detected by compiler warning: `-Winteger-overflow`

https://github.com/llvm/llvm-project/pull/98352
___
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   >