10566 Commits

Author SHA1 Message Date
Harald-R
d51ce3406a [clangd] Use resolved path when checking AngledHeaders/QuotedHeaders in IncludeInserter (#148371)
This makes IncludeInserter's behavior consistent with include-cleaner,
as discussed in https://github.com/llvm/llvm-project/pull/140594.

(cherry picked from commit ff0093cecd0c807d122cfb6b74634074c962ade9)
2025-08-08 12:17:01 +02:00
Nathan Ridge
d1f761c8d7 [clangd] Add clangd 21 release notes 2025-08-08 12:12:15 +02:00
Victor Chernyakin
92ef8e3419
[clang-tidy] Teach cppcoreguidelines-interfaces-global-init about constinit (#148334)
This check already understands how `constexpr` makes initialization
order problems impossible, and C++20's `constinit` provides the exact
same guarantees.
2025-07-15 00:10:10 +03:00
Keith Smiley
455105f1c6
[clang-tidy] Improve --verify-config documentation (#148699)
Previously it wasn't clear that passing this disables otherwise running
clang-tidy.
2025-07-14 13:16:05 -07:00
Baranov Victor
6ac286cd49
[clang-tidy] Improve bugprone-exception-escape: add stacktrace of escaped 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.
2025-07-14 21:59:28 +03:00
Victor Chernyakin
4328b69df6
[clang-tidy] Update confusables.txt in misc-confusable-identifiers (#148399)
We're currently on Unicode 14.0.0. This PR updates it to Unicode 16.0.0.
2025-07-14 21:05:33 +03:00
Baranov Victor
b56aebaf82
[clang-tidy] Add filtering of check options by enabled checks in '--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.
2025-07-13 23:44:30 +03:00
Victor Chernyakin
59b39c0031
[clang-tidy] Add new check: 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
```
2025-07-13 19:23:27 +03:00
Baranov Victor
45f7285d0e
[clang-tidy] Use lexical anon-ns matcher in 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`.
2025-07-12 20:05:05 +03:00
Yanzuo Liu
c4cc3573d1
[Clang][AST][NFC] (RecordDecl -> CXXRecordDecl)::isInjectedClassName (#148195)
Move `RecordDecl::isInjectedClassName` to
`CXXRecordDecl::isInjectedClassName`. C language doesn't have the term
"injected class name".

Co-authored-by: Matheus Izvekov <mizvekov@gmail.com>
2025-07-12 21:13:30 +08:00
Sirraide
7b43c6c6a7
Revert "[Clang] [Diagnostics] Simplify filenames that contain '..'" (#148367)
Revert llvm/llvm-project#143520 for now since it’s causing issues for
people who are using symlinks and prefer to preserve the original path
(i.e. looks like we’ll have to make this configurable after all; I just
need to figure out how to pass `-no-canonical-prefixes` down through the
driver); I’m planning to refactor this a bit and reland it in a few
days.
2025-07-12 15:13:22 +02:00
Baranov Victor
bd7a6bfdf4
[clang-tidy][NFC] fixed invalid formatting in 'ReleaseNotes.rst' (#148352) 2025-07-12 15:57:25 +03:00
Victor Chernyakin
4326f68acb
[ASTMatchers][NFC] Replace makeMatcher function with CTAD (#147197)
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.
2025-07-12 14:12:02 +03:00
Baranov Victor
2f4a804e6e
[clang-tidy] Add new check llvm-prefer-static-over-anonymous-namespace (#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.
2025-07-12 09:56:30 +03:00
Erick Velez
94bb9e12ec
[clang-doc] Serialize record files with mangled name (#148021)
This patch changes JSON file serialization. Now, files are serialized
to a single directory instead of nesting them based on namespaces. The
global namespace retains the "index.json" name.

This solves the problem of class template specializations being serialized to the
same file as its base template. This is also planned as part of
future integration with the Mustache generator which will consume the JSON files.
2025-07-11 13:39:41 -07:00
Baranov Victor
d7a17540f8
[clang-tidy][NFC] add '.clang-tidy' config for clang-tidy project (#147793)
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.
2025-07-11 17:17:59 +03:00
Dmitry Polukhin
a61ea9fd9b
[clang-tidy] Add an option in 'readability-named-parameter' to print names 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; }
```
2025-07-11 11:51:20 +01:00
Chuanqi Xu
aa9902691d [NFC] [clangd] [Modules] Logging more if compilation failed
Coming from internal using experience.

The original log is just confusing... Users can't understand it unless
he reads the code.

This patch tries to make this more understandable.

Note that the mentioned module files in the logs might be removed
intentionally. We need another option to allow users to remain these
module files. Let's done this in another patch.
2025-07-11 11:18:21 +08:00
Aiden Grossman
896575eb74
[clang] Prefer clang_setup over use_clang
This patch switches over uses of use_clang to clang_setup to fix a
potential race condition that has been impacting CI.

This is split from the refactoring to ensure I'm not missing anything
major here on the clang-tools-extra side.

This should fix #145703.

Reviewers: AaronBallman, HighCommander4, HerrCai0907, petrhosek, Keenuts

Reviewed By: petrhosek

Pull Request: https://github.com/llvm/llvm-project/pull/147437
2025-07-10 06:14:06 -07:00
Baranov Victor
66316657ab
[clang-tidy] properly handle private move constructors in 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.
2025-07-09 19:05:34 +03:00
Victor Chernyakin
b041a58989
[clang-tidy][NFC] concat static-analyzer name at compilation time (#147406)
```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!
2025-07-09 20:05:42 +08:00
Victor Chernyakin
fbc4255ffc
[clang-tidy] Teach modernize-type-traits about more type traits (#147074)
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.
2025-07-09 08:21:40 +03:00
Victor Chernyakin
1e3f6a6c4f
[clang-tidy][NFC] Prefer constexpr llvm::StringLiteral over const char * (#147301)
Some of these are even global mutable state — probably not what was
intended!
```cpp
static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
```
2025-07-08 20:48:51 +03:00
Oleksandr T.
0ff01ef9d4
[clang-tidy] support ak_attr_info in diagnostic forwarding (#147503)
This patch addresses missing support for forwarding `ak_attr_info`
diagnostic arguments in `ClangTidyDiagnosticConsumer`
2025-07-08 15:08:42 +03:00
Gregor Jasny
4d07c7f9a0
[clang-tidy][NFC] fix compilation by disambiguating equality operator (#147048)
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>
2025-07-08 11:08:45 +03:00
Sirraide
e3e7393c46
[Clang] [Diagnostics] Simplify filenames that contain '..' (#143520)
This can significantly shorten file paths to standard library headers,
e.g. on my system, `<ranges>` is currently printed as
```console
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/ranges
```
but with this change, we instead print
```console
/usr/include/c++/15/ranges
```

This is of course just a heuristic; there are paths that would get longer
as a result of this, so we use whichever path ends up being shorter.

@AaronBallman pointed out that this might be problematic for network
file systems since path resolution might take a while, so this is enabled 
only for paths that are part of a local filesystem—though not on Windows
since there we noticed that the check itself is slow.

The file names are cached in `SourceManager`.
2025-07-08 01:02:19 +02:00
Zahira Ammarguellat
f34de0a14f
[clang-tidy] [NFC] Potential dereference of nullptr. (#143145)
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.
2025-07-07 06:57:51 -04:00
Nathan Ridge
0860f7aaeb
[clangd][NFC] fix broken documentation link (#147088) 2025-07-07 05:08:49 -04:00
flovent
6c153e50f8
[clang-tidy] Fix false positives with template in 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.
2025-07-06 15:06:18 +03:00
Nathan Ridge
e64289baa0
[clang][Sema] Unify getPrototypeLoc helpers in SemaCodeComplete and clangd (#143345)
HeuristicResolver houses the unified implementation.

Fixes https://github.com/llvm/llvm-project/issues/143240
2025-07-05 10:59:16 -04:00
Baranov Victor
5a9e6babd8
[clang-tidy] fix false negatives with type aliases in 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.
2025-07-04 09:49:26 +03:00
Dave Bartolomeo
85aaaf6e74
[clang-tidy] EndSourceFile() for preprocessor before diagnostic client (#145784)
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
2025-07-04 12:36:57 +08:00
Erick Velez
0a02c28e29
[clang-doc] add namespace references to VarInfo (#146964)
VarInfo was missing its addReference specialization. This causes errors
when a VarInfo is inside a namespace that isn't the global namespace.
2025-07-03 15:50:23 -07:00
Kazu Hirata
0f1accd806
[clangd] Drop const from a return type (NFC) (#146707)
We don't need const on the return type.
2025-07-02 09:32:23 -07:00
flovent
5a8d096ae3
[clang-tidy] Fix false positive for 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.
2025-07-02 17:41:24 +03:00
Kazu Hirata
838b91d7f6
[clangd] Drop const from a return type (NFC) (#146623)
We don't need const on a return type.
2025-07-01 22:49:56 -07:00
Richard Smith
c56c349d39
[clang-tidy] Switch misc-confusable-identifiers check to a faster algorithm. (#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.
2025-07-01 13:31:46 -07:00
Ilya Biryukov
cf9374933d [Modularize] Make Location::operator bool explicit
This unbreaks C++20 buildbot that was broken since
402baea0a9ff7894565449e41f700c4e6a3f99cb.

With implicit conversion in C++20 compilation mode the spaceship
will unintentionally be based on `operator bool`:

```cpp
auto foo(Location L, Location R) {
  return L <=> R;
  // Equivalent to the following line due to implicit conversions.
  // return L.operator bool() <=> R.operator bool();
}
```

The spaceship operator is rarely used explicitly, but its implicit uses
in the STL may cause surprising results, as exposed by the use of  `std::tie`
in 402baea0a9ff7894565449e41f700c4e6a3f99cb, which ended up changing the
comparisons results unintentionally.
2025-07-01 16:38:07 +02:00
Mythreya
d9d9ab8698
[clang][CodeComplete] skip explicit obj param in code completion string (#146258)
Fixes clangd/clangd#2339
2025-07-01 08:33:56 -04:00
Haojian Wu
2ee884a9db [clang-doc] Remove the unused clangd header.
This header seems to be included unintentionally.
2025-07-01 12:07:35 +02:00
Erick Velez
a68e4470c1
[clang-doc] serialize friends (#146165)
Parse friends into a new FriendInfo and serialize them in JSON. We keep track of the friend declaration's template and function information if applicable.
2025-06-30 12:43:52 -07:00
Dimitrije Dobrota
0f291e5787
[clang-tidy] Add flag to specify an alternative to std::move in 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>
2025-06-30 22:36:23 +03:00
Dimitrije Dobrota
6a57af8d03
[clang-tidy] Add flag to specify an alternative to std::forward (#138755)
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>
2025-06-30 22:13:33 +03:00
Erick Velez
ba84d0c8d7
[clang-doc] Precommit friends test (#146164) 2025-06-30 11:47:09 -07:00
Baranov Victor
a3a60e03e2
[clang-tidy] add new check: modernize-use-scoped-lock (#126434)
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.
2025-06-29 22:34:32 +03:00
Mythreya
d2d5203bf4
[clangd] Consistent precedence between --header-insertion and HeaderInsertion (#146235)
In PR #128503, the CLI option would take precedence over the config option
only if it was set to `never`. This commit ensures the CLI option always takes
precedence over the config option.
2025-06-29 10:47:49 -04:00
Kazu Hirata
402baea0a9
[modularize] Use std::tie to implement operator< (NFC) (#146220)
std::tie clearly expresses the intent while slightly shortening the
code.
2025-06-28 13:04:00 -07:00
Björn Svensson
8351752dbc
[clang-tidy] Fix false positives in readability-redundant-inline-specifier (#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>
2025-06-28 09:10:34 +03:00
Erick Velez
6d817810da
[clang-doc] serialize IsBuiltIn and IsTemplate for types (#146149)
IsBuiltIn and IsTemplate were being emitted as their default values.
2025-06-27 16:17:39 -07:00
Erick Velez
ab1e4d55d8
[clang-doc] refactor BitcodeReader::readSubBlock (#145835)
Reduce boilerplate code in readSubBlock by creating a callable from a higher-order lambda based on the block's add need.
2025-06-26 20:44:14 -07:00