Age | Commit message (Collapse) | Author | Files | Lines |
|
the codebase (#151356)
|
|
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs.
For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to
convenience method `DiagnosticIDs::create()`.
Part of cleanup https://github.com/llvm/llvm-project/issues/151026
|
|
|
|
Don't create a fix where object invoked on is a temporary object as
create method requires a reference.
|
|
check` (#147060)
`readability-qualified-auto` check currently looks at the unsugared
type, skipping any typedefs, to determine if the variable is a
pointer-type. This may not be the desired behaviour, in particular when
the type depends on compilation flags.
For example
```
#if CONDITION
using Handler = int *;
#else
using Handler = uint64_t;
#endif
```
A more common example is some implementations of `std::array` use
pointers as iterators.
This introduces the IgnoreAliasing option so that
`readability-qualified-auto` does not look beyond typedefs.
---------
Co-authored-by: juanbesa <juanbesa@devvm33299.lla0.facebook.com>
Co-authored-by: Kazu Hirata <kazu@google.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
|
|
check (#150842)
Resolves #150782.
|
|
|
|
Fix the regression introduced in #149148 that incorrectly explicitly
linked `clangTransformer` when dylib was used. As a result, the
executables linking to `clangTidyLLVMModule` would end up linking both
the dylib and a number of static clang libraries, leading to complete
mayhem and undecipherable segmentation faults.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
|
|
'clang-tidy-diff' (#149739)
Change the default value of `-j` from `1` to `0` in `clang-tidy-diff.py`
script to autodetect number of CPU cores to run on.
Script `run-clang-tidy.py` already had this behavior by default.
Both scripts now also print the number of threads being used to
provide better visibility into their execution behavior.
Fixes https://github.com/llvm/llvm-project/issues/148624.
|
|
functions (#142312)
These checks previously failed with absl::StrFormat and absl::PrintF
etc. with:
Unable to use 'std::format' instead of 'StrFormat' because first
argument is not a narrow string literal [modernize-use-std-format]
because FormatStringConverter was rejecting the format string if it had
already converted into a different type. Fix the tests so that they
check this case properly by accepting string_view rather than const char
* and fix the check so that these tests pass. Update the existing tests
that checked for the error message that can no longer happen.
Fixes: https://github.com/llvm/llvm-project/issues/129484
|
|
Upstream is moving towards new create method invocation, add check to flag old
usage that will be deprecated.
---------
Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
|
|
`bugprone-signed-char-misuse` (#149790)
Ignore false positives on C23 enums which allows setting the fixed
underlying type to signed char.
The AST tree for C enums includes a ImplicitCastExp
(that was matched) but this is not the case for C++ enums.
Fixes #145651
---------
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
|
|
Ignore pure virtual member functions in
portability-template-virtual-member-function check.
Those functions will be represented in vtable
as __cxa_pure_virtual or something similar.
Fixes #139031.
|
|
Performance optimization of misc-header-include-cycle
based on clangd test on Sema.cpp. Check were slow due
calls to SM.translateFile. Cost reduction (+-) from 11% to 3%.
|
|
`bugprone-unhandled-self-assignment` (#147066)
This change enhances the `bugprone-unhandled-self-assignment` checker by
adding an additional matcher that generalizes the copy-and-swap idiom
pattern detection.
# What Changed
Added a new matcher that checks for:
- An instance of the current class being created in operator=
(regardless of constructor arguments)
- That instance being passed to a `swap` function call
# Problem Solved
This fix reduces false positives in PMR-like scenarios where "extended"
constructors are used (typically taking an additional allocator
argument). The checker now properly recognizes copy-and-swap
implementations that use extended copy/move constructors instead of
flagging them as unhandled self-assignment cases.
Fixes #146324
---------
Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
|
|
structured bindings (#144213)
Before this patch, this check only handles `VarDecl` as varaibles
declaration in statement, but this will ignore variables in structured
bindings (`BindingDecl` in AST), which leads to false positives.
Closes #138842.
|
|
Add `NamespaceBaseDecl` as common base class of `NamespaceDecl` and
`NamespaceAliasDecl`. This simplifies `NestedNameSpecifier` a bit.
Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
|
|
`constinit` (#148334)
This check already understands how `constexpr` makes initialization
order problems impossible, and C++20's `constinit` provides the exact
same guarantees.
|
|
Previously it wasn't clear that passing this disables otherwise running
clang-tidy.
|
|
exception (#134375)
This PR add stacktrace of escaped exception to
`bugprone-exception-escape` check.
Changes:
1. Modified `ExceptionAnalyzer` and `ExceptionInfo` classes to hold
stacktrace of escaped exception in `llvm::MapVector`. `llvm::MapVector`
is needed to hold relative positions of functions in stack as well as
have fast lookup.
2. Added new diagnostics based of `misc-no-recursion` check.
Fixes https://github.com/llvm/llvm-project/issues/87422.
|
|
We're currently on Unicode 14.0.0. This PR updates it to Unicode 16.0.0.
|
|
'--dump-config' (#147142)
Added function to filter out `CheckOptions` that come from
`ClangTidyOptions::getDefaults()`, but does not have a corresponding
check enabled in the `Checks` configuration.
Fixes https://github.com/llvm/llvm-project/issues/146693.
|
|
`readability-use-concise-preprocessor-directives` (#146830)
Closes #132561.
This is a check that rewrites `#if`s and `#elif`s like so:
```cpp
#if defined(MEOW) // -> #ifdef MEOW
#if !defined(MEOW) // -> #ifndef MEOW
```
And, since C23 and C++23:
```cpp
#elif defined(MEOW) // -> #elifdef MEOW
#elif !defined(MEOW) // -> #elifndef MEOW
```
|
|
llvm-prefer-static-over-anonymous-namespace (#148357)
When having this code:
```cpp
namespace {
class MyClassOutOfAnon {
public:
MyClassOutOfAnon();
} // namespace
MyClassOutOfAnon::MyClassOutOfAnon() {}
```
`MyClassOutOfAnon::MyClassOutOfAnon` is located in anonymous namespace
in `DeclContext` but outside anonymous namespace in
`LexicalDeclContext`.
For this check to work correctly, we need to check if definition is
located inside `LexicalDeclContext`.
|
|
C++17's CTAD obsoletes `makeMatcher` (and many `make*` functions like
it).
The deduction guide is written out explicitly to avoid
`-Wctad-maybe-unsupported` warnings.
|
|
(#142839)
Finds function and variable declarations inside anonymous namespace and
suggests replacing them with ``static`` declarations.
The check will enforce that
[restrict-visibility](https://llvm.org/docs/CodingStandards.html#restrict-visibility)
rule in LLVM Coding Standards is followed correctly (by adding `static`
to functions instead of putting them in anonimous namespace).
The check has additional levels of "strictness" represented by Options.
By default, the check works in the most relaxed way by giving warning
only for methods and functions defined in anonymous namespaces. Also, It
finds `static` functions that are placed inside anonymous namespace -
there is no point in keeping them inside.
|
|
Added `.clang-tidy` config as discussed in
[RFC](https://discourse.llvm.org/t/rfc-create-hardened-clang-tidy-config-for-clang-tidy-directory/87247).
Added `bugprone`, `readability`, `modernize`, `performance` checks that
didn't create many warnings.
Fixed minor warnings to make `/clang-tidy` directory complaint with
`clang-tidy-20`.
Disabled checks will be enabled in future PRs after fixing their
warnings.
|
|
without comment (#147953)
Add InsertPlainNamesInForwardDecls option to readability-named-parameter
check to insert parameter names without comments for forward
declarations only.
When enabled, forward declarations get plain parameter names (e.g., `int
param`) while function definitions continue to use commented names
(e.g., `int /*param*/`). Named parameters in forward decls don't cause
compiler warnings and some developers prefer to have names without
comments but in sync between declarations and the definition.
Default behavior remains unchanged
(InsertPlainNamesInForwardDecls=false).
Example with InsertPlainNamesInForwardDecls=true:
```cpp
// Forward declaration - gets plain name because the definition has name.
void func(int param);
void func(int param) { ... = param; }
```
|
|
`modernize-pass-by-value` check (#141304)
Fixed false positives when class passed by const-reference had a private
move constructor, which could not be used for a fix-it.
Closes https://github.com/llvm/llvm-project/issues/140236.
|
|
```cpp
for (std::string OptionName : {
#define GET_CHECKER_OPTIONS
#define CHECKER_OPTION(TYPE, CHECKER, OPTION_NAME, DESCRIPTION, DEFAULT, \
RELEASE, HIDDEN) \
Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),
#include "clang/StaticAnalyzer/Checkers/Checkers.inc"
#undef CHECKER_OPTION
#undef GET_CHECKER_OPTIONS
}) {
Result.Options.insert(OptionName);
}
```
This code is doing a lot of unnecessary work at runtime. For each of the
(currently) 59 checker options, it runs
`Twine(AnalyzerCheckNamePrefix).concat(CHECKER ":" OPTION_NAME).str(),`,
which allocates a string (all of this is unrolled, leading to code
bloat). Then it copies all those strings (because `std::string
OptionName`, not `const std::string& OptionName`). All of this can be
done at compile time!
|
|
These new traits come from various standard versions:
C++14:
- `tuple_element_t`
C++17:
- `is_placeholder_v`
- `is_bind_expression_v`
- `ratio_equal_v`
- `ratio_not_equal_v`
- `ratio_less_v`
- `ratio_less_equal_v`
- `ratio_greater_v`
- `ratio_greater_equal_v`
- `is_error_code_enum_v`
- `is_error_condition_enum_v`
- `is_execution_policy_v`
- `tuple_size_v`
- `variant_size_v`
- `uses_allocator_v`
- `variant_alternative_t`
C++20:
- `compare_three_way_result_t`
- `common_comparison_category_t`
- `unwrap_ref_decay_t`
- `unwrap_reference_t`
C++23:
- `is_implicit_lifetime_v`
C++26:
- `is_nothrow_relocatable_v`
- `is_replaceable_v`
- `is_trivially_relocatable_v`
- `is_virtual_base_of_v`
This doesn't add `treat_as_floating_point_v` or `is_clock_v` because
they require more invasive changes; instead I've opened #147072 to track
them.
|
|
(#147301)
Some of these are even global mutable state — probably not what was
intended!
```cpp
static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
```
|
|
This patch addresses missing support for forwarding `ak_attr_info`
diagnostic arguments in `ClangTidyDiagnosticConsumer`
|
|
This fixes an issue compiling LLVM 20.1.7 on Ubuntu 22.04 with the
Ubuntu provided Clang 14 and C++20. That's probably happening due to
incomplete C++20 support in either Clang 14 or the GNU libstdc++ 12.
The actual error is:
```
[1/8] Building CXX object tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o
FAILED: tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o
/usr/lib/llvm-14/bin/clang++ -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/work/_build/tools/clang/tools/extra/clang-tidy/bugprone -I/work/llvm-project/clang-tools-extra/clang-tidy/bugprone -I/work/_build/tools/clang/tools/extra/clang-tidy -I/work/llvm-project/clang/include -I/work/_build/tools/clang/include -I/work/_build/include -I/work/llvm-project/llvm/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -std=c++20 -fno-exceptions -funwind-tables -fno-rtti -MD -MT tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o -MF tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o.d -o tools/clang/tools/extra/clang-tidy/bugprone/CMakeFiles/obj.clangTidyBugproneModule.dir/TaggedUnionMemberCountCheck.cpp.o -c /work/llvm-project/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp
/work/llvm-project/clang-tools-extra/clang-tidy/bugprone/TaggedUnionMemberCountCheck.cpp:148:39: error: use of overloaded operator '==' is ambiguous (with operand types 'llvm::APSInt' and 'unsigned long')
(LastEnumConstant->getInitVal() == (EnumValues.size() - 1))) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~
/work/llvm-project/llvm/include/llvm/ADT/APInt.h:2080:13: note: candidate function (with reversed parameter order)
inline bool operator==(uint64_t V1, const APInt &V2) { return V2 == V1; }
^
/work/llvm-project/llvm/include/llvm/ADT/APSInt.h:188:8: note: candidate function
bool operator==(int64_t RHS) const {
^
/work/llvm-project/llvm/include/llvm/ADT/APSInt.h:357:13: note: candidate function (with reversed parameter order)
inline bool operator==(int64_t V1, const APSInt &V2) { return V2 == V1; }
^
1 error generated.
```
I know that clang-14 in combination with the GNU libstdc++ 12 might not
be 100% C++20 compliant. But this is the only error we see when
compiling LLVM 20.1.7 and it looks very fixable
Thanks,
Gregor
---------
Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
|
|
The static analyzer we use internally complains about potential
dereference of `nullptr` for `Found`. I think both `Found` and `Member`
can't be null here (please confirm). I have added assertions.
|
|
`misc-unconventional-assign-operator` check (#143292)
Fix false positives when copy assignment operator function in a template
class returns the result of another assignment to `*this`, this check
doesn't consider this situation that there will be a `BinaryOperator`
for assignment rather than `CXXOperatorCallExpr` since `this`'s type is
dependent.
Closes #143237.
|
|
`cppcoreguidlines-pro-bounds-pointer-arithmetic` check (#139430)
Fixed false negatives with type aliases in
`cppcoreguidlines-pro-bounds-pointer-arithmetic` check.
Added tests with pointer arithmetic in template functions to make test
cases more robust.
Closes https://github.com/llvm/llvm-project/issues/139241.
|
|
The comment for `DiagnosticConsumer::BeginSourceFile()` states that
"diagnostics with source range information are required to only be
emitted in between BeginSourceFile() and EndSourceFile().". While
working on some upcoming changes to the static analyzer, we hit some
crashes when diagnostics were reported from the `EndOfMainFile` callback
in the preprocessor. This turned out to be because
`FrontEndAction::EndSourceFile()` notifies the diagnostic clients of the
end of the source file before it notifies the preprocessor. Thus, the
diagnostics from the preprocessor callback are reported when the
diagnostic client is no longer expecting any diagnostics.
The fix is to swap the order of the `EndSourceFile()` calls so that the
preprocessor is notified first.
I've added asserts to the `ClangTidyDiagnosticConsumer` to catch
unexpected diagnostics outside of a source file. Before swapping the
order of the calls as described above, this causes several failures in
the clang-tidy regression tests. With the swap, there are no failures in
`check-all`.
rdar://141230583
|
|
cppcoreguidelines-pro-bounds-pointer-arithmetic (#127394)
this PR fixes #126424
for `ArraySubScriptExpr`, `hasBase` Matcher will get right operand when
it is not integer type, but is not for sure that left operand is integer
type. For the example code below `hasBase` will get `r` for the
Subsequent matching and causing false positive.
```
template <typename R>
int f(std::map<R*, int>& map, R* r) {
return map[r];
}
```
so is needed to see if index is integer type to avoid this situation.
|
|
(#130369)
Optimizations:
- Only build the skeleton for each identifier once, rather than once for
each declaration of that identifier.
- Only compute the contexts in which identifiers are declared for
identifiers that have the same skeleton as another identifier in the
translation unit.
- Only compare pairs of declarations that are declared in related
contexts, rather than comparing all pairs of declarations with the same
skeleton.
Also simplify by removing the caching of enclosing `DeclContext` sets,
because with the above changes we don't even compute the enclosing
`DeclContext` sets in common cases. Instead, we terminate the traversal
to enclosing `DeclContext`s immediately if we've already found another
declaration in that context with the same identifier. (This optimization
is not currently applied to the `forallBases` traversal, but could be
applied there too if needed.)
This also fixes two bugs that together caused the check to fail to find
some of the issues it was looking for:
- The old check skipped comparisons of declarations from different
contexts unless both declarations were type template parameters. This
caused the checker to not warn on some instances of the CVE it is
intended to detect.
- The old check skipped comparisons of declarations in all base classes
other than the first one found by the traversal. This appears to be an
oversight, incorrectly returning `false` rather than `true` from the
`forallBases` callback, which terminates traversal.
This also fixes an issue where the check would have false positives for
template parameters and function parameters in some cases, because those
parameters sometimes have a parent `DeclContext` that is the parent of
the parameterized entity, or sometimes is the translation unit. In
either case, this would cause warnings about declarations that are never
visible together in any scope.
This decreases the runtime of this check, especially in the common case
where there are few or no skeletons with two or more different
identifiers. Running this check over LLVM, clang, and clang-tidy, the
wall time for the check as reported by clang-tidy's internal profiler is
reduced from 5202.86s to 3900.90s.
|
|
cppcoreguidelines-rvalue-reference-param-not-moved (#138757)
Since std::move is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of <utility>.
Added flag (MoveFunction) provides a way to continue using this
essential check even with the custom implementation of moving.
---------
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
|
|
Since std::forward is nothing more than a cast, part of STL and not the
language itself, it's easy to provide a custom implementation if one
wishes not to include the entirety of <utility>.
Added flag (ForwardFunction) provides a way to continue using this
essential check even with the custom implementation of forwarding.
---------
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
|
|
Add new clang-tidy check that finds uses of `std::lock_guard` and suggests
replacing them with C++17's more flexible and safer alternative
`std::scoped_lock`.
Here is a small description of how it works for better understanding of
the code:
Two separate AST matchers are registered:
- The first one matches declarations of `std::lock_guard` that are
single in their scope (only one `std::lock_guard` in `CompoundStmt`).
It's an easy case, we can emit warning right away.
- The second one matches `CompoundStmt`'s that have multiple
`std::lock_guard` declarations, which means that we may have consecutive
declarations of `std::lock_guard` that can be replaced by a single
`std::scoped_lock`. In order to ensure that declarations are
consecutive, we need to loop over `Stmt`'s in `CompoundStmt`. Here is a
small example:
```cpp
{
std::mutex m1, m2;
std::lock(m1, m2);
std::lock_guard<std::mutex> l1(m, std::adopt_lock); // first declaration of 'std::lock_guard'
std::lock_guard<std::mutex> l2(m, std::adopt_lock); // second declaration of 'std::lock_guard' that can be merged with first using 'scoped_lock'
}
```
This PR closes https://github.com/llvm/llvm-project/issues/107839.
|
|
(#135391)
The out-of-line explicitly-defaulted definition is not the first
declaration, so it is not implicitly inline.
Alt. reference:
9.5.2 (3) Explicitly-defaulted functions in
[N4950](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/n4950.pdf).
or https://timsong-cpp.github.io/cppwp/n4861/dcl.fct.def.default#3
Fixes #130745
---------
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
|
|
This patch fixes:
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp:371:26:
error: variable 'E' set but not used
[-Werror,-Wunused-but-set-variable]
|
|
The sizeof operator misuses in loop conditionals can be a source of
bugs. The common misuse is attempting to retrieve the number of elements
in the array by using the sizeof expression and forgetting to divide the
value by the sizeof the array elements. This results in an incorrect
computation of the array length and requires a warning from the sizeof
checker.
Example:
```
int array[20];
void test_for_loop() {
// Needs warning.
for(int i = 0; i < sizeof(array); i++) {
array[i] = i;
}
}
void test_while_loop() {
int count = 0;
// Needs warning.
while(count < sizeof(array)) {
array[count] = 0;
count = count + 2;
}
}
```
rdar://151403083
---------
Co-authored-by: MalavikaSamak <malavika2@apple.com>
|
|
(#143550)
|
|
Reverts llvm/llvm-project#127430 due to stable asan buildbot failures:
https://lab.llvm.org/buildbot/#/builders/169
|
|
|
|
The adds a check that replaces specific numeric literals like `32767`
with the equivalent call to `std::numeric_limits` (such as
`std::numeric_limits<int16_t>::max())`.
Partially addresses #34434, but notably does not handle cases listed in
the title post such as `~0` and `-1`.
|