[clang-tools-extra] [clang-tidy] add option to avoid "no checks enabled" error (PR #96122)

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

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

if a reason for this parameter is not to fail wrapper scripts, then maybe 
run-clang-tidy.py / run-clang-tidy-diff.py should also be updated.



https://github.com/llvm/llvm-project/pull/96122
___
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 option to avoid "no checks enabled" error (PR #96122)

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


@@ -125,6 +125,9 @@ Improvements to clang-tidy
 - Added argument `--exclude-header-filter` and config option 
`ExcludeHeaderFilterRegex`
   to exclude headers from analysis via a RegEx.
 
+- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList`

PiotrZSL wrote:

this push request does not contain new config option, only argument.

https://github.com/llvm/llvm-project/pull/96122
___
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 option to avoid "no checks enabled" error (PR #96122)

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


@@ -125,6 +125,9 @@ Improvements to clang-tidy
 - Added argument `--exclude-header-filter` and config option 
`ExcludeHeaderFilterRegex`
   to exclude headers from analysis via a RegEx.
 
+- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList`

PiotrZSL wrote:

maybe better --allow-no-checks or something that would suggest that clang-tidy 
will not fail with empty check list

https://github.com/llvm/llvm-project/pull/96122
___
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 option to avoid "no checks enabled" error (PR #96122)

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


@@ -125,6 +125,9 @@ Improvements to clang-tidy
 - Added argument `--exclude-header-filter` and config option 
`ExcludeHeaderFilterRegex`
   to exclude headers from analysis via a RegEx.
 
+- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList`

PiotrZSL wrote:

you need to document this also in other places in documentation.

https://github.com/llvm/llvm-project/pull/96122
___
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 option to avoid "no checks enabled" error (PR #96122)

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

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

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

PiotrZSL wrote:

Main reason why I pointed out that I do not like ':' character and would prefer 
',' or ';' is that:
- no other check is using it
- could in theory cause an issue for some tools that parse warnings because ': 
' characters are after "warning" and basically almost never happen in message 
itself.

https://github.com/llvm/llvm-project/pull/95550
___
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 false negatives for performance-inefficient-vector-operation (PR #95667)

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

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


https://github.com/llvm/llvm-project/pull/95667
___
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 false positives of the result of std::move() is used as rvalue for performance-move-const-arg (PR #95633)

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

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


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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

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

https://github.com/PiotrZSL commented:

Consider replacing ":" separator with ","

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


[clang-tools-extra] [clang-tidy] avoid false positive when overload for bugprone-return-const-ref-from-parameter (PR #95434)

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


@@ -18,20 +17,87 @@ namespace clang::tidy::bugprone {
 void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   returnStmt(
-  hasReturnValue(declRefExpr(to(parmVarDecl(hasType(hasCanonicalType(
-  qualType(matchers::isReferenceToConst()).bind("type"))),
-  hasAncestor(functionDecl(hasReturnTypeLoc(
-  loc(qualType(hasCanonicalType(equalsBoundNode("type"
+  hasReturnValue(declRefExpr(
+  to(parmVarDecl(hasType(hasCanonicalType(
+ qualType(lValueReferenceType(pointee(
+  qualType(isConstQualified()
+ .bind("type"
+ .bind("param",
+  hasAncestor(
+  functionDecl(hasReturnTypeLoc(loc(qualType(
+   hasCanonicalType(equalsBoundNode("type"))
+  .bind("func")))
   .bind("ret"),
   this);
 }
 
+static bool isSameTypeIgnoringConst(QualType A, QualType B) {
+  A = A.getCanonicalType();
+  B = B.getCanonicalType();
+  A.addConst();
+  B.addConst();
+  return A == B;

PiotrZSL wrote:

```suggestion
  return A.getCanonicalType().withConst() == B.getCanonicalType().withConst();
```

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


[clang-tools-extra] [clang-tidy] avoid false positive when overload for bugprone-return-const-ref-from-parameter (PR #95434)

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


@@ -18,20 +17,87 @@ namespace clang::tidy::bugprone {
 void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   returnStmt(
-  hasReturnValue(declRefExpr(to(parmVarDecl(hasType(hasCanonicalType(
-  qualType(matchers::isReferenceToConst()).bind("type"))),
-  hasAncestor(functionDecl(hasReturnTypeLoc(
-  loc(qualType(hasCanonicalType(equalsBoundNode("type"
+  hasReturnValue(declRefExpr(
+  to(parmVarDecl(hasType(hasCanonicalType(
+ qualType(lValueReferenceType(pointee(
+  qualType(isConstQualified()
+ .bind("type"
+ .bind("param",
+  hasAncestor(
+  functionDecl(hasReturnTypeLoc(loc(qualType(
+   hasCanonicalType(equalsBoundNode("type"))
+  .bind("func")))
   .bind("ret"),
   this);
 }
 
+static bool isSameTypeIgnoringConst(QualType A, QualType B) {
+  A = A.getCanonicalType();
+  B = B.getCanonicalType();
+  A.addConst();
+  B.addConst();
+  return A == B;
+}
+
+static bool isSameTypeIgnoringConstRef(QualType A, QualType B) {
+  return isSameTypeIgnoringConst(A.getCanonicalType().getNonReferenceType(),
+ B.getCanonicalType().getNonReferenceType());
+}
+
+static bool hasSameParameterTypes(const FunctionDecl , const FunctionDecl 
,
+  const ParmVarDecl ) {
+  if (FD.getNumParams() != O.getNumParams())
+return false;
+  for (unsigned I = 0, E = FD.getNumParams(); I < E; ++I) {
+const ParmVarDecl *DPD = FD.getParamDecl(I);
+const QualType OPT = O.getParamDecl(I)->getType();
+if (DPD == ) {
+  if (!llvm::isa(OPT) ||
+  !isSameTypeIgnoringConstRef(DPD->getType(), OPT))
+return false;
+} else {
+  if (!isSameTypeIgnoringConst(DPD->getType(), OPT))
+return false;
+}
+  }
+  return true;
+}
+
+static const Decl *findRVRefOverload(const FunctionDecl ,
+ const ParmVarDecl ) {
+  // Actually it would be better to do lookup in caller site.
+  // But in most of cases, overloads of LVRef and RVRef will appear together.
+  // FIXME:
+  // 1. overload in anonymous namespace
+  // 2. forward reference
+  DeclContext::lookup_result LookupResult =
+  FD.getParent()->lookup(FD.getNameInfo().getName());
+  if (LookupResult.isSingleResult()) {
+return nullptr;
+  }
+  for (const Decl *Overload : LookupResult) {
+if (Overload == )
+  continue;
+Overload->dumpColor();

PiotrZSL wrote:

debug ?

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


[clang-tools-extra] [clang-tidy] avoid false positive when overload for bugprone-return-const-ref-from-parameter (PR #95434)

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

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


[clang-tools-extra] [clang-tidy] avoid false positive when overload for bugprone-return-const-ref-from-parameter (PR #95434)

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

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

Few nits.

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


[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)

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

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

LGTM.

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


[clang-tools-extra] [clang-tidy] ignoring macro with hash preprocessing token in cppcoreguidelines-macro-usage (PR #95265)

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

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

LGTM

https://github.com/llvm/llvm-project/pull/95265
___
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-06-10 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,145 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+namespace {
+
+// Reports whether the QualType matches the inner matcher, which is expected 
to be
+// matchesAnyListedName. The QualType is expected to either point to a 
RecordDecl
+// (for concrete types) or an ElaboratedType (for dependent ones).
+AST_MATCHER_P(QualType, isSharedPointer,
+  clang::ast_matchers::internal::Matcher, InnerMatcher) 
{
+  if (const auto *RD = Node.getTypePtr()->getAsCXXRecordDecl(); RD != nullptr) 
{
+return InnerMatcher.matches(*RD, Finder, Builder);
+  } else if (const auto *ED = Node.getTypePtr()->getAs();
+ ED != nullptr) {
+if (const auto *TS = ED->getNamedType()
+ .getTypePtr()
+ ->getAs();
+TS != nullptr) {
+  return InnerMatcher.matches(*TS->getTemplateName().getAsTemplateDecl(),
+  Finder, Builder);
+}
+  }
+
+  return false;
+}
+
+} // namespace
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}

PiotrZSL wrote:

You could add boost::shared_ptr to this list.

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] Add bugprone-move-shared-pointer-contents check. (PR #67467)

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


@@ -383,7 +388,7 @@ Changes in existing checks
 
 - Improved :doc:`misc-unused-using-decls
   ` check to avoid false positive 
when
-  using in elaborated type and only check cpp files.

PiotrZSL wrote:

revert this small change.

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] Add bugprone-move-shared-pointer-contents check. (PR #67467)

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


@@ -0,0 +1,145 @@
+//===--- MoveSharedPointerContentsCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+#include 
+
+#include "MoveSharedPointerContentsCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+namespace {
+
+// Reports whether the QualType matches the inner matcher, which is expected 
to be
+// matchesAnyListedName. The QualType is expected to either point to a 
RecordDecl
+// (for concrete types) or an ElaboratedType (for dependent ones).
+AST_MATCHER_P(QualType, isSharedPointer,
+  clang::ast_matchers::internal::Matcher, InnerMatcher) 
{
+  if (const auto *RD = Node.getTypePtr()->getAsCXXRecordDecl(); RD != nullptr) 
{
+return InnerMatcher.matches(*RD, Finder, Builder);
+  } else if (const auto *ED = Node.getTypePtr()->getAs();
+ ED != nullptr) {
+if (const auto *TS = ED->getNamedType()
+ .getTypePtr()
+ ->getAs();
+TS != nullptr) {
+  return InnerMatcher.matches(*TS->getTemplateName().getAsTemplateDecl(),
+  Finder, Builder);
+}
+  }
+
+  return false;
+}
+
+} // namespace
+
+MoveSharedPointerContentsCheck::MoveSharedPointerContentsCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SharedPointerClasses(utils::options::parseStringList(
+  Options.get("SharedPointerClasses", "::std::shared_ptr"))) {}
+
+void MoveSharedPointerContentsCheck::registerMatchers(MatchFinder *Finder) {
+  auto isStdMove = callee(functionDecl(hasName("::std::move")));

PiotrZSL wrote:

You could also add '::std::forward' here with hasAnyName, as both would be 
invalid

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] Add bugprone-move-shared-pointer-contents check. (PR #67467)

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


@@ -368,8 +374,7 @@ Changes in existing checks
   ` check to avoid false positive 
when
   using pointer to member function. Additionally, the check no longer emits
   a diagnostic when a variable that is not type-dependent is an operand of a
-  type-dependent binary operator. Improved performance of the check through

PiotrZSL wrote:

revert this small change.

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] Add bugprone-move-shared-pointer-contents check. (PR #67467)

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


@@ -0,0 +1,19 @@
+.. title:: clang-tidy - bugprone-move-shared-pointer-contents
+
+bugprone-move-shared-pointer-contents
+=
+
+
+Detects calls to move the contents out of a ``std::shared_ptr`` rather
+than moving the pointer itself. In other words, calling
+``std::move(*p)`` or ``std::move(*p.get())``. Other reference holders
+may not be expecting the move and suddenly getting empty or otherwise
+indeterminate states can cause issues.
+

PiotrZSL wrote:

add info that check is restricted to C++11 and above.

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] Add bugprone-move-shared-pointer-contents check. (PR #67467)

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

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

@pizzud
To be honest I see this check being already done in 99%.
Please resolve some last nits, rebase code and we could merge it in this month.

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] Add bugprone-move-shared-pointer-contents check. (PR #67467)

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

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


[clang-tools-extra] [clang-tidy] Add readability-use-builtin-literals check (PR #76065)

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

PiotrZSL wrote:

@BenBlaise Clang-tidy 19 branch out is in ... a month. Any plans to finish this 
? It's fine if this would get in limited scope (only for explicit casts), but 
some current issues need fixes.

https://github.com/llvm/llvm-project/pull/76065
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -126,6 +126,11 @@ New checks
   reference. This may cause use-after-free errors if the caller uses xvalues as
   arguments.
 
+- New :doc:`bugprone-pointer-arithmetic-on-polymorphic-object

PiotrZSL wrote:

add in line 173 info about new alias (check release notes from previous release)

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,61 @@
+.. title:: clang-tidy - bugprone-pointer-arithmetic-on-polymorphic-object
+
+bugprone-pointer-arithmetic-on-polymorphic-object
+=
+
+Finds pointer arithmetic performed on classes that declare a virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is 
+different from its dynamic type is undefined behavior, as the two types can
+have different sizes.
+Finding pointers where the static type contains a virtual member function is a
+good heuristic, as the pointer is likely to point to a different, derived 
class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void ~Base();
+  };
+
+  struct Derived : public Base {};
+
+  void foo() {
+Base *b = new Derived[10];
+
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function,
+//  which can result in undefined behavior if the pointee is a
+//  different class
+
+delete[] static_cast(b);
+  }
+
+This check corresponds to the SEI Cert rule `CTR56-CPP: Do not use pointer 
arithmetic on polymorphic objects 
`_.

PiotrZSL wrote:

wrap this line,. move link to new line.

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,61 @@
+.. title:: clang-tidy - bugprone-pointer-arithmetic-on-polymorphic-object
+
+bugprone-pointer-arithmetic-on-polymorphic-object
+=
+
+Finds pointer arithmetic performed on classes that declare a virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is 
+different from its dynamic type is undefined behavior, as the two types can
+have different sizes.
+Finding pointers where the static type contains a virtual member function is a
+good heuristic, as the pointer is likely to point to a different, derived 
class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void ~Base();
+  };
+
+  struct Derived : public Base {};
+
+  void foo() {
+Base *b = new Derived[10];
+
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function,
+//  which can result in undefined behavior if the pointee is a
+//  different class
+
+delete[] static_cast(b);
+  }
+
+This check corresponds to the SEI Cert rule `CTR56-CPP: Do not use pointer 
arithmetic on polymorphic objects 
`_.
+
+Options
+---
+
+.. option:: MatchInheritedVirtualFunctions
+
+  When `true`, all classes with a virtual function are considered,

PiotrZSL wrote:

Maybe: "When `true`, all polymorphic classes are checked regardless if they add 
new virtual functions or not. Default value is `false`"

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,38 @@
+//===--- PointerArithmeticOnPolymorphicObjectCheck.h *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POINTERARITHMETICONPOLYMORPHICOBJECTCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_POINTERARITHMETICONPOLYMORPHICOBJECTCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// Finds pointer arithmetic performed on classes that declare a
+/// virtual function.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/pointer-arithmetic-on-polymorphic-object.html
+class PointerArithmeticOnPolymorphicObjectCheck : public ClangTidyCheck {
+public:
+  PointerArithmeticOnPolymorphicObjectCheck(StringRef Name,
+ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus;
+  }
+

PiotrZSL wrote:

Exclude implicit code with TK_IgnoreUnlessSpelledInSource here (look into other 
checks).

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,78 @@
+//===--- PointerArithmeticOnPolymorphicObjectCheck.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 "PointerArithmeticOnPolymorphicObjectCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isAbstract) { return Node.isAbstract(); }
+} // namespace
+
+PointerArithmeticOnPolymorphicObjectCheck::
+PointerArithmeticOnPolymorphicObjectCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  MatchInheritedVirtualFunctions(
+  Options.get("MatchInheritedVirtualFunctions", false)) {}
+
+void PointerArithmeticOnPolymorphicObjectCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "MatchInheritedVirtualFunctions", true);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers(
+MatchFinder *Finder) {
+  const auto PolymorphicPointerExpr =
+  expr(hasType(hasCanonicalType(
+   pointerType(pointee(hasCanonicalType(hasDeclaration(
+   cxxRecordDecl(unless(isFinal()),
+ cxxRecordDecl(hasMethod(isVirtual()))
+  .bind("pointer");
+
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(hasCanonicalType(pointerType(
+   pointee(hasCanonicalType(hasDeclaration(cxxRecordDecl(
+   unless(isFinal()),
+   anyOf(hasMethod(isVirtualAsWritten()), isAbstract())
+  .bind("pointer");

PiotrZSL wrote:

This doesn't make sense, simply IF type is derived with added new methods, then 
there will be no issues, as vtable will handle everything correctly, and even 
if operation would be done on base class everything will be fine.

Actually only issue will be if size of classes does not match, but that can 
happen whatever this is polymorphic object of not.

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,49 @@
+//===--- VirtualArithmeticCheck.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 "VirtualArithmeticCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void VirtualArithmeticCheck::registerMatchers(MatchFinder *Finder) {
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(pointerType(pointee(hasDeclaration(
+   cxxRecordDecl(hasMethod(isVirtualAsWritten(
+  .bind("pointer");

PiotrZSL wrote:

This should be default scenario, to detect all usage on polymorphic classes, 
and options should reduce scope.
I personally do not see use case for pointer arithmetic on such classes.

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,78 @@
+//===--- PointerArithmeticOnPolymorphicObjectCheck.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 "PointerArithmeticOnPolymorphicObjectCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isAbstract) { return Node.isAbstract(); }
+} // namespace
+
+PointerArithmeticOnPolymorphicObjectCheck::
+PointerArithmeticOnPolymorphicObjectCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  MatchInheritedVirtualFunctions(
+  Options.get("MatchInheritedVirtualFunctions", false)) {}
+
+void PointerArithmeticOnPolymorphicObjectCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "MatchInheritedVirtualFunctions", true);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers(
+MatchFinder *Finder) {
+  const auto PolymorphicPointerExpr =
+  expr(hasType(hasCanonicalType(
+   pointerType(pointee(hasCanonicalType(hasDeclaration(
+   cxxRecordDecl(unless(isFinal()),
+ cxxRecordDecl(hasMethod(isVirtual()))
+  .bind("pointer");
+
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(hasCanonicalType(pointerType(
+   pointee(hasCanonicalType(hasDeclaration(cxxRecordDecl(
+   unless(isFinal()),
+   anyOf(hasMethod(isVirtualAsWritten()), isAbstract())
+  .bind("pointer");
+
+  const auto SelectedPointerExpr = MatchInheritedVirtualFunctions
+   ? PolymorphicPointerExpr
+   : PointerExprWithVirtualMethod;
+
+  const auto ArraySubscript = arraySubscriptExpr(hasBase(SelectedPointerExpr));
+
+  const auto BinaryOperators =
+  binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="),
+ hasEitherOperand(SelectedPointerExpr));
+
+  const auto UnaryOperators = unaryOperator(
+  hasAnyOperatorName("++", "--"), hasUnaryOperand(SelectedPointerExpr));
+
+  Finder->addMatcher(
+  expr(anyOf(ArraySubscript, BinaryOperators, UnaryOperators)), this);

PiotrZSL wrote:

that's too generic, register each of those matchers separately.

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -126,6 +126,11 @@ New checks
   reference. This may cause use-after-free errors if the caller uses xvalues as
   arguments.
 
+- New :doc:`bugprone-pointer-arithmetic-on-polymorphic-object
+  ` check.
+
+  Finds pointer arithmetic performed on classes that declare a virtual 
function.

PiotrZSL wrote:

Change this description to point about polymorphic-object. Or instead of that 
declare (class does not declare anything), just say "that contain".

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,78 @@
+//===--- PointerArithmeticOnPolymorphicObjectCheck.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 "PointerArithmeticOnPolymorphicObjectCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isAbstract) { return Node.isAbstract(); }
+} // namespace
+
+PointerArithmeticOnPolymorphicObjectCheck::
+PointerArithmeticOnPolymorphicObjectCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  MatchInheritedVirtualFunctions(
+  Options.get("MatchInheritedVirtualFunctions", false)) {}
+
+void PointerArithmeticOnPolymorphicObjectCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "MatchInheritedVirtualFunctions", true);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers(
+MatchFinder *Finder) {
+  const auto PolymorphicPointerExpr =
+  expr(hasType(hasCanonicalType(
+   pointerType(pointee(hasCanonicalType(hasDeclaration(
+   cxxRecordDecl(unless(isFinal()),
+ cxxRecordDecl(hasMethod(isVirtual()))
+  .bind("pointer");
+
+  const auto PointerExprWithVirtualMethod =
+  expr(hasType(hasCanonicalType(pointerType(
+   pointee(hasCanonicalType(hasDeclaration(cxxRecordDecl(
+   unless(isFinal()),
+   anyOf(hasMethod(isVirtualAsWritten()), isAbstract())
+  .bind("pointer");
+
+  const auto SelectedPointerExpr = MatchInheritedVirtualFunctions
+   ? PolymorphicPointerExpr
+   : PointerExprWithVirtualMethod;
+
+  const auto ArraySubscript = arraySubscriptExpr(hasBase(SelectedPointerExpr));
+
+  const auto BinaryOperators =
+  binaryOperator(hasAnyOperatorName("+", "-", "+=", "-="),
+ hasEitherOperand(SelectedPointerExpr));
+
+  const auto UnaryOperators = unaryOperator(
+  hasAnyOperatorName("++", "--"), hasUnaryOperand(SelectedPointerExpr));
+
+  Finder->addMatcher(
+  expr(anyOf(ArraySubscript, BinaryOperators, UnaryOperators)), this);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *PointerExpr = Result.Nodes.getNodeAs("pointer");
+  const CXXRecordDecl *PointeeType =
+  PointerExpr->getType()->getPointeeType()->getAsCXXRecordDecl();

PiotrZSL wrote:

This may fail with typedefs, you already got cxxRecordDecl in matcher, just 
bind it to some name, like "Record"

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,78 @@
+//===--- PointerArithmeticOnPolymorphicObjectCheck.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 "PointerArithmeticOnPolymorphicObjectCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(CXXRecordDecl, isAbstract) { return Node.isAbstract(); }
+} // namespace
+
+PointerArithmeticOnPolymorphicObjectCheck::
+PointerArithmeticOnPolymorphicObjectCheck(StringRef Name,
+  ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  MatchInheritedVirtualFunctions(
+  Options.get("MatchInheritedVirtualFunctions", false)) {}
+
+void PointerArithmeticOnPolymorphicObjectCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "MatchInheritedVirtualFunctions", true);
+}
+
+void PointerArithmeticOnPolymorphicObjectCheck::registerMatchers(
+MatchFinder *Finder) {
+  const auto PolymorphicPointerExpr =
+  expr(hasType(hasCanonicalType(
+   pointerType(pointee(hasCanonicalType(hasDeclaration(
+   cxxRecordDecl(unless(isFinal()),
+ cxxRecordDecl(hasMethod(isVirtual()))

PiotrZSL wrote:

1. you dont need to repeat cxxRecordDecl.
2. Create custom AST matcher that utilize 
[isPolymorphic](https://clang.llvm.org/doxygen/classclang_1_1CXXRecordDecl.html#a6989371936079ccd01556c99637e9de0)
 ()

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,61 @@
+.. title:: clang-tidy - bugprone-pointer-arithmetic-on-polymorphic-object
+
+bugprone-pointer-arithmetic-on-polymorphic-object
+=
+
+Finds pointer arithmetic performed on classes that declare a virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is 
+different from its dynamic type is undefined behavior, as the two types can
+have different sizes.

PiotrZSL wrote:

"as the two types can have different sizes."
this apply also to non polymorphic classes.

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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


@@ -0,0 +1,61 @@
+.. title:: clang-tidy - bugprone-pointer-arithmetic-on-polymorphic-object
+
+bugprone-pointer-arithmetic-on-polymorphic-object
+=
+
+Finds pointer arithmetic performed on classes that declare a virtual function.
+
+Pointer arithmetic on polymorphic objects where the pointer's static type is 
+different from its dynamic type is undefined behavior, as the two types can
+have different sizes.
+Finding pointers where the static type contains a virtual member function is a
+good heuristic, as the pointer is likely to point to a different, derived 
class.
+
+Example:
+
+.. code-block:: c++
+
+  struct Base {
+virtual void ~Base();
+  };
+
+  struct Derived : public Base {};
+
+  void foo() {
+Base *b = new Derived[10];
+
+b += 1;
+// warning: pointer arithmetic on class that declares a virtual function,
+//  which can result in undefined behavior if the pointee is a
+//  different class
+
+delete[] static_cast(b);
+  }
+
+This check corresponds to the SEI Cert rule `CTR56-CPP: Do not use pointer 
arithmetic on polymorphic objects 
`_.
+
+Options
+---
+
+.. option:: MatchInheritedVirtualFunctions

PiotrZSL wrote:

this name and description is confusing.
Maybe name it like: IgnoreInheritedVirtualFunctions
Check should be default match all polymorphic classes, and then options could 
be just to reduce scope, like ignore classes with only virtual destructor, and 
so on.

https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/91951
___
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-pointer-arithmetic-on-polymorphic-object` check (PR #91951)

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

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

Few nits:
- storeOptions needs fix
- Consider excluding implicit code with TK_IgnoreUnlessSpelledInSource (not 
this may exclude also template instances, so I leave it up to you)
- Documentation require small work
- Make check more strict by default, and add options to relax it (as thats what 
[CTR56-CPP](https://wiki.sei.cmu.edu/confluence/display/cplusplus/CTR56-CPP.+Do+not+use+pointer+arithmetic+on+polymorphic+objects)
 require). I undestand that on your project this may cause some 
false-positives, but still thats your project problem. Consider adding options 
to "Allow classes where only virtual function is destructor", "Classes where 
all virtual functions are marked final",  "Classes that do not add new virtual 
functions or members". (Just check what suit your project most).

Note that next release branch out is in a ~month. Would be nice if this check 
could fit-in.

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


[clang-tools-extra] bc70c29 - [clang-tidy][DOC] Update doc for Clang Static Analyzer checks

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

Author: Piotr Zegar
Date: 2024-06-10T19:07:49Z
New Revision: bc70c29558c6ecb53e61cc8d668768e919e81bde

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

LOG: [clang-tidy][DOC] Update doc for Clang Static Analyzer checks

Fix gen-static-analyzer-docs.py script.
Commit doc for:
 - clang-analyzer-cplusplus.ArrayDelete
 - clang-analyzer-security.SetgidSetuidOrder
 - clang-analyzer-unix.Stream

Added: 

clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.ArrayDelete.rst

clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst
clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.Stream.rst

Modified: 
clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.ArrayDelete.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.ArrayDelete.rst
new file mode 100644
index 0..981476883
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/cplusplus.ArrayDelete.rst
@@ -0,0 +1,14 @@
+.. title:: clang-tidy - clang-analyzer-cplusplus.ArrayDelete
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#cplusplus-arraydelete
+
+clang-analyzer-cplusplus.ArrayDelete
+
+
+Reports destructions of arrays of polymorphic objects that are destructed as
+their base class.
+
+The `clang-analyzer-cplusplus.ArrayDelete` 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.SetgidSetuidOrder.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst
new file mode 100644
index 0..82f22b11f77fb
--- /dev/null
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/security.SetgidSetuidOrder.rst
@@ -0,0 +1,10 @@
+.. title:: clang-tidy - clang-analyzer-security.SetgidSetuidOrder
+
+clang-analyzer-security.SetgidSetuidOrder
+=
+
+Warn on possible reversed order of 'setgid(getgid()))' and 'setuid(getuid())'
+(CERT: POS36-C).
+
+The clang-analyzer-security.SetgidSetuidOrder check is an alias of
+Clang Static Analyzer security.SetgidSetuidOrder.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.Stream.rst 
b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.Stream.rst
new file mode 100644
index 0..82a8bdcaefce7
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/clang-analyzer/unix.Stream.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - clang-analyzer-unix.Stream
+.. meta::
+   :http-equiv=refresh: 
5;URL=https://clang.llvm.org/docs/analyzer/checkers.html#unix-stream
+
+clang-analyzer-unix.Stream
+==
+
+Check stream handling functions.
+
+The `clang-analyzer-unix.Stream` check is an alias, please see
+`Clang Static Analyzer Available Checkers
+`_
+for more information.

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py 
b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
index 8408ef5123ab3..fba1592c7c1c7 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
+++ b/clang-tools-extra/docs/clang-tidy/checks/gen-static-analyzer-docs.py
@@ -130,7 +130,7 @@ def generate_documentation(checker, has_documentation):
 def update_documentation_list(checkers):
 with open(os.path.join(__location__, "list.rst"), "r+") as f:
 f_text = f.read()
-check_text = f_text.split(".. csv-table:: Aliases..\n")[1]
+check_text = f_text.split(':header: "Name", "Redirect", "Offers 
fixes"\n')[1]
 checks = [x for x in check_text.split("\n") if ":header:" not in x and 
x]
 old_check_text = "\n".join(checks)
 checks = [x for x in checks if "clang-analyzer-" not in x]

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 87d3db20f7684..a698cecc0825c 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -443,6 +443,7 @@ Check aliases
:doc:`clang-analyzer-core.uninitialized.CapturedBlockVariable 
`, `Clang Static 
Analyzer core.uninitialized.CapturedBlockVariable 
`_,

[clang-tools-extra] fix(clang-tools-extra/**.py): fix invalid escape sequences (PR #94028)

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

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


[clang-tools-extra] fix(clang-tools-extra/**.py): fix invalid escape sequences (PR #94028)

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

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

LGTM,
I will merge this once I confirm that it still works.

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


[clang-tools-extra] fix(clang-tools-extra/**.py): fix comparison to None (PR #94013)

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

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


[clang-tools-extra] fix(clang-tools-extra/**.py): fix comparison to None (PR #94013)

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

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

LGTM

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

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

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

LGTM

https://github.com/llvm/llvm-project/pull/93827
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-10 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -292,11 +318,17 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult ) {
 diag(E->getBeginLoc(),
  "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
 << E->getSourceRange();
-  } else if (const auto *E =
- Result.Nodes.getNodeAs("sizeof-pointer-to-aggregate")) {
-diag(E->getBeginLoc(),
- "suspicious usage of 'sizeof(A*)'; pointer to aggregate")
-<< E->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-pointer")) {
+if (Result.Nodes.getNodeAs("struct-type")) {
+  diag(E->getBeginLoc(),
+   "suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did 
"
+   "you mean 'sizeof(A)'?")
+  << E->getSourceRange();
+} else {
+  diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
+ "that results in a pointer")

PiotrZSL wrote:

ok

https://github.com/llvm/llvm-project/pull/94356
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-10 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy ,
=?utf-8?q?Don=C3=A1t?= Nagy 
Message-ID:
In-Reply-To: 


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

Overall LGTM.
It doesn't look to break (by default) previous behavior, so it's fine.

https://github.com/llvm/llvm-project/pull/94356
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-10 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy ,
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/94356
___
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 false positives for the functions with the same name as standard library functions in misc-include-cleaner (PR #94923)

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

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

LGTM.

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


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

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

PiotrZSL wrote:

Yes, you can just submit new PR, reference this one.

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception&) {
+throw; // Good
+  }
+
+However, when an empty throw statement is used outside a catch block, it
+results in a call to ``std::terminate()``, which abruptly terminates the
+application. This behavior can lead to the abnormal termination of the
+program and is often unintended. Such occurrences may indicate errors or
+oversights in the exception handling logic, and it is essential to avoid empty
+throw statements outside catch blocks to prevent unintended program 
termination.
+
+.. code-block:: c++
+
+  void foo() {
+// std::terminate will be called because there is no exception to rethrow
+throw;
+  }
+
+  int main() {
+try {
+  foo();
+} catch(...) {
+  return 1;
+}
+return 0;
+  }
+
+The above program will be terminated with:
+
+.. code-block:: text
+
+  terminate called without an active exception
+  Aborted (core dumped)
+
+Check does not perform a call-flow analysis and may produce false positives in
+lambdas or functions that are actually called from a catch block. In such 
cases,
+it is recommended to suppress the warning using the ``NOLINT`` comment.

PiotrZSL wrote:

There is entire documentation about nolints in "Suppressing Undesired 
Diagnostics" section in main documentation. It's not being duplicated in 
pre-check doc.

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception&) {
+throw; // Good
+  }
+
+However, when an empty throw statement is used outside a catch block, it
+results in a call to ``std::terminate()``, which abruptly terminates the
+application. This behavior can lead to the abnormal termination of the
+program and is often unintended. Such occurrences may indicate errors or
+oversights in the exception handling logic, and it is essential to avoid empty
+throw statements outside catch blocks to prevent unintended program 
termination.
+
+.. code-block:: c++
+
+  void foo() {
+// std::terminate will be called because there is no exception to rethrow
+throw;
+  }
+
+  int main() {
+try {
+  foo();
+} catch(...) {
+  return 1;
+}
+return 0;
+  }
+
+The above program will be terminated with:
+
+.. code-block:: text
+
+  terminate called without an active exception
+  Aborted (core dumped)
+
+Check does not perform a call-flow analysis and may produce false positives in

PiotrZSL wrote:

Done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception&) {
+throw; // Good
+  }
+
+However, when an empty throw statement is used outside a catch block, it

PiotrZSL wrote:

Done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,83 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad, 'e' is copied
+  }
+
+.. code-block:: c++
+
+  class derived_exception : public std::exception { ... };
+
+  void throwDerived() { throw derived_exception{}; }
+
+  try {
+throwDerived();
+  } catch (const std::exception& e) {
+throw e; // Bad, exception slicing occurs when 'derived_exception' is
+ // being rethrown as 'std::exception'
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to

PiotrZSL wrote:

Done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,68 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto RefToExceptionVariable = 
declRefExpr(to(varDecl(isExceptionVariable(;
+  auto StdMoveCall =
+  callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),
+   hasArgument(0, RefToExceptionVariable));
+  auto CopyOrMoveConstruction = cxxConstructExpr(
+  argumentCountIs(1),
+  traverse(TK_AsIs, hasDeclaration(cxxConstructorDecl(
+anyOf(isCopyConstructor(), isMoveConstructor(),
+  hasArgument(0, anyOf(RefToExceptionVariable, StdMoveCall)));
+
+  auto HasEmptyThrowExprDescendant =
+  hasDescendant(cxxThrowExpr(equalsBoundNode("empty-throw")));
+
+  Finder->addMatcher(
+  cxxThrowExpr(
+  unless(isExpansionInSystemHeader()), unless(has(expr())),
+  expr().bind("empty-throw"),
+  anyOf(unless(hasAncestor(cxxCatchStmt())),
+hasAncestor(cxxCatchStmt(anyOf(
+hasDescendant(functionDecl(HasEmptyThrowExprDescendant)),
+
hasDescendant(lambdaExpr(HasEmptyThrowExprDescendant))),
+  this);
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   has(expr(anyOf(RefToExceptionVariable, StdMoveCall,
+  CopyOrMoveConstruction
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult ) {
+  if (const auto *MatchedThrow =
+  Result.Nodes.getNodeAs("throw")) {
+const Expr *ThrownObject = MatchedThrow->getSubExpr();
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  if (const auto *MatchedEmptyThrow =
+  Result.Nodes.getNodeAs("empty-throw")) {
+diag(MatchedEmptyThrow->getThrowLoc(),
+ "empty 'throw' outside a catch block with no operand triggers "

PiotrZSL wrote:

Done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits

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

>From 8ed57a657d9b87bfaaa5c4394fc3fcaf670ba94c Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 24 Mar 2024 18:39:54 +
Subject: [PATCH 1/7] [clang-tidy] Added bugprone-exception-rethrow check

Identifies problematic exception rethrowing, especially with caught
exception variables or empty throw statements outside catch blocks.

Closes #71292
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/ExceptionRethrowCheck.cpp| 50 ++
 .../bugprone/ExceptionRethrowCheck.h  | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../checks/bugprone/exception-rethrow.rst | 68 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/bugprone/exception-rethrow.cpp   | 60 
 8 files changed, 226 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-rethrow.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-rethrow.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 1b92d2e60cc17..7466d3f2e4fc2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "EasilySwappableParametersCheck.h"
 #include "EmptyCatchCheck.h"
 #include "ExceptionEscapeCheck.h"
+#include "ExceptionRethrowCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
@@ -127,6 +128,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck("bugprone-empty-catch");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
+CheckFactories.registerCheck(
+"bugprone-exception-rethrow");
 CheckFactories.registerCheck("bugprone-fold-init-type");
 CheckFactories.registerCheck(
 "bugprone-forward-declaration-namespace");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 2d303191f8865..345ae420398e6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModule
   EasilySwappableParametersCheck.cpp
   EmptyCatchCheck.cpp
   ExceptionEscapeCheck.cpp
+  ExceptionRethrowCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
new file mode 100644
index 0..4855ccc2724a9
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}
+} // namespace
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   anyOf(unless(has(expr())),
+ has(declRefExpr(to(varDecl(isExceptionVariable()),
+   optionally(hasAncestor(cxxCatchStmt().bind("catch"
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult ) {
+  const auto *MatchedThrow = Result.Nodes.getNodeAs("throw");
+
+  if (const Expr *ThrownObject = MatchedThrow->getSubExpr()) {
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  const bool HasCatchAnsestor =
+  Result.Nodes.getNodeAs("catch") != nullptr;
+  if (!HasCatchAnsestor) {
+diag(MatchedThrow->getThrowLoc(),
+ "empty 'throw' outside a catch block without an exception can trigger 
"
+ "'std::terminate'");
+  }
+}
+
+} 

[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,68 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto RefToExceptionVariable = 
declRefExpr(to(varDecl(isExceptionVariable(;
+  auto StdMoveCall =
+  callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),

PiotrZSL wrote:

That's not necessary. As other checks doesn't do that.

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-06-09 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,68 @@
+//===--- ExceptionRethrowCheck.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 "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto RefToExceptionVariable = 
declRefExpr(to(varDecl(isExceptionVariable(;
+  auto StdMoveCall =
+  callExpr(argumentCountIs(1), 
callee(functionDecl(hasName("::std::move"))),
+   hasArgument(0, RefToExceptionVariable));
+  auto CopyOrMoveConstruction = cxxConstructExpr(
+  argumentCountIs(1),

PiotrZSL wrote:

It's not redundant, it's cheaper to exclude first all calls that have more than 
1 argument, and then compare strings.

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


[clang-tools-extra] [clang-tidy] Improve bugprone-multi-level-implicit-pointer-conversion (PR #94524)

2024-06-09 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Extend modernize-use-designated-initializers with new options (PR #94651)

2024-06-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/94651
___
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 implicit functions in readability-implicit-bool-conversion (PR #94512)

2024-06-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/94512
___
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 non-math operators in readability-math-missing-parentheses (PR #94654)

2024-06-09 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/94654
___
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-06-08 Thread Piotr Zegar via cfe-commits

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

- Removed custom smart pointers handling (were hiding issues)
- Changed 'move occurred here' note location to always point to 'std::move'

Closes #90174


>From 1179f63d792da2462e1490c1b0a59cf1e6e47349 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sat, 8 Jun 2024 19:41:51 +
Subject: [PATCH 1/3] [clang-tidy] Fix smart pointers handling in
 bugprone-use-after-move

- Removed custom smart pointers handling (were hidding issues)
- Changed 'move occurred here' note location to always point to 'std::move'
- Fixed issue when 'std::move' of 'x' on initialization list would be
  incorrectly detected as use after move.

Closes #90174
---
 .../clang-tidy/bugprone/UseAfterMoveCheck.cpp |  39 +-
 .../checkers/bugprone/use-after-move.cpp  | 114 ++
 2 files changed, 95 insertions(+), 58 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index b91ad0f182295..593ed11d8ac43 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -215,26 +215,6 @@ void UseAfterMoveFinder::getUsesAndReinits(
   });
 }
 
-bool isStandardSmartPointer(const ValueDecl *VD) {
-  const Type *TheType = VD->getType().getNonReferenceType().getTypePtrOrNull();
-  if (!TheType)
-return false;
-
-  const CXXRecordDecl *RecordDecl = TheType->getAsCXXRecordDecl();
-  if (!RecordDecl)
-return false;
-
-  const IdentifierInfo *ID = RecordDecl->getIdentifier();
-  if (!ID)
-return false;
-
-  StringRef Name = ID->getName();
-  if (Name != "unique_ptr" && Name != "shared_ptr" && Name != "weak_ptr")
-return false;
-
-  return RecordDecl->getDeclContext()->isStdNamespace();
-}
-
 void UseAfterMoveFinder::getDeclRefs(
 const CFGBlock *Block, const Decl *MovedVariable,
 llvm::SmallPtrSetImpl *DeclRefs) {
@@ -248,13 +228,8 @@ 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())) {
-DeclRefs->insert(DeclRef);
-  }
+  DeclRefs->insert(DeclRef);
 }
   }
 };
@@ -265,11 +240,6 @@ void UseAfterMoveFinder::getDeclRefs(
 
 AddDeclRefs(match(traverse(TK_AsIs, findAll(DeclRefMatcher)), 
*S->getStmt(),
   *Context));
-AddDeclRefs(match(findAll(cxxOperatorCallExpr(
-  hasAnyOverloadedOperatorName("*", "->", 
"[]"),
-  hasArgument(0, DeclRefMatcher))
-  .bind("operator")),
-  *S->getStmt(), *Context));
   }
 }
 
@@ -411,10 +381,9 @@ void UseAfterMoveCheck::registerMatchers(MatchFinder 
*Finder) {
   auto TryEmplaceMatcher =
   cxxMemberCallExpr(callee(cxxMethodDecl(hasName("try_emplace";
   auto CallMoveMatcher =
-  callExpr(argumentCountIs(1),
+  callExpr(argumentCountIs(1), hasArgument(0, declRefExpr().bind("arg")),
callee(functionDecl(hasAnyName("::std::move", "::std::forward"))
   .bind("move-decl")),
-   hasArgument(0, declRefExpr().bind("arg")),
unless(inDecltypeOrTemplateArg()),
unless(hasParent(TryEmplaceMatcher)), expr().bind("call-move"),
anyOf(hasAncestor(compoundStmt(
@@ -464,7 +433,7 @@ void UseAfterMoveCheck::check(const 
MatchFinder::MatchResult ) {
   const auto *MoveDecl = Result.Nodes.getNodeAs("move-decl");
 
   if (!MovingCall || !MovingCall->getExprLoc().isValid())
-MovingCall = CallMove;
+MovingCall = ContainingCtorInit ? ContainingCtorInit : CallMove;
 
   // Ignore the std::move if the variable that was passed to it isn't a local
   // variable.
@@ -496,7 +465,7 @@ void UseAfterMoveCheck::check(const 
MatchFinder::MatchResult ) {
 UseAfterMoveFinder Finder(Result.Context);
 UseAfterMove Use;
 if (Finder.find(CodeBlock, MovingCall, Arg->getDecl(), ))
-  emitDiagnostic(MovingCall, Arg, Use, this, Result.Context,
+  emitDiagnostic(CallMove, Arg, Use, this, Result.Context,
  determineMoveType(MoveDecl));
   }
 }
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
index 7d9f63479a1b4..3d06dc008d353 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/use-after-move.cpp
+++ 

[clang-tools-extra] [clang-tidy] Ignore non-math operators in readability-math-missing-parentheses (PR #94654)

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

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

>From 5d37ba1925696582d752a45ceec605c8b6277543 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Thu, 6 Jun 2024 18:17:55 +
Subject: [PATCH] [clang-tidy] Ignore non-math operators in
 readability-math-missing-parentheses

Do not emit warnings for non-math operators.

Closes #92516
---
 .../readability/MathMissingParenthesesCheck.cpp |  3 ++-
 .../readability/math-missing-parentheses.cpp| 17 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index 65fd296094915..64ce94e3fc1db 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -57,7 +57,8 @@ static void addParantheses(const BinaryOperator *BinOp,
   int Precedence1 = getPrecedence(BinOp);
   int Precedence2 = getPrecedence(ParentBinOp);
 
-  if (ParentBinOp != nullptr && Precedence1 != Precedence2) {
+  if (ParentBinOp != nullptr && Precedence1 != Precedence2 && Precedence1 > 0 
&&
+  Precedence2 > 0) {
 const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
 const clang::SourceLocation EndLoc =
 clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
index a6045c079a482..4face0bb3fe68 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
@@ -140,3 +140,20 @@ void f(){
 //CHECK-MESSAGES: :[[@LINE+1]]:13: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
 int v = FUN5(0 + 1);
 }
+
+namespace PR92516 {
+  void f(int i) {
+int j, k;
+for (j = i + 1, k = 0; j < 1; ++j) {}
+  }
+
+  void f2(int i) {
+int j;
+for (j = i + 1; j < 1; ++j) {}
+  }
+
+  void f3(int i) {
+int j;
+for (j = i + 1, 2; j < 1; ++j) {}
+  }
+}

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


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

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

PiotrZSL wrote:

Check if you can commit to sebwolf-de:avoid-bounds-error-check

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


[clang-tools-extra] [clang-tidy] refactor misc-header-include-cycle (PR #94697)

2024-06-06 Thread Piotr Zegar via cfe-commits

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


https://github.com/llvm/llvm-project/pull/94697
___
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 non-math operators in readability-math-missing-parentheses (PR #94654)

2024-06-06 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

@11happy You may want to take a look.

https://github.com/llvm/llvm-project/pull/94654
___
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 non-math operators in readability-math-missing-parentheses (PR #94654)

2024-06-06 Thread Piotr Zegar via cfe-commits

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

Do not emit warnings for non-math operators.

Closes #92516

>From 034026add71cc0ec09e7cb715bffef38c5533233 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Thu, 6 Jun 2024 18:17:55 +
Subject: [PATCH] [clang-tidy] Ignore non-math operators in
 readability-math-missing-parentheses

Do not emit warnings for non-math operators.

Closes #92516
---
 .../readability/MathMissingParenthesesCheck.cpp |  3 ++-
 .../readability/math-missing-parentheses.cpp| 17 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
index 65fd296094915..64ce94e3fc1db 100644
--- a/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MathMissingParenthesesCheck.cpp
@@ -57,7 +57,8 @@ static void addParantheses(const BinaryOperator *BinOp,
   int Precedence1 = getPrecedence(BinOp);
   int Precedence2 = getPrecedence(ParentBinOp);
 
-  if (ParentBinOp != nullptr && Precedence1 != Precedence2) {
+  if (ParentBinOp != nullptr && Precedence1 != Precedence2 && Precedence1 > 0 
&&
+  Precedence2 > 0) {
 const clang::SourceLocation StartLoc = BinOp->getBeginLoc();
 const clang::SourceLocation EndLoc =
 clang::Lexer::getLocForEndOfToken(BinOp->getEndLoc(), 0, SM, LangOpts);
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
index a6045c079a482..4face0bb3fe68 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/math-missing-parentheses.cpp
@@ -140,3 +140,20 @@ void f(){
 //CHECK-MESSAGES: :[[@LINE+1]]:13: warning: '*' has higher precedence than 
'+'; add parentheses to explicitly specify the order of operations 
[readability-math-missing-parentheses]
 int v = FUN5(0 + 1);
 }
+
+namespace PR92516 {
+  void f(int i) {
+int j, k;
+for (j = i + 1, k = 0; j < 1; ++j) {}
+  }
+
+  void f2(int i) {
+int j;
+for (j = i + 1; j < 1; ++j) {}
+  }
+
+  void f3(int i) {
+int j;
+for (j = i + 1, 2; j < 1; ++j) {}
+  }
+}

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


[clang-tools-extra] [clang-tidy] Extend modernize-use-designated-initializers with new options (PR #94651)

2024-06-06 Thread Piotr Zegar via cfe-commits

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

Add StrictCStandardCompliance and StrictCppStandardCompliance options that 
default to true.

Closes #83732

>From 1f166251b629c1fd9dd2e5b8ac64ee5976ee0724 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Thu, 6 Jun 2024 18:09:29 +
Subject: [PATCH] [clang-tidy] Extend modernize-use-designated-initializers
 with new options

Add StrictCStandardCompliance and StrictCppStandardCompliance
options that default to true.

Closes #83732
---
 .../UseDesignatedInitializersCheck.cpp | 18 +-
 .../modernize/UseDesignatedInitializersCheck.h |  9 +
 .../modernize/use-designated-initializers.rst  | 12 +++-
 .../modernize/use-designated-initializers.cpp  |  8 
 4 files changed, 41 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
index ebc5338d0a7bf..2a0cc403b726e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp
@@ -32,6 +32,14 @@ static constexpr bool RestrictToPODTypesDefault = false;
 static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
 static constexpr bool IgnoreMacrosDefault = true;
 
+static constexpr char StrictCStandardComplianceName[] =
+"StrictCStandardCompliance";
+static constexpr bool StrictCStandardComplianceDefault = true;
+
+static constexpr char StrictCppStandardComplianceName[] =
+"StrictCppStandardCompliance";
+static constexpr bool StrictCppStandardComplianceDefault = true;
+
 namespace {
 
 struct Designators {
@@ -97,7 +105,12 @@ 
UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
   RestrictToPODTypes(
   Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
   IgnoreMacros(
-  Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+  Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)),
+  StrictCStandardCompliance(Options.get(StrictCStandardComplianceName,
+StrictCStandardComplianceDefault)),
+  StrictCppStandardCompliance(
+  Options.get(StrictCppStandardComplianceName,
+  StrictCppStandardComplianceDefault)) {}
 
 void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
   const auto HasBaseWithFields =
@@ -179,6 +192,9 @@ void UseDesignatedInitializersCheck::storeOptions(
 IgnoreSingleElementAggregates);
   Options.store(Opts, RestrictToPODTypesName, RestrictToPODTypes);
   Options.store(Opts, IgnoreMacrosName, IgnoreMacros);
+  Options.store(Opts, StrictCStandardComplianceName, 
StrictCStandardCompliance);
+  Options.store(Opts, StrictCppStandardComplianceName,
+StrictCppStandardCompliance);
 }
 
 } // namespace clang::tidy::modernize
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
index 0a496f51b9576..79095ade50371 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.h
@@ -29,10 +29,19 @@ class UseDesignatedInitializersCheck : public 
ClangTidyCheck {
 return TK_IgnoreUnlessSpelledInSource;
   }
 
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus20 || LangOpts.C99 ||
+   (LangOpts.CPlusPlus && !StrictCppStandardCompliance) ||
+   (!LangOpts.CPlusPlus && !LangOpts.ObjC &&
+!StrictCStandardCompliance);
+  }
+
 private:
   bool IgnoreSingleElementAggregates;
   bool RestrictToPODTypes;
   bool IgnoreMacros;
+  bool StrictCStandardCompliance;
+  bool StrictCppStandardCompliance;
 };
 
 } // namespace clang::tidy::modernize
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
index 22f50980baade..f101cfc6f3a2b 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst
@@ -37,7 +37,7 @@ declaration of ``S``.
 
 Even when compiling in a language version older than C++20, depending on your
 compiler, designated initializers are potentially supported. Therefore, the
-check is not restricted to C++20 and newer versions. Check out the options
+check is by default restricted to C99/C++20 and above. Check out the options
 ``-Wc99-designator`` to get support for mixed designators in initializer list 
in
 C and ``-Wc++20-designator`` for support of designated initializers in older 
C++
 language modes.
@@ -60,3 +60,13 @@ Options

[clang-tools-extra] [clang-tidy] Fix crash in readability-container-size-empty (PR #94527)

2024-06-06 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/94527
___
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 crashing when self include cycles for misc-header-include-cycle (PR #94636)

2024-06-06 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-06 Thread Piotr Zegar via cfe-commits


@@ -24,12 +24,28 @@ namespace {
 
 AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
 
-AST_MATCHER_P(Decl, isInMainFile, FileExtensionsSet, HeaderFileExtensions) {
+static bool isInMainFile(SourceLocation L, SourceManager ,
+ const FileExtensionsSet ) {
+  for (;;) {
+if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions))
+  return false;
+if (SM.isInMainFile(L))
+  return true;
+// not in header file but not in main file
+L = SM.getIncludeLoc(SM.getFileID(L));
+if (L.isValid())
+  continue;
+// Conservative about the unknown
+return false;
+  }
+}
+
+AST_MATCHER_P(Decl, isAllRedeclsInMainFile, FileExtensionsSet,
+  HeaderFileExtensions) {
   return llvm::all_of(Node.redecls(), [&](const Decl *D) {
-SourceManager  = Finder->getASTContext().getSourceManager();
-const SourceLocation L = D->getLocation();
-return SM.isInMainFile(L) &&
-   !utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions);
+return isInMainFile(D->getLocation(),
+Finder->getASTContext().getSourceManager(),
+HeaderFileExtensions);

PiotrZSL wrote:

Still I would just assume that if first declaration isn't in header file, then 
such declaration could be considered to be internal. As include for header 
should be there anyway.

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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-06 Thread Piotr Zegar via cfe-commits


@@ -24,12 +24,28 @@ namespace {
 
 AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
 
-AST_MATCHER_P(Decl, isInMainFile, FileExtensionsSet, HeaderFileExtensions) {
+static bool isInMainFile(SourceLocation L, SourceManager ,
+ const FileExtensionsSet ) {
+  for (;;) {
+if (utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions))
+  return false;
+if (SM.isInMainFile(L))
+  return true;
+// not in header file but not in main file
+L = SM.getIncludeLoc(SM.getFileID(L));
+if (L.isValid())
+  continue;
+// Conservative about the unknown
+return false;
+  }
+}
+
+AST_MATCHER_P(Decl, isAllRedeclsInMainFile, FileExtensionsSet,
+  HeaderFileExtensions) {
   return llvm::all_of(Node.redecls(), [&](const Decl *D) {
-SourceManager  = Finder->getASTContext().getSourceManager();
-const SourceLocation L = D->getLocation();
-return SM.isInMainFile(L) &&
-   !utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions);
+return isInMainFile(D->getLocation(),
+Finder->getASTContext().getSourceManager(),
+HeaderFileExtensions);

PiotrZSL wrote:

this isn't needed.
All you need to do is just get location and:
```
return SM.isInMainFile(L) ||  !utils::isSpellingLocInHeaderFile(L, SM, 
HeaderFileExtensions);
```

Or better add: isSpellingLocInSourceFile

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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-06 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-06 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,78 @@
+//===--- UseInternalLinkageCheck.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 "UseInternalLinkageCheck.h"
+#include "../utils/FileExtensionsUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+
+AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
+
+AST_MATCHER_P(Decl, isInMainFile, FileExtensionsSet, HeaderFileExtensions) {
+  return llvm::all_of(Node.redecls(), [&](const Decl *D) {
+SourceManager  = Finder->getASTContext().getSourceManager();
+const SourceLocation L = D->getLocation();
+return SM.isInMainFile(L) &&
+   !utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions);
+  });

PiotrZSL wrote:

No need to do recursive, using (current) first declaration should also work.

https://github.com/llvm/llvm-project/pull/90830
___
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 readability-container-size-empty (PR #94527)

2024-06-05 Thread Piotr Zegar via cfe-commits

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

Fixed crash caused by call to getCookedLiteral on
template user defined literal. Fix base on assert in getCookedLiteral method.

Closes #94454

>From a19a71fdf5e421c6b79fc3d6ecf7212b090b13a1 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 5 Jun 2024 19:38:18 +
Subject: [PATCH] [clang-tidy] Fix crash in readability-container-size-empty

Fixed crash caused by call to getCookedLiteral on
template user defined literal. Fix base on assert in
getCookedLiteral method.

Closes #94454
---
 .../clang-tidy/readability/ContainerSizeEmptyCheck.cpp   | 9 +++--
 clang-tools-extra/docs/ReleaseNotes.rst  | 1 +
 .../checkers/readability/container-size-empty.cpp| 6 ++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
index bbc1b47b97ae6..bf7a847dff103 100644
--- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp
@@ -96,9 +96,14 @@ AST_MATCHER(QualType, isIntegralType) {
 
 AST_MATCHER_P(UserDefinedLiteral, hasLiteral,
   clang::ast_matchers::internal::Matcher, InnerMatcher) {
-  if (const Expr *CookedLiteral = Node.getCookedLiteral()) {
+  const UserDefinedLiteral::LiteralOperatorKind LOK =
+  Node.getLiteralOperatorKind();
+  if (LOK == UserDefinedLiteral::LOK_Template ||
+  LOK == UserDefinedLiteral::LOK_Raw)
+return false;
+
+  if (const Expr *CookedLiteral = Node.getCookedLiteral())
 return InnerMatcher.matches(*CookedLiteral, Finder, Builder);
-  }
   return false;
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6947cf06f6e56..661b2b1620d0b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -376,6 +376,7 @@ Changes in existing checks
 - Improved :doc:`readability-container-size-empty
   ` check to prevent false
   positives when utilizing ``size`` or ``length`` methods that accept 
parameter.
+  Fixed crash when facing template user defined literals.
 
 - Improved :doc:`readability-duplicate-include
   ` check by excluding include
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
index ecaf97fa348cc..46755270b48ea 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/container-size-empty.cpp
@@ -889,3 +889,9 @@ namespace PR88203 {
 // CHECK-FIXES: {{^}}if (s.empty()) {}{{$}}
   }
 }
+
+namespace PR94454 {
+  template 
+  int operator""_ci() { return 0; }
+  auto eq = 0_ci == 0;
+}

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


[clang-tools-extra] [clang-tidy] Improve bugprone-multi-level-implicit-pointer-conversion (PR #94524)

2024-06-05 Thread Piotr Zegar via cfe-commits

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

Ignore implicit pointer conversions that are part of a cast expression

Closes #93959

>From bdff94eb18212005d059a5cbb8d649a356fdd301 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 5 Jun 2024 19:19:38 +
Subject: [PATCH] [clang-tidy] Improve
 bugprone-multi-level-implicit-pointer-conversion

Ignore implicit pointer conversions that are part of a cast expression

Closes #93959
---
 .../MultiLevelImplicitPointerConversionCheck.cpp | 11 ++-
 clang-tools-extra/docs/ReleaseNotes.rst  |  4 
 .../multi-level-implicit-pointer-conversion.cpp  | 12 
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
 
b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
index 4dd3cb57e6dd1..7a989b07119aa 100644
--- 
a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
@@ -48,12 +48,21 @@ AST_MATCHER(ImplicitCastExpr, 
isMultiLevelPointerConversion) {
   return SourcePtrLevel != TargetPtrLevel;
 }
 
+AST_MATCHER(QualType, isPointerType) {
+  const QualType Type =
+  Node.getCanonicalType().getNonReferenceType().getUnqualifiedType();
+
+  return !Type.isNull() && Type->isPointerType();
+}
+
 } // namespace
 
 void MultiLevelImplicitPointerConversionCheck::registerMatchers(
 MatchFinder *Finder) {
   Finder->addMatcher(
-  implicitCastExpr(hasCastKind(CK_BitCast), 
isMultiLevelPointerConversion())
+  implicitCastExpr(hasCastKind(CK_BitCast), 
isMultiLevelPointerConversion(),
+   unless(hasParent(explicitCastExpr(
+   hasDestinationType(isPointerType())
   .bind("expr"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6947cf06f6e56..d1e0543a513a5 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -218,6 +218,10 @@ Changes in existing checks
   check by ignoring ``__func__`` macro in lambda captures, initializers of
   default parameters and nested function declarations.
 
+- Improved :doc:`bugprone-multi-level-implicit-pointer-conversion
+  ` check
+  by ignoring implicit pointer conversions that are part of a cast expression.
+
 - Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
   ` check by
   eliminating false positives resulting from direct usage of bitwise operators
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
index 7a56242e4202d..6868f9e590908 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/multi-level-implicit-pointer-conversion.cpp
@@ -63,3 +63,15 @@ void test()
 
   takeSecondLevelVoidPtr(getSecondLevelVoidPtr());
 }
+
+namespace PR93959 {
+  void free(void*);
+
+  void test() {
+char **p = nullptr;
+free(p);
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: multilevel pointer conversion 
from 'char **' to 'void *', please use explicit cast 
[bugprone-multi-level-implicit-pointer-conversion]
+free((void *)p);
+free(static_cast(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] Fix handling of members in readability-redundant-member-init (PR #93217)

2024-06-05 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/93217
___
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 implicit functions in readability-implicit-bool-conversion (PR #94512)

2024-06-05 Thread Piotr Zegar via cfe-commits

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

Ignore implicit declarations and defaulted functions. Helps with issues in 
generated code like, C++
spaceship operator.

Closes #93409

>From 22cd99f5288f53eb561a3040ce78c5143a9a7dad Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 5 Jun 2024 17:40:18 +
Subject: [PATCH] [clang-tidy] Ignore implicit functions in
 readability-implicit-bool-conversion

Ignore implicit declarations and defaulted functions.
Helps with issues in generated code like, C++
spaceship operator.

Closes #93409
---
 .../ImplicitBoolConversionCheck.cpp   |  7 +++--
 clang-tools-extra/docs/ReleaseNotes.rst   |  3 +-
 .../implicit-bool-conversion-cxx20.cpp| 31 +++
 3 files changed, 38 insertions(+), 3 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 28f5eada6d825..aa115cd450c4f 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -279,6 +279,9 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   hasParent(callExpr()),
   hasSourceExpression(binaryOperator(hasAnyOperatorName("==", "!=";
 
+  auto IsInCompilerGeneratedFunction = hasAncestor(namedDecl(anyOf(
+  isImplicit(), functionDecl(isDefaulted()), functionTemplateDecl(;
+
   Finder->addMatcher(
   traverse(TK_AsIs,
implicitCastExpr(
@@ -299,7 +302,7 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
// additional parens in replacement.
optionally(hasParent(stmt().bind("parentStmt"))),
unless(isInTemplateInstantiation()),
-   unless(hasAncestor(functionTemplateDecl(
+   unless(IsInCompilerGeneratedFunction))
.bind("implicitCastToBool")),
   this);
 
@@ -331,7 +334,7 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
   anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
 anything()),
   unless(isInTemplateInstantiation()),
-  unless(hasAncestor(functionTemplateDecl(),
+  unless(IsInCompilerGeneratedFunction))),
   this);
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 33b65caf2b02c..6e2344de3e09f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -397,7 +397,8 @@ Changes in existing checks
   valid fix suggestions for ``static_cast`` without a preceding space and
   fixed problem with duplicate parentheses in double implicit casts. Corrected
   the fix suggestions for C23 and later by using C-style casts instead of
-  ``static_cast``.
+  ``static_cast``. Fixed false positives in C++20 spaceship operator by 
ignoring
+  casts in implicit and defaulted functions.
 
 - Improved :doc:`readability-redundant-inline-specifier
   ` check to properly
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp
new file mode 100644
index 0..13aa5c5774b47
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-cxx20.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy -std=c++20 %s readability-implicit-bool-conversion %t
+
+namespace std {
+struct strong_ordering {
+  int n;
+  constexpr operator int() const { return n; }
+  static const strong_ordering equal, greater, less;
+};
+constexpr strong_ordering strong_ordering::equal = {0};
+constexpr strong_ordering strong_ordering::greater = {1};
+constexpr strong_ordering strong_ordering::less = {-1};
+} // namespace std
+
+namespace PR93409 {
+  struct X
+  {
+  auto operator<=>(const X&) const = default;
+  bool m_b;
+  };
+
+  struct Y
+  {
+  auto operator<=>(const Y&) const = default;
+  X m_x;
+  };
+  
+  bool compare(const Y& y1, const Y& y2)
+  {
+ return y1 == y2 || y1 < y2 || y1 > y2;
+  }
+}

___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-05 Thread Piotr Zegar via cfe-commits


@@ -193,3 +193,8 @@ Options
When `true`, the check will warn on an expression like
``sizeof(expr)`` where the expression is a pointer
to aggregate. Default is `true`.
+
+.. option:: WarnOnSizeOfPointer
+
+   When `true`, the check will warn on an expression like ``sizeof(expr)``
+   where the expression is a pointer. Default is `false`.

PiotrZSL wrote:

expression type is a pointer

https://github.com/llvm/llvm-project/pull/94356
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-05 Thread Piotr Zegar via cfe-commits


@@ -292,11 +318,17 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult ) {
 diag(E->getBeginLoc(),
  "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
 << E->getSourceRange();
-  } else if (const auto *E =
- Result.Nodes.getNodeAs("sizeof-pointer-to-aggregate")) {
-diag(E->getBeginLoc(),
- "suspicious usage of 'sizeof(A*)'; pointer to aggregate")
-<< E->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-pointer")) {
+if (Result.Nodes.getNodeAs("struct-type")) {
+  diag(E->getBeginLoc(),
+   "suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did 
"
+   "you mean 'sizeof(A)'?")
+  << E->getSourceRange();
+} else {
+  diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
+ "that results in a pointer")

PiotrZSL wrote:

maybe : "suspicious use of 'sizeof()' on an expression of pointer type" or even 
"suspicious use of 'sizeof()' on a pointer type resulting from an expression"

https://github.com/llvm/llvm-project/pull/94356
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-05 Thread Piotr Zegar via cfe-commits

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

+- LGTM, except nits.

https://github.com/llvm/llvm-project/pull/94356
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-05 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL edited 
https://github.com/llvm/llvm-project/pull/94356
___
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 WarnOnSizeOfPointer mode to bugprone-sizeof-expression (PR #94356)

2024-06-05 Thread Piotr Zegar via cfe-commits


@@ -193,3 +193,8 @@ Options
When `true`, the check will warn on an expression like
``sizeof(expr)`` where the expression is a pointer
to aggregate. Default is `true`.
+
+.. option:: WarnOnSizeOfPointer
+
+   When `true`, the check will warn on an expression like ``sizeof(expr)``
+   where the expression is a pointer. Default is `false`.

PiotrZSL wrote:

You could mention here that CWE.

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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-05 Thread Piotr Zegar via cfe-commits

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

I accept this change as it's fine for 1.0 version
Any fixed can be always done in this or new change.

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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-05 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,78 @@
+//===--- UseInternalLinkageCheck.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 "UseInternalLinkageCheck.h"
+#include "../utils/FileExtensionsUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+
+AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
+
+AST_MATCHER_P(Decl, isInMainFile, FileExtensionsSet, HeaderFileExtensions) {
+  return llvm::all_of(Node.redecls(), [&](const Decl *D) {
+SourceManager  = Finder->getASTContext().getSourceManager();
+const SourceLocation L = D->getLocation();
+return SM.isInMainFile(L) &&
+   !utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions);
+  });

PiotrZSL wrote:

yes, that FirstDecl stuff will work. just note that we got config for header 
extensions and source extensions. better would be to use source. as those .inc 
could be part of header files also.

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


[clang-tools-extra] [clang-tidy] new check misc-use-internal-linkage (PR #90830)

2024-06-04 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,78 @@
+//===--- UseInternalLinkageCheck.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 "UseInternalLinkageCheck.h"
+#include "../utils/FileExtensionsUtils.h"
+#include "clang/AST/Decl.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/STLExtras.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+
+AST_MATCHER(Decl, isFirstDecl) { return Node.isFirstDecl(); }
+
+AST_MATCHER_P(Decl, isInMainFile, FileExtensionsSet, HeaderFileExtensions) {
+  return llvm::all_of(Node.redecls(), [&](const Decl *D) {
+SourceManager  = Finder->getASTContext().getSourceManager();
+const SourceLocation L = D->getLocation();
+return SM.isInMainFile(L) &&
+   !utils::isSpellingLocInHeaderFile(L, SM, HeaderFileExtensions);
+  });

PiotrZSL wrote:

simply .cpp (source files) files included from main file should be treated like 
main file.

https://github.com/llvm/llvm-project/pull/90830
___
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 assert in modernize-use-std-format/print (PR #94104)

2024-06-03 Thread Piotr Zegar via cfe-commits

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

2024-06-03 Thread Piotr Zegar via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/94104
___
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 assert in modernize-use-std-format/print (PR #94104)

2024-06-03 Thread Piotr Zegar via cfe-commits


@@ -351,6 +351,10 @@ Changes in existing checks
   ` check to also handle
   calls to ``compare`` method.
 
+- Improved :doc:`modernize-use-std-format` and

PiotrZSL wrote:

remove modernize-use-std-format from here, as it's new check, only leave 
std-print

https://github.com/llvm/llvm-project/pull/94104
___
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 assert in modernize-use-std-format/print (PR #94104)

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

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

Overall LGTM, consider adding release note entry for modernize-use-std-print 
(as it were added in previous release)

https://github.com/llvm/llvm-project/pull/94104
___
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 assert in modernize-use-std-format/print (PR #94104)

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


@@ -20,6 +20,11 @@ namespace clang::tidy::modernize {
 
 namespace {
 AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+AST_MATCHER(QualType, isSimpleChar) {
+  const auto ActualType = Node.getTypePtr();
+  return ActualType->isSpecificBuiltinType(BuiltinType::Char_S) ||

PiotrZSL wrote:

Note: you ay also verify that ActualType is not null

https://github.com/llvm/llvm-project/pull/94104
___
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 assert in modernize-use-std-format/print (PR #94104)

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


@@ -20,6 +20,11 @@ namespace clang::tidy::modernize {
 
 namespace {
 AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+AST_MATCHER(QualType, isSimpleChar) {
+  const auto ActualType = Node.getTypePtr();
+  return ActualType->isSpecificBuiltinType(BuiltinType::Char_S) ||
+ ActualType->isSpecificBuiltinType(BuiltinType::Char_U);
+}

PiotrZSL wrote:

consider moving this to some exist file in utils directory

https://github.com/llvm/llvm-project/pull/94104
___
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 assert in modernize-use-std-format/print (PR #94104)

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

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

2024-05-30 Thread Piotr Zegar via cfe-commits


@@ -41,3 +41,25 @@ The variables ``a``, ``c``, ``c_ptr1``, ``c_const_ptr`` and 
``c_reference``
 will all generate warnings since they are either a non-const globally 
accessible
 variable, a pointer or a reference providing global access to non-const data
 or both.
+
+Options
+---
+
+.. option:: AllowAnonymousNamespace
+
+   When set to `true` (default is `false`), non-const variables in anonymous 
namespaces will not generate a warning.
+
+Example
+^^^
+
+.. code-block:: c++
+
+   namespace {
+ int counter = 0;
+   }
+
+   int Increment() {
+return ++counter;
+   }
+
+will not generate a warning for `counter` if :option:`AllowAnonymousNamespace` 
is set to `true`.

PiotrZSL wrote:

I dont think that this example is needed. Check option already says a lot.

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

2024-05-30 Thread Piotr Zegar via cfe-commits


@@ -41,3 +41,25 @@ The variables ``a``, ``c``, ``c_ptr1``, ``c_const_ptr`` and 
``c_reference``
 will all generate warnings since they are either a non-const globally 
accessible
 variable, a pointer or a reference providing global access to non-const data
 or both.
+
+Options
+---
+
+.. option:: AllowAnonymousNamespace
+
+   When set to `true` (default is `false`), non-const variables in anonymous 
namespaces will not generate a warning.

PiotrZSL wrote:

wrap on 80 column

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

2024-05-30 Thread Piotr Zegar via cfe-commits


@@ -1,29 +1,39 @@
-// RUN: %check_clang_tidy %s 
cppcoreguidelines-avoid-non-const-global-variables %t
+// RUN: %check_clang_tidy %s -check-suffix=DEFAULT 
cppcoreguidelines-avoid-non-const-global-variables %t
+// RUN: %check_clang_tidy %s -check-suffix=NAMESPACE 
cppcoreguidelines-avoid-non-const-global-variables %t -- \

PiotrZSL wrote:

use -check-suffixes=,NAMESPACE instead of duplicating all CHECK-MESSGAES or 
adding DEFAULT

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

2024-05-30 Thread Piotr Zegar via cfe-commits


@@ -16,9 +15,12 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::cppcoreguidelines {
 
 void AvoidNonConstGlobalVariablesCheck::registerMatchers(MatchFinder *Finder) {
+  auto NamespaceMatcher = Options.get("AllowAnonymousNamespace", false)

PiotrZSL wrote:

Options.get should be called from constructor and saved into class member.
storeOption is missing or not updated.

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

2024-05-30 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Option to ignore anonymous namespaces in avoid-non-const-global-variables (PR #93827)

2024-05-30 Thread Piotr Zegar via cfe-commits

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

- storeOptions is missing
- release notes need to be updated about added new option
- tests need some love (reduce amount of changes)
- what about "static" non const global variables 

I'm fine for having an options that control behavior of the check.
But please note that there are other aspects of "I.2: Avoid non-const global 
variables" rule that anonymous namespace or static does not solve. Like 
race-conditions in multithread env. Or even to force developer not to use 
global objects to pass data between functions.

Even that I see many times that warnings from this check are being nolinted, I 
still think that it's doing good job.

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


[clang-tools-extra] [clang-tidy] Check number of arguments to size/length in readability-container-size-empty (PR #93724)

2024-05-30 Thread Piotr Zegar via cfe-commits

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