247 Commits

Author SHA1 Message Date
Piotr Zegar
cbdc3e1bf9 [clang-tidy][NFC] Fix cppcoreguidelines-init-variables findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:03 +00:00
Piotr Zegar
26078f33bd [clang-tidy][NFC] Fix cppcoreguidelines-missing-std-forward findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:03 +00:00
Piotr Zegar
01c8bf6fd4 [clang-tidy][NFC] Fix llvm-else-after-return findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:02 +00:00
Piotr Zegar
fc2a9ad10e [clang-tidy][NFC] Fix modernize-use-auto findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 11:59:02 +00:00
Piotr Zegar
24a7587b79 [clang-tidy][NFC] Fix readability-make-member-function-const findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:11 +00:00
Piotr Zegar
ec5f4be452 [clang-tidy][NFC] Fix modernize-return-braced-init-list findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:10 +00:00
Piotr Zegar
c5a4f29ef0 [clang-tidy][NFC] Fix readability-container-size-empty findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:10 +00:00
Piotr Zegar
f1f16331bd [clang-tidy][NFC] Fix readability-inconsistent-declaration-parameter-name findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-27 08:52:09 +00:00
Jorge Pinto Sousa
41818ce150 [clang-tidy] Access checks not done classes derived of std::array
Index accessing checks are not performed for derived classes of
of `std::array`, as only `std::array` itself and its aliases
seems to be checked.

This patch aims to extend it for derived classes such as:
```
template<class T, size_t N>
class DerivedArray : public std::array<T, N> {};
```

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D156624
2023-08-25 17:09:04 +00:00
Piotr Zegar
0e2c5cda3c [clang-tidy] Improve cppcoreguidelines-avoid-reference-coroutine-parameters check
Ignore false positives related to matching parameters of non
coroutine functions and increase issue detection for cases
involving type aliases with references.

Fixes: #64915

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D158665
2023-08-24 21:49:28 +00:00
Congcong Cai
9be33de4f3 [clang-tidy]pro-bounds-array-to-pointer-decay ignore predefined expression
cast PredefinedExpr such as `__func__` to const char* should be accpetted.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D158244
2023-08-19 08:13:00 +08:00
Chris Cotter
a563ced78b [clang-tidy] Implement cppcoreguidelines CP.52
Flag code that suspends a coroutine while a lock is held.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D157057
2023-08-11 07:13:59 +00:00
Piotr Zegar
894140b4fd [clang-tidy] Ignore delegate constructors in cppcoreguidelines-pro-type-member-init
Ignore dependend delegate constructors.

Fixes: #37250

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D157367
2023-08-10 19:51:09 +00:00
Piotr Zegar
7f29f14d02 [clang-tidy] Ignore unevaluated context in cppcoreguidelines-pro-type-vararg
Ignore decltype, sizeof, alignof in this check.

Fixes: #30542

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D157376
2023-08-10 19:51:09 +00:00
Piotr Zegar
7899d2aa66 [clang-tidy][NFC] Remove trailing whitespaces from ProTypeVarargCheck
Just a whitespace cleanup.
2023-08-08 08:56:41 +00:00
Piotr Zegar
7a4b12e39b
[clang-tidy] Exclude delegate constructors in cppcoreguidelines-prefer-member-initializer
As proposed by check fix would result in compilation error,
lets exclude delegate constructors from being checked.

Fixes: #52818

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D157242
2023-08-07 06:08:39 +00:00
Piotr Zegar
b3700c34aa [clang-tidy] Re-add cppcoreguidelines-macro-to-enum alias
Looks like somewere in clang-16 this alias were removed,
even that is mention in clang-tidy 15 release notes.

Fixes: #64342

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D157181
2023-08-06 08:09:57 +00:00
Piotr Zegar
3e2ed5701b [clang-tidy] Exclude class/struct scope variables from cppcoreguidelines-avoid-non-const-global-variables
Ignore static variables declared within the scope of class/struct.
Those variables should be covered by I.3 rule.

Fixes: #47384

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D157180
2023-08-05 16:47:49 +00:00
Jon Roelofs
2fb1c1082c
cmake: add missing dependencies on ClangDriverOptions tablegen
The modules build trips over this frequently because there is no textual
include of the tablegen output, but the module includes it.

Differential revision: https://reviews.llvm.org/D157119
2023-08-04 10:27:19 -07:00
Piotr Zegar
5b5b75bfd4 [clang-tidy] Ignore implcit casts in cppcoreguidelines-owning-memory
Add getCheckTraversalKind to the check in order
to ignore some implicit casts when matching
expresions.

Fixes: #63994

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D156031
2023-07-22 19:24:54 +00:00
Carlos Galvez
b70e6e9681 [clang-tidy] Warn only for copyable/movable classes in cppcoreguidelines-avoid-const-or-ref-members
Since that's what the guidelines require.

Fixes #63733

