aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/test/clang-tidy
AgeCommit message (Collapse)AuthorFilesLines
2024-06-20[Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit ↵Mital Ashok5-4/+9
(#95580) This checks if the layout of `std::initializer_list` is something Clang can handle much earlier and deduplicates the checks in CodeGen/CGExprAgg.cpp and AST/ExprConstant.cpp Also now diagnose `union initializer_list` (Fixes #95495), bit-field for the size (Fixes a crash that would happen during codegen if it were unnamed), base classes (that wouldn't be initialized) and polymorphic classes (whose vtable pointer wouldn't be initialized).
2024-06-18[llvm] Remove the Legacy PM Hello example (#95708)Andrzej Warzyński1-1/+1
The Legacy PM was deprecated for the optimization pipeline in LLVM 14 [1] (the support was removed altogether in the following release). This patch removes the original Hello example that was introduced to illustrate the Legacy PM. The Hello example no longer works and hence is deleted. The corresponding documentation is also removed. Note, Hello example for the new PM is located in * llvm/lib/Transforms/Utils/HelloWorld.cpp and documented in * WritingAnLLVMNewPMPass.rst. [1] https://releases.llvm.org/14.0.0/docs/ReleaseNotes.html#changes-to-the-llvm-ir
2024-06-18Revert "[clang-tidy] fix false positives for the functions with the same ↵Kadir Cetinkaya1-8/+0
name as standard library functions in misc-include-cleaner (#94923)" This reverts commit 1bae10879d9183c5edfb709c36b55086ebc772f0. Also add some test cases to prevent further regressions.
2024-06-16[clang-tidy] fix false negatives for ↵Congcong Cai1-0/+35
performance-inefficient-vector-operation (#95667) Fixes: #95596 Avoid false negatives caused by different variable definition type and variable initial value type in loop initialization expression.
2024-06-15[clang-tidy]fix false positives of the result of std::move() is used as ↵Congcong Cai1-5/+9
rvalue for performance-move-const-arg (#95633) Fixes: #86404 --------- Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2024-06-15[clang-tidy] avoid false positive when overload for ↵Congcong Cai1-0/+34
bugprone-return-const-ref-from-parameter (#95434) Fixes: #90274
2024-06-13[clang-tidy] ignoring macro with hash preprocessing token in ↵Congcong Cai1-0/+4
cppcoreguidelines-macro-usage (#95265) `#` and `##` preprocessing tokens cannot be replaced by constexpr function. It should be ignored in check.
2024-06-11[clang-tidy] fix false positives for the functions with the same name as ↵Congcong Cai1-0/+8
standard library functions in misc-include-cleaner (#94923) Fixes: #93335 For decl with body, we should provide physical locations also. Because it may be the function which have the same name as std library.
2024-06-11[clang-tidy] Improve sizeof(pointer) handling in bugprone-sizeof-expression ↵Donát Nagy3-27/+299
(#94356) This commit reimplements the functionality of the Clang Static Analyzer checker `alpha.core.SizeofPointer` within clang-tidy by adding a new (off-by-default) option to bugprone-sizeof-expression which activates reporting all the `sizeof(ptr)` expressions (where ptr is an expression that produces a pointer). The main motivation for this change is that `alpha.core.SizeofPointer` was an AST-based checker, which did not rely on the path sensitive capabilities of the Static Analyzer, so there was no reason to keep it in the Static Analyzer instead of the more lightweight clang-tidy. After this commit I'm planning to create a separate commit that deletes `alpha.core.SizeofPointer` from Clang Static Analyzer. It was natural to place this moved logic in bugprone-sizeof-expression, because that check already provided several heuristics that reported various especially suspicious classes of `sizeof(ptr)` expressions. The new mode `WarnOnSizeOfPointer` is off-by-default, so it won't surprise the existing users; but it can provide a more through coverage for the vulnerability CWE-467 ("Use of sizeof() on a Pointer Type") than the existing partial heuristics. Previously this checker had an exception that the RHS of a `sizeof(array) / sizeof(array[0])` expression is not reported; I generalized this to an exception that the check doesn't report `sizeof(expr[0])` and `sizeof(*expr)`. This idea is taken from the Static Analyzer checker `alpha.core.SizeofPointer` (which had an exception for `*expr`), but analysis of open source projects confirmed that this indeed eliminates lots of unwanted results. Note that the suppression of `sizeof(expr[0])` and `sizeof(*expr)` reports also affects the "old" mode `WarnOnSizeOfPointerToAggregate` which is enabled by default. This commit also replaces the old message "suspicious usage of 'sizeof(A*)'; pointer to aggregate" with two more concrete messages; but I feel that this tidy check would deserve a through cleanup of all the diagnostic messages that it can produce. (I added a FIXME to mark one outright misleading message.)
2024-06-10[clang-tidy] `doesNotMutateObject`: Handle calls to member functions … ↵Clement Courbet1-2/+27
(#94362) …and operators that have non-const overloads. This allows `unnecessary-copy-initialization` to warn on more cases. The common case is a class with a a set of const/non-sconst overloads (e.g. std::vector::operator[]). ``` void F() { std::vector<Expensive> v; // ... const Expensive e = v[i]; } ```
2024-06-09[clang-tidy] Improve bugprone-multi-level-implicit-pointer-conversion (#94524)Piotr Zegar1-0/+12
Ignore implicit pointer conversions that are part of a cast expression Closes #93959
2024-06-09[clang-tidy] Extend modernize-use-designated-initializers with new options ↵Piotr Zegar1-4/+4
(#94651) Add StrictCStandardCompliance and StrictCppStandardCompliance options that default to true. Closes #83732
2024-06-09[clang-tidy] Ignore implicit functions in ↵Piotr Zegar1-0/+31
readability-implicit-bool-conversion (#94512) Ignore implicit declarations and defaulted functions. Helps with issues in generated code like, C++ spaceship operator. Closes #93409
2024-06-09[clang-tidy] Ignore non-math operators in ↵Piotr Zegar1-0/+17
readability-math-missing-parentheses (#94654) Do not emit warnings for non-math operators. Closes #92516
2024-06-08[clang-tidy] new check misc-use-internal-linkage (#90830)Congcong Cai6-0/+87
Add new check misc-use-internal-linkage to detect variable and function can be marked as static. --------- Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2024-06-07[clang-tidy]fix crashing when self include cycles for ↵Congcong Cai1-0/+3
misc-header-include-cycle (#94636) Fixes: #94634
2024-06-06[clang-tidy] Fix crash in readability-container-size-empty (#94527)Piotr Zegar1-0/+6
Fixed crash caused by call to getCookedLiteral on template user defined literal. Fix base on assert in getCookedLiteral method. Closes #94454
2024-06-05[clang-tidy] Fix handling of members in readability-redundant-member-init ↵Piotr Zegar1-0/+16
(#93217) Compare class type instead of just assuming that called constructor belong to same class. Fixes #91605
2024-06-03[clang-tidy] Fix assert in modernize-use-std-format/print (#94104)Mike Crowe2-4/+40
Ensure that FormatStringConverter's constructor fails with a sensible error message rather than asserting if the format string is not a narrow string literal. Also, ensure that we don't even get that far in modernize-use-std-print and modernize-use-std-format by checking that the format string parameter is a char pointer. Fixes #92896
2024-05-30[clang-tidy] Check number of arguments to size/length in ↵Piotr Zegar1-0/+28
readability-container-size-empty (#93724) Verify that size/length methods are called with no arguments. Closes #88203
2024-05-23[clang-tidy] Correcting issues in `readability-implicit-bool-conversion` on ↵Björn Svensson1-0/+354
C23 (#92241) `readability-implicit-bool-conversion` supports language-versions with `LangOpts.Bool` which includes C23. This PR corrects an issue that the fixer suggests `static_cast<>()` which is not available in C23, and will instead suggest C-style casts on other than C++. The fixer will also suggest using `nullptr` instead of `0` and avoid a problem with recursive fixes on C23. The recursive issue, a function taking bool and a comparison, is now excluded as in C++.
2024-05-22Reland "[clang] Enable sized deallocation by default in C++14 onwards" (#90373)Pengcheng Wang1-10/+0
Since C++14 has been released for about nine years and most standard libraries have implemented sized deallocation functions, it's time to make this feature default again. This is another try of https://reviews.llvm.org/D112921. The original commit cf5a8b4 was reverted by 2e5035a due to some failures (see #83774). Fixes #60061
2024-05-21[clang-tidy] Rename out-of-line function definitions (#91954)Edwin Vane1-0/+30
Member function templates defined out-of-line were resulting in conflicting naming failures with overlapping usage sets. With this change, out-of-line definitions are treated as a usage of the failure which is the inline declaration.
2024-05-20[Clang][Sema] Diagnose current instantiation used as an incomplete base ↵Krystian Stasiowski2-6/+8
class (#92597) Consider the following: ``` template<typename T> struct A { struct B : A { }; }; ``` According to [class.derived.general] p2: > [...] A _class-or-decltype_ shall denote a (possibly cv-qualified) class type that is not an incompletely defined class; any cv-qualifiers are ignored. [...] Although GCC and EDG rejects this, Clang accepts it. This is incorrect, as `A` is incomplete within its own definition (outside of a complete-class context). This patch correctly diagnoses instances where the current instantiation is used as a base class before it is complete. Conversely, Clang erroneously rejects the following: ``` template<typename T> struct A { struct B; struct C : B { }; struct B : C { }; // error: circular inheritance between 'C' and 'A::B' }; ``` Though it may seem like no valid specialization of this template can be instantiated, an explicit specialization of either member classes for an implicit instantiated specialization of `A` would permit the definition of the other member class to be instantiated, e.g.: ``` template<> struct A<int>::B { }; A<int>::C c; // ok ``` So this patch also does away with this error. This means that circular inheritance is diagnosed during instantiation of the definition as a consequence of requiring the base class type to be complete (matching the behavior of GCC and EDG).
2024-05-16[clang] Fix CXXNewExpr end source location for 'new struct S' (#92266)Arseniy Zaostrovnykh1-5/+2
Currently, `new struct S` fails to set any valid end source location because the token corresponding to `S` is consumed in `ParseClassSpecifier` and is not accessible in the `ParseDeclarationSpecifiers` that normally sets the end source location. Fixes #35300
2024-05-15[clang-tidy] Add AllowImplicitlyDeletedCopyOrMove option to ↵Piotr Zegar1-3/+23
cppcoreguidelines-special-member-functions (#71683) Improved cppcoreguidelines-special-member-functions check with a new option AllowImplicitlyDeletedCopyOrMove, which removes the requirement for explicit copy or move special member functions when they are already implicitly deleted. Closes #62392
2024-05-15[clang-tidy] Fix crash in modernize-use-constraints (#92019)Piotr Zegar1-0/+32
Improved modernize-use-constraints check by fixing a crash that occurred in some scenarios and excluded system headers from analysis. Problem were with DependentNameTypeLoc having null type location as getQualifierLoc().getTypeLoc(). Fixes #91872
2024-05-15[clang-tidy] fix crash due to assumed callee in min-max-use-initializer-list ↵Julian Schmidt1-0/+21
(#91992) Previously, the call to `findArgs` for a `CallExpr` inside of a `min` or `max` call would call `findArgs` before checking if the argument is a call to `min` or `max`, which is what `findArgs` is expecting. The fix moves the name checking before the call to `findArgs`, such that only a `min` or `max` function call is used as an argument. Fixes #91982 Fixes #92249
2024-05-14Add option to exclude headers from clang-tidy analysis (#91400)Justin Cady5-1/+24
This is a renewed attempt to land @toddlipcon's D34654. The comments on that patch indicate a broad desire for some ability to ignore headers. After considering various options, including migrating to std::regex, I believe this is the best path forward. It's intuitive to have separate regexes for including headers versus excluding them, and this approach has the added benefit of being completely opt-in. No existing configs will break, regardless of existing HeaderFilterRegex values. This functionality is useful for improving performance when analyzing a targeted subset of code, as well as in cases where some collection of headers cannot be modified (third party source, for example).
2024-05-14[clang-tidy] support expect no diagnosis test (#91293)Congcong Cai3-12/+28
When someone wants to declare a test case without any diagnosis. check-clang-tidy will failed with error message ``` CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES not found in the input ``` This PR want to check there are no diagnosis from clang-tidy when CHECK-FIXES, CHECK-MESSAGES or CHECK-NOTES are not found. It also changes the extension of a test case. `hxx` is not a valid test case extension and won't be tested. --------- Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2024-05-13[clang-tidy] Add modernize-use-std-format check (#90397)Mike Crowe3-0/+196
Add a new clang-tidy check that converts absl::StrFormat (and similar functions) to std::format (and similar functions.) Split the configuration of FormatStringConverter out to a separate Configuration class so that we don't risk confusion by passing two boolean configuration parameters into the constructor. Add AllowTrailingNewlineRemoval option since we never want to remove trailing newlines in this check.
2024-05-13[clang-tidy] Ignore unevaluated context in ↵Piotr Zegar1-0/+2
bugprone-optional-value-conversion (#90410) Ignore optionals in unevaluated context, like static_assert or decltype. Closes #89593
2024-05-13[clang-tidy] Ignore `if consteval` in else-after-return (#91588)Jover1-0/+17
2024-05-11[clang-tidy] `readability-simplify-boolean-expr` avoid to warn expression ↵Congcong Cai1-4/+14
expand from macro when ``IgnoreMacro`` option is enabled. (#91757) Fixes: #91487
2024-05-09[NFC][clang-tidy] remove magic-numbers-todo.cpp (#91577)Congcong Cai1-15/+0
This XFAIL test is written in 4 years ago and still todo. 4 is already in DefaultIgnoredIntegerValues so I do not think this XFAIL case can be passed.
2024-05-09[clang-tidy] check `std::string_view` and custom string-like classes in ↵Vadim D3-0/+68
`readability-string-compare` (#88636) This PR aims to expand the list of classes that are considered to be "strings" by `readability-string-compare` check. 1. Currently only `std::string;:compare` is checked, but `std::string_view` has a similar `compare` method. This PR enables checking of `std::string_view::compare` by default. 2. Some codebases use custom string-like classes that have public interfaces similar to `std::string` or `std::string_view`. Example: [TStringBase](https://github.com/yandex/yatool/blob/main/util/generic/strbase.h#L38), A new option, `readability-string-compare.StringClassNames`, is added to allow specifying a custom list of string-like classes. Related to, but does not solve #28396 (only adds support for custom string-like classes, not custom functions)
2024-05-08[clang-tidy] Handle expr with side-effects in ↵Piotr Zegar1-7/+31
readability-static-accessed-through-instance (#90736) Improved readability-static-accessed-through-instance check to support expressions with side-effects. Originally calls to overloaded operator were ignored by check, in fear of possible side-effects. This change remove that restriction, and enables fix-its for expressions with side-effect via --fix-notes. Closes #75163
2024-05-08[clang-tidy] Handle implicit casts in hicpp-signed-bitwise for ↵Piotr Zegar1-0/+3
IgnorePositiveIntegerLiterals (#90621) Improved hicpp-signed-bitwise check by ignoring false positives involving positive integer literals behind implicit casts when IgnorePositiveIntegerLiterals is enabled. Closes #89367
2024-05-05[clang-tidy] fix false-positives for templates in ↵Julian Schmidt1-1/+115
`bugprone-return-const-ref-from-parameter` (#90273) In the AST for function templates, the return will be a DeclRefExpr, even if the return type differs from that of the returned variable. Protect against false-positives by constraining the canonical return type to be that of the parameter. Also streams the source range of the returned expression into the diagnostic.
2024-05-03[clang-tools-extra,test] Convert text files from CRLF to LFFangrui Song4-39/+39
Skip files with intentional CRLF line endings: test/clang-apply-replacements/crlf.cpp test/clang-apply-replacements/Inputs/crlf/crlf.cpp.expected clangd/test/input-mirror.test clangd/test/protocol.test clangd/test/too-large.test
2024-05-03Use FileCheck in new clang-tidy/infrastructure/config-files.cpp testsHans Wennborg1-6/+2
The test was failing spuriously on some machines [1]. Converting from grep to FileCheck makes it easier to see what's happening, and also grep is discouraged in tests [2]. Also drop the negative test: checking for the expected output is better. 1. https://crbug.com/338535754 2. https://llvm.org/docs/TestingGuide.html#:~:text=.%20%5BThe-,usage%20of%20grep,-in%20RUN%20lines
2024-05-02[clang-tidy] Relax readability-const-return-type (#90560)Piotr Zegar1-3/+17
From now readability-const-return-type won't provide warnings for returning const types, where const is not on top level. In such case const there is a performance issue, but not a readability. Closes #73270
2024-05-02[clang-tidy] Ignore casts from void to void in bugprone-casting-through-void ↵Piotr Zegar1-0/+7
(#90566) Improved bugprone-casting-through-void check by ignoring casts where source is already a void pointer, making middle void pointer casts bug-free. Closes #87069
2024-04-30Reapply "[Clang][Sema] Diagnose class member access expressions naming ↵Krystian Stasiowski2-0/+14
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" (#90152) Reapplies #84050, addressing a bug which cases a crash when an expression with the type of the current instantiation is used as the _postfix-expression_ in a class member access expression (arrow form).
2024-04-30[clang-tidy] fix false-negative for macros in ↵Julian Schmidt1-0/+22
`readability-math-missing-parentheses` (#90279) When a binary operator is the last operand of a macro, the end location that is past the `BinaryOperator` will be inside the macro and therefore an invalid location to insert a `FixIt` into, which is why the check bails when encountering such a pattern. However, the end location is only required for the `FixIt` and the diagnostic can still be emitted, just without an attached fix.
2024-04-27[clang-tidy] Enable C23 support in modernize-use-nullptr (#89990)Björn Svensson2-1/+140
C23 introduces the `nullptr` constant similar to C++11 which means that the checker `modernize-use-nullptr` can be used on C23 code as well. This PR enables the checker to be run on C23 and adds testcases. See N3042: https://open-std.org/JTC1/SC22/WG14/www/docs/n3042.htm
2024-04-26Revert "[clang] Enable sized deallocation by default in C++14 onwards ↵Vitaly Buka1-0/+10
(#83774)" (#90299) https://lab.llvm.org/buildbot/#/builders/168/builds/20063 (should be fixed with #90292) More details in #83774 This reverts commit cf5a8b489464d09dfdd7a48ce7c8b41d3c9bf819.
2024-04-26[clang] Enable sized deallocation by default in C++14 onwards (#83774)Pengcheng Wang1-10/+0
Since C++14 has been released for about nine years and most standard libraries have implemented sized deallocation functions, it's time to make this feature default again. This is another try of https://reviews.llvm.org/D112921. Fixes #60061
2024-04-26Revert "[Clang][Sema] Diagnose class member access expressions naming ↵Pranav Kant2-14/+0
non-existent members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050)" This reverts commit a8fd0d029dca7d17eee72d0445223c2fe1ee7758.
2024-04-25[Clang][Sema] Diagnose class member access expressions naming non-existent ↵Krystian Stasiowski2-0/+14
members of the current instantiation prior to instantiation in the absence of dependent base classes (#84050) Consider the following: ```cpp template<typename T> struct A { auto f() { return this->x; } }; ``` Although `A` has no dependent base classes and the lookup context for `x` is the current instantiation, we currently do not diagnose the absence of a member `x` until `A<T>::f` is instantiated. This patch moves the point of diagnosis for such expressions to occur at the point of definition (i.e. prior to instantiation).