3434 Commits

Author SHA1 Message Date
Kazu Hirata
ff4e21fccc
[clang-tidy] Avoid repeated hash lookups (NFC) (#127444) 2025-02-17 01:31:52 -08:00
Kazu Hirata
0bae0bf8ba
[clang-tidy] Avoid repeated hash lookups (NFC) (#127370) 2025-02-16 08:14:42 -08:00
Kazu Hirata
1bc2f1c83f
[clang-tidy] Avoid repeated map lookups (NFC) (#127167) 2025-02-14 01:33:51 -08:00
Piotr Zegar
a663e78a6e
[clang-tidy] Add recursion protection in ExceptionSpecAnalyzer (#66810)
Normally endless recursion should not happen in ExceptionSpecAnalyzer,
but if AST would be malformed (missing include), this could cause crash.

I run into this issue when due to missing include constructor argument
were parsed as FieldDecl.
As checking for recursion cost nothing, why not to do this in check just
in case.

Fixes #111436
2025-02-13 17:51:28 +01:00
Baranov Victor
0b922d66e5
[clang-tidy] Added support for 3-argument std::string ctor in bugprone-string-constructor check (#123413)
This PR add diagnostics for 3-parameter `std::basic_string(const char*
t, size_type pos, size_type count)` constructor in
bugprone-string-constructor check:

```cpp
  std::string r1("test", 1, 0); // constructor creating an empty string
  std::string r2("test", 0, -4); // negative value used as length parameter
  // more examples in test file
  ```

Fixes false-positives reported in https://github.com/llvm/llvm-project/issues/123198.
2025-02-11 09:09:57 +08:00
earnol
1e14edb898
[clang-tidy] Address false positives in misc-redundant-expression checker (#122841)
This patch addresses situations when misc-redundant-expression checker
provides excessive diagnostics for situations with different macros
having the same value. In particular it addresses situations described
in the initial report of
https://github.com/llvm/llvm-project/issues/118885 are addressed. The
situations which are popped inside discussion like if (A + B == B + A)
for macros are not properly addressed by this patch.
Those changes are also mentioned in Release Notes.
---------

Co-authored-by: Vladislav Aranov <vladislav.aranov@ericsson.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
2025-02-10 13:16:37 -05:00
Discookie
3262863805
[clang-tidy] Add C++ member function support to custom bugprone-unsafe-functions matches (#117165)
Before, C++ member functions in the format of ``Class instance;
instance.memberfn();`` were unable to be matched.
This PR adds support for this type of call, and it is matched in exactly
the same format as other functions (eg. ``::Class::memberfn`` qualified
name).
2025-01-30 10:49:01 +00:00
Congcong Cai
8e6d6a5510
[clang-tidy][NFC] improve performance misc-unused-using-decls (#123454)
skip header file before register AST Matchers
it can avoid to matcher lots of ast node when lint header file
2025-01-24 19:32:11 +08:00
Congcong Cai
46a08ce832
[clang-tidy][NFC] simplify TimerGroup in ClangTidyProfiling (#123958)
`TimerGroup` don't need to use as field of `ClangTidyProfiling`.
We can construct it local during destructing.
2025-01-24 19:29:24 +08:00
Congcong Cai
68c6b2e188
[ASTMatchers][NFC] use Matcher<QualType> instead of DynTypedMatcher in TypeLocTypeMatcher (#123450)
There are no template in `TypeLocTypeMatcher`. So we do not need to use
`DynTypedMatcher` which can improve performance
2025-01-23 06:28:43 +08:00
qt-tatiana
aa580c2ec5
[clang-tidy] Add EnableQtSupport option to modernize-use-integer-sign-comprison (#122127)
- add an option `EnableQtSupport`, that makes C++17 `q20::cmp_*`
alternative available for Qt-based applications.
2025-01-22 23:30:53 +08:00
Clement Courbet
fbd86d05fe
[clang-reorder-fields] Reorder leading comments (#123740)
Similarly to https://github.com/llvm/llvm-project/pull/122918, leading
comments are currently not being moved.

```
struct Foo {
  // This one is the cool field.
  int a;
  int b;
};
```

becomes:

```
struct Foo {
  // This one is the cool field.
  int b;
  int a;
};
```

but should be:

```
struct Foo {
  int b;
  // This one is the cool field.
  int a;
};
```
2025-01-22 13:42:00 +01:00
Congcong Cai
909bf38c1f
[clang-tidy][NFC] remove unused field in UnusedUsingDeclsCheck (#123451) 2025-01-18 14:14:50 +08:00
Congcong Cai
48d0ef1a07
[clang-tidy][NFC] refactor modernize-raw-string-literal fix hint (#122909) 2025-01-17 21:47:47 +08:00
Congcong Cai
361f363c11
[clang-tidy]fix incorrect fix-it for the string contains a user-defined suffix (#122901)
Fixed: #97243
2025-01-17 21:41:48 +08:00
Clement Courbet
1819646623
[clang][refactor] Refactor findNextTokenIncludingComments (#123060)
We have two copies of the same code in clang-tidy and
clang-reorder-fields, and those are extremenly similar to
`Lexer::findNextToken`, so just add an extra agument to the latter.

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2025-01-16 17:06:05 +01:00
zotnhucucbot
bc74625f50
[clang-tidy] Add an option to exclude files not present in the compile database (#120348)
A change list may include files that are not part of the compile
database, which can cause clang-tidy to fail (e.g., due to missing
included headers). To prevent false negatives, we should allow to skip
processing these files.
2025-01-15 07:59:03 +08:00
Jay Foad
e87f94a6a8
[llvm-project] Fix typos mutli and mutliple. NFC. (#122880) 2025-01-14 11:59:41 +00:00
Congcong Cai
ab023199d5
[clang-tidy] fix wrong float to float conversion check when floating point type is not standard type (#122637)
compare type kind is the wrong way to compare floating point type compatibility.
more generic compatibility check is needed.
2025-01-14 06:15:50 +08:00
MichelleCDjunaidi
8ebc35f8d0
[clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (#102299)
This checks that classes/structs inheriting from
``std::enable_shared_from_this`` does so with public inheritance, so it
prevents crashes due to ``std::make_shared`` and ``shared_from_this()``
getting called when the internal weak pointer was not initialized (e.g.
due to private inheritance).
2025-01-12 11:04:40 +01:00
Barnabás Pőcze
a5364444bd
[clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (#119974)
Static member functions can be considered the same way as free functions
are, so do that.
2025-01-12 10:07:52 +01:00
Congcong Cai
0249554ee1
[clang-tidy] fix incorrect configuration file path resolving when file paths contain .. (#121323)
`makeAbsolute` will not normalize path. When getting parent folder, `..`
will go into the subfolder instead of the parent folder.
2025-01-11 22:51:47 +08:00
Congcong Cai
ae9bf17697
[clang-tidy] remove never used IgnoreCase in option (#122573) 2025-01-11 22:46:04 +08:00
Congcong Cai
32bcd41adc
[clang-tidy] use correct template type in `std::min and std::max` when operand is integer literal for readability-use-std-min-max (#122296)
When comparing with integer literal, integer promote will happen to
promote type which has less bit width than int to int or unsigned int.
It will let auto-fix provide correct but out of expected fix.

e.g.
```c++
short a;
if ( a > 10 )
  a = 10;
```
will be
```c++
short a;
if ( (int)a > 10 )
  a = (short)10;
```

which will be fixed as
```c++
short a;
a = std::max<int>(a, 10);
```

but actually it can be
```c++
short a;
a = std::max<short>(a, 10);
```

Fixed: #121676
2025-01-11 18:48:39 +08:00
Tommy Chen
dc2963c8d7
[clang-tidy] exclude CXXParenListInitExpr from RedundantCastingCheck (#109741)
Exclude CXXParenListInitExpr from RedundantCastingCheck because there
are false positive cases. Currently, we can't think of positive cases
for CXXParenListInitExpr. This can be improved by following the
initListExpr method if we can come up with some positive cases.

Fixes #108846
2025-01-11 11:04:19 +01:00
Niels Dekker
30bb186389
[clang-tidy] Mention std::forward_list in container-size-empty doc (#120701)
Mentioned `std::forward_list` as example of a container without
`size()`.
2025-01-11 10:15:17 +01:00
Timm Baeder
cfe26358e3
Reapply "[clang] Avoid re-evaluating field bitwidth" (#122289) 2025-01-11 07:12:37 +01:00
Congcong Cai
aee51b4d75
[clang-tidy][NFC] optimize cache for config option (#121406)
Current implement will cache `OptionsSource` for each path, it will
create lots of copy of `OptionsSource` when project has deep nested
folder structure.
New implement use vector to store `OptionsSource` and only cache the
index. It can reduce memory usage and avoid meaningless copy.
2025-01-10 23:42:29 +08:00
maflcko
6504546abc
[clang-tidy][use-internal-linkage] fix false positive for consteval function (#122141)
Fixes https://github.com/llvm/llvm-project/issues/122096

---------

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2025-01-10 09:24:24 +01:00
Congcong Cai
504f6ce0c2
[clang-tidy][NFC] clean readability-use-std-min-max (#122288)
1. add `static` for internal linkage functions
2. remove `clang` prefix for `QualType`
2025-01-10 07:35:50 +08:00
Maksim Ivanov
1b897f737d
[clang-tidy] Fix misc-unused-parameters on params with attrs (#122286)
Don't suggest to comment-out the parameter name if the parameter has an
attribute that's spelled after the parameter name.

This prevents the parameter's attributes from being wrongly applied to
the parameter's type.

This fixes #122191.
2025-01-09 20:40:31 +01:00
Congcong Cai
e41f96ad25
[clang-tidy][NFC] clean LangOpts parameter in explicitMarkUnused matcher (#122170)
https://github.com/llvm/llvm-project/pull/121783#discussion_r1907847579
2025-01-09 20:21:31 +08:00
Timm Bäder
59bdea24b0 Revert "[clang] Avoid re-evaluating field bitwidth (#117732)"
This reverts commit 81fc3add1e627c23b7270fe2739cdacc09063e54.

This breaks some LLDB tests, e.g.
SymbolFile/DWARF/x86/no_unique_address-with-bitfields.cpp:

lldb: ../llvm-project/clang/lib/AST/Decl.cpp:4604: unsigned int clang::FieldDecl::getBitWidthValue() const: Assertion `isa<ConstantExpr>(getBitWidth())' failed.
2025-01-08 15:09:52 +01:00
Timm Baeder
81fc3add1e
[clang] Avoid re-evaluating field bitwidth (#117732)
Save the bitwidth value as a `ConstantExpr` with the value set. Remove
the `ASTContext` parameter from `getBitWidthValue()`, so the latter
simply returns the value from the `ConstantExpr` instead of
constant-evaluating the bitwidth expression every time it is called.
2025-01-08 14:45:19 +01:00
Congcong Cai
72b6a57363
[clang-tidy] fix false positives when using name-independent variables after C++26 for bugprone-unused-local-non-trivial-variable (#121783)
Fixed: #121731
According to https://eel.is/c++draft/basic.scope.scope#5, name
independent declaration should not be warned as unused
2025-01-08 20:56:49 +08:00
flovent
c27483763c
[clang-tidy] bugprone-unhandled-self-assignment: fix smart pointer check against std::unique_ptr type (#121266)
Unlike other standard smart pointer types, std::unique_ptr has two
template arguments.
testcase need to be updated too.
2025-01-07 20:56:21 +08:00
Congcong Cai
42dfaa15a6
[clang-tidy] add depercation warning for non-whitelisted global options (#121057)
We plan to depercate `StrictMode` and `IgnoreMacros` global options
after 2 major versions and support local options only for them.
This patch introduces the depercation warning.
2024-12-30 22:35:46 +08:00
Congcong Cai
b34ed25dd5 [clang-tidy][NFC] add link libs for bugprone module
Fixed bug issue introduced in #120245
2024-12-29 19:51:55 +08:00
Congcong Cai
e45e091b90
[clang-tidy] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (#120245)
According to #116591.
> Coding guidelines should "cherry-pick" (and posddsibly
configure/harden/make more strict) base checks.
We should move narrowing conversion to bugprone and keep alias in
cppcoreguidelines
2024-12-29 19:22:25 +08:00
NAKAMURA Takumi
537d4e9d21 Revert "Added options to readability-implicit-bool-conversion (#120087)"
This reverts commit 5bec2b71b44ddff44aa4d8534b58a5561389bb1d.
(llvmorg-20-init-16425-g5bec2b71b44d)

This broke tests.
2024-12-28 17:47:00 +09:00
4m4n-x-B4w4ne
5bec2b71b4
Added options to readability-implicit-bool-conversion (#120087)
As given in the issue #36323 , I added two new options in the
clang-tools-extra/clan-tidy/readibility/ImplicitBoolConversionCheck.cpp
and header file.
I have also written new test cases to test these new options in
test/readibility directory.
2024-12-28 15:35:30 +08:00
hill
7ecbeace01
[clang-tidy] fix incorrect argument names in documentation for ExtraArgs and ExtraArgsBefore (#120963) 2024-12-26 22:44:14 +01:00
Congcong Cai
34f7000734
[clang-tidy]link LLVMTargetParser (#121072)
Fix build issue introduced in #120547
2024-12-25 11:07:05 +08:00
Congcong Cai
2ff614aaa6
[clang-tidy] support parameters file in command line (#120547)
Fixes: #103499
2024-12-24 23:24:14 +08:00
Julian Schmidt
f77152d9a4
[clang-tidy] use specified type verbatim in modernize-use-using fix (#113837)
Previously, the implementation used the printed type, which contains
expanded
macro arguments, deletes comments, and removes function argument names 
from the alias declaration. Instead, this check can be more surgical and
use the
actual written type verbatim.

Fixes #33760
Fixes #37846
Fixes #41685
Fixes #83568
Fixes #95716
Fixes #97009
2024-12-21 13:06:30 +01:00
Congcong Cai
e5de2a2df4
[clang-tidy][NFC] extract options verify to separately function (#120768) 2024-12-21 07:07:19 +08:00
Niels Dekker
e3b571e632
[clang-tidy][NFC] Sync ContainerSizeEmptyCheck with container-size-empty doc (#118459)
Brought the class documentation in sync with the user documentation at
container-size-empty.rst:


bfb26202e0/clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst (L7-L14)
2024-12-19 21:16:40 +01:00
Congcong Cai
222dd235ff
[clang-tidy] use local config (#120004)
follow up patch for #119948.
2024-12-18 18:38:46 +08:00
Congcong Cai
aaadaee7b2
[clang-tidy] remove misuse of getLocalOrGlobal for non common used options (#119948)
[RFC](https://discourse.llvm.org/t/rfc-global-option-rules-for-clang-tidy/83647)
2024-12-15 05:04:32 +08:00
Congcong Cai
ba373a222f
[clang-tidy]detecting conversion directly by make_unique and make_shared in bugprone-optional-value-conversion (#119371)
Inspired by #110964
2024-12-12 06:55:29 +08:00