Differential Revision: https://reviews.llvm.org/D155625
2023-07-19 12:05:15 +00:00
Jorge Pinto Sousa
ce2d44b0ab [clang-tidy] Accessing checks not done for aliases of std::array
Index accessing checks are not performed for aliases
of `std::array`, as only `std::array` itself seems to be checked.

This patch aims to extend it for aliases such as:
 `using MyArray = std::array<int, 10>;`

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D154297
2023-07-03 16:43:08 +00:00
Nemanja Ivanovic
ffd7a200fd [clang-tidy] Fix build bot break after 474a2b9367ad
The commmit added clang-tidy checks without adding
the required library to the link step.
Caused failures with shared library builds.
2023-06-14 06:47:34 -05:00
AMS21
474a2b9367 [clang-tidy] Add more checks for functions which should be noexcept
Added new checks
- `performance-noexcept-destructor`
- `performance-noexcept-swap`

Also added cppcoreguidlines aliases for the 2 new checks as well as `performance-noexcept-move-constructor`

This fixes llvm#62154

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D148697
2023-06-13 18:56:57 +00:00
Chris Cotter
5902bb9584 [clang-tidy] Implement cppcoreguidelines F.19
Warns when a function accepting a forwarding reference does anything besides
forwarding (with std::forward) the parameter in the body of the function.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D146921
2023-05-06 10:49:23 +00:00
Carlos Galvez
b507bda455 [clang-tidy] Add alias cppcoreguidelines-use-default-member-init
And deprecate identical functionality from
cppcoreguidelines-prefer-member-initializer, which had too many
responsibilities and a tight coupling to the
modernize-use-default-member-init check.

Fixes https://github.com/llvm/llvm-project/issues/62164.

Differential Revision: https://reviews.llvm.org/D148460
2023-04-17 06:09:59 +00:00
Piotr Zegar
b34ca0851a [clang-tidy] Fix handling of UseAssignment option in cppcoreguidelines-prefer-member-initializer
From now on check will use value from cppcoreguidelines-prefer-member-initializer
and fallback to modernize-use-default-member-init.UseAssignment if not specified.

Fixes: #55616.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D147929
2023-04-16 10:34:48 +00:00
Nathan James
4530c3bc48 [clang-tidy] Fix cppcoreguidelines-narrowing-conversions false positive
Fix https://llvm.org/PR49498.
The check notices 2 sides of a conditional operator have types with a different constness and so tries to examine the implicit cast.
As one side is infinity, the float narrowing detection sees when its casted to a double(which it already was) it thinks the result is out of range.

I've fixed this by just disregarding expressions where the builtin type(without quals) match as no conversion would take place.

However this has opened a can of worms. Currenty `float a = std::numeric_limits<double>::infinity();` is marked as narrowing.
Whats more suspicious is `double a = std::numeric_limits<float>::infinity();` is also marked as narrowing.
It could be argued `double inf -> float inf` is narrowing, but `float inf -> double inf` definitely isnt.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D98416
2023-04-15 15:07:44 +00:00
Carlos Galvez
d69c362dfd [clang-tidy][NFC] Fix format of header file comment in MisleadingCaptureDefaultByValueCheck.h 2023-04-15 14:49:20 +00:00
Carlos Galvez
fa3de2ed29 [clang-tidy][NFC] Improve doc of cppcoreguidelines-misleading-capture-default-by-value
Also fix ordering in Release Notes.

Differential Revision: https://reviews.llvm.org/D148424
2023-04-15 12:07:18 +00:00
Carlos Galvez
eedbe81b1c [clang-tidy] Apply cppcoreguidelines-avoid-capture-default-when-capturin-this only to by-value capture default
Since Cpp Core Guidelines have accepted the change in the rules:
3c90d590e1

Also rename the check accordingly.

Differential Revision: https://reviews.llvm.org/D148340
2023-04-15 10:10:04 +00:00
Nathan James
df0c8f2514
[clang-tidy][NFC] Remove redundant allOf matcher calls
Remove calls to the `allOf` matcher in all matchers that are derived from the `VariadicDynCastAllOfMatcher`.
2023-04-11 00:38:37 +01:00
Carlos Galvez
4d4c0f9734 [clang-tidy] Add option to ignore capture default by reference in cppcoreguidelines-avoid-capture-default-when-capturing-this
The rule exists primarily for when using capture default
by copy "[=]", since member variables will be captured by
reference, which is against developer expectations.

However when the capture default is by reference, then there
is no doubt: everything will be captured by reference. Add
an option to allow just that.

Note: Release Notes do not need update since this check
has been introduced in the current WIP release.

A ticket has been opened at the C++ Core Guidelines repo
to consider updating the rule such that this behavior
is the default one:
https://github.com/isocpp/CppCoreGuidelines/issues/2060

Differential Revision: https://reviews.llvm.org/D147062
2023-03-28 20:36:34 +00:00
Chris Cotter
bd7628461b [clang-tidy] Ignore unevaluated exprs in rvalue-reference-param-not-moved
Ignore unevaluated expressions in rvalue-reference-param-not-moved
check since they are not actual uses of a move().

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D146929
2023-03-28 07:05:12 +00:00
Chris Cotter
c491c91702 [clang-tidy] Implement CppCoreGuideline F.18
Warn when an rvalue reference function paramter is never moved
from within the function body.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D141569
2023-03-12 16:58:08 +00:00
Piotr Zegar
f1e2469edc [clang-tidy] Fix false-positive in cppcoreguidelines-slicing
When warning would be emitted in constructor for virtual base class
initialization.

Fixes: https://github.com/llvm/llvm-project/issues/31187

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D144206
2023-03-11 17:36:21 +00:00
Piotr Zegar
17d403f664 [clang-tidy] Finish cppcoreguidelines-avoid-capturing-lambda-coroutines check
This commit implements check for CP.51 C++ Core Guidelines

Depends on D137514

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D145720
2023-03-10 14:06:50 +00:00
Noah Watkins
54178fc616 [clang-tidy] add check for capturing lambda coroutines
Signed-off-by: Noah Watkins <noah@redpanda.com>

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D137514
2023-03-10 14:06:50 +00:00
Roy Jacobson
aa56e66bf7 [clang-tidy] Tweak 'rule of 3/5' checks to allow defaulting a destructor outside the class.
A somewhat common code-pattern is to default a destructor in the source file and not in the header.
For example, this is the way to use smart pointers with forward-declared classes:

```c++

struct Impl;
struct A {
  ~A(); // Can't be defaulted in the header.

private:
  std::unique_ptr<Impl> impl;
};
```

To be able to use this check with this pattern, I modified the behavior with `AllowSoleDefaultDtor`
to not trigger on destructors if they aren't defined yet.
Since a declared destructor should still be defined somewhere in the program, this
won't miss bad classes, just diagnose on less translation units.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D143851
2023-02-26 15:55:54 +02:00
Sockke
ce6de98b80 [clang-tidy] Fix cppcoreguidelines-init-variables for invalid vardecl
https://godbolt.org/z/n4cK4fo3o
The checker missed a check for invalid vardecl and this could cause a false positive.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D138655
2023-02-07 19:34:54 +08:00
Chris Cotter
8a8f77c1b8 [clang-tidy] Implement CppCoreGuideline F.54
Warn when a lambda specifies a default capture and captures
``this``. Offer FixIts to correct the code.

Reviewed By: njames93, carlosgalvezp

Differential Revision: https://reviews.llvm.org/D141133
2023-02-02 07:20:59 +00:00
Carlos Galvez
4718da5060 [clang-tidy][NFC] Use C++17 nested namespaces in clang-tidy headers
We forgot to apply the change to headers in the previous patch,
due to missing "-header-filter" in the run-clang-tidy invocation.

Differential Revision: https://reviews.llvm.org/D142307
2023-01-23 21:23:16 +00:00
Carlos Galvez
7d2ea6c422 [clang-tidy][NFC] Use C++17 nested namespaces in the clang-tidy folder
Fix applied by running:

run-clang-tidy.py -checks=-*,modernize-concat-nested-namespaces

Differential Revision: https://reviews.llvm.org/D141770
2023-01-14 18:51:39 +00:00
Kazu Hirata
f71ffd3b73 [clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to clean up the "using" declarations, #include
"llvm/ADT/Optional.h", etc.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:19:42 -08:00
Kazu Hirata
71f557355d [clang-tools-extra] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:02:20 -08:00
Chris Cotter
b06b248ad9 [clang-tidy] Implement CppCoreGuideline CP.53
Implement CppCoreGuideline CP.53 to warn when a coroutine accepts
references parameters. Although the guideline mentions that it is safe
to access a reference parameter before suspension points, the guideline
recommends flagging all coroutine parameter references.

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D140793
2023-01-05 13:57:22 +00:00
Fangrui Song
b0de363024 [clang] Remove uses of ::testing::Matcher<const Optional<T> &>
Change a few functions (getCheckTraversalKind, some clang/Tooling/ API, etc)
from llvm::Optional to std::optional.
2022-12-14 06:42:35 +00:00
Kazu Hirata
cd8702efe7 [clang-tidy] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 11:54:48 -08:00
Carlos Galvez
1ae33bf426 [clang-tidy] Add cppcoreguidelines-avoid-do-while check
Implements rule ES.75 of C++ Core Guidelines.

Differential Revision: https://reviews.llvm.org/D132461
2022-10-10 07:29:17 +00:00
isuckatcs
cd40245f54 [clang-tidy] Fix false positive on ArrayInitIndexExpr inside ProBoundsConstantArrayIndexCheck
Sometimes in the AST we can have an ArraySubscriptExpr,
where the index is an ArrayInitIndexExpr.
ArrayInitIndexExpr is not a constant, so
ProBoundsConstantArrayIndexCheck reports a warning when
it sees such expression. This expression can only be
implicitly generated, and always appears inside an
ArrayInitLoopExpr, so we shouldn't report a warning.

Differential Revision: https://reviews.llvm.org/D132654
2022-08-30 20:27:38 +02:00