Commit Graph

10485 Commits

Author SHA1 Message Date
David Rivera
e65d323166 [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (#134188)
Aims to fix #127471
Covered the edge case where an int expression is not necessarily
directly wrapped around an 'ImplicitCastExpr' which seemed to be a
requirement in 'use-integer-sign-comparison.cpp' check to trigger.

**For instance**:

```cpp
#include <vector>

bool f() {
  std::vector<int> v;
  unsigned int i = 0;

  return i >= v.size();
}
```
2025-06-10 10:57:11 +03:00
Baranov Victor
5213c57cb1 [clang-tidy][NFC] run clang-format over clang-tidy checks and tool code. (#143324) 2025-06-09 21:54:48 +03:00
Nathan Ridge
392bd577e3 [clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints (#143087)
Fixes https://github.com/llvm/llvm-project/issues/142608
2025-06-09 00:33:20 -04:00
Kazu Hirata
240ff854ad [clangd] Use llvm::find (NFC) (#143317) 2025-06-08 16:18:16 -07:00
Baranov Victor
68070f908b [clang-tidy][NFC] run clang-format over 'cert', 'cppcore', 'fuchsia',… (#143316)
… 'google' checks
2025-06-08 23:22:55 +03:00
Baranov Victor
ce46adb8b7 [clang-tidy][NFC] run clang-format over 'android', 'boost' and 'bugprone' checks (#143315) 2025-06-08 23:22:05 +03:00
Baranov Victor
65d66625b3 [clang-tidy][NFC] run clang-format over abseil and altera checks. (#143314) 2025-06-08 23:21:35 +03:00
Baranov Victor
55c86c5f77 [clang-tidy][NFC] fix formatting of namespace-comment-check (#143305)
Fixed formatting and codestyle issues in `namespace-comment-check`

Follow up to https://github.com/llvm/llvm-project/pull/124265.
2025-06-08 13:51:17 +02:00
Thorsten Klein
00eb22fff9 added option google-readability-namespace-comments.AllowNoNamespaceComments (#124265)
New option AllowNoNamespaceComments for
`google-readability-namespace-comments.AllowNoNamespaceComments` is
added.

When true, the check will allow that no namespace comment is present. If
a namespace comment is added but it is not matching, the check will
fail. Default is `false`

Fixes #124264
2025-06-08 13:19:40 +03:00
Kazu Hirata
6edfc6ce6c [clang-tools-extra] Use llvm::any_of (NFC) (#143281) 2025-06-08 01:34:24 -07:00
Kazu Hirata
0613f8b9e4 [clang-move] Teach getDeclarationList to return ArrayRef (NFC) (#143278)
getDeclarationList is used only for read-only access to the array.  I
don't think it's actually meant to return by value.
2025-06-08 01:34:02 -07:00
flovent
239c8ac268 [clang-tidy] Fix false positives with deducing this in readability-convert-member-functions-to-static check (#141391)
Add check for `DeclRefExpr` which points to an explicit object
parameter.

Fixes #141381.

---------

Co-authored-by: fubowen <fubowen@protomail.com>
Co-authored-by: flovent <flbven@protomail.com>
2025-06-08 09:58:24 +03:00
Carlos Galvez
30d8aebbe2 [clang-tidy] Add option to disable bugprone-multi-level-pointer-conversion in C code (#141209)
Sometimes a project may want to enable this check only in C++, and
disable it in C, since the patterns the check warns about are quite
common and idiomatic in C, and there are no better alternatives.
    
Fixes #140659

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-06-07 21:52:23 +02:00
Samarth Narang
d5704097fc Refactor clang doc comment structure (#142273)
This patch refactors CommentKind handling in clang-doc by introducing a
strongly typed enum class for better type safety and clarity. It updates
all relevant places, including YAML traits and serialization, to work
with the new enum. Additionally, it enhances the Mustache-based HTML
generation by fully supporting all comment kinds, ensuring accurate
structured rendering of comment blocks. The changes simplify future
maintenance, improve robustness by eliminating unchecked defaults, and
ensure consistency between generators.

Fixes https://github.com/llvm/llvm-project/issues/142083
2025-06-07 08:04:56 -07:00
Baranov Victor
0f03f8ab2e [clang-tidy] Add support for lambda-expression in use-trailing-return-type check (#135383)
Add support for lambda-expression in `use-trailing-return-type` check.

Added two new options:
1. `TransformFunctions` will trigger function declarations to use
trailing return type.
2. `TransformLambdas` will trigger lambda expression to use trailing
return type if it was not stated explicitly.

Fixed false positives when lambda was matched as a function in C++11
mode.

Closes https://github.com/llvm/llvm-project/issues/95711
2025-06-06 10:46:41 +03:00
fleeting-xx
93b0bf635a [clangd] [Modules] Fix to correctly handle module dependencies (#142828)
This is a re-application of llvm/llvm-project#142090 without the unit
test changes. A subsequent PR will follow that adds a unit test for
module dependencies.

### Changes
- Fix dangling string references in the return value of
getAllRequiredModules()
- Change a couple of calls in getOrBuildModuleFile() to use the loop
variable instead of the ModuleName parameter.

@ChuanqiXu9 for review
2025-06-06 09:33:11 +08:00
Aaron Puchert
8641a2cf99 Fix cross-references in Clang attribute reference (#142967)
Anchors are automatically generated, but adding another anchor with the
same name hides the anchor that we actually want. Simply removing the
unnecessary self-referential anchor `lifetimebound` fixes the links.

The documentation for coro_disable_lifetimebound and coro_lifetimebound
also had an unnecessary redirection. It's possible to change the link
text to differ from the heading, but I think that's not necessary here.

Also fix a reference in clang-tidy that was using the (unstable)
numbered anchor.
2025-06-05 18:17:49 +02:00
Nick Sarnie
3b9ebe9201 [clang] Simplify device kernel attributes (#137882)
We have multiple different attributes in clang representing device
kernels for specific targets/languages. Refactor them into one attribute
with different spellings to make it more easily scalable for new
languages/targets.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-06-05 14:15:38 +00:00
flovent
a12f4f0031 [clang-tidy] Add check for assignment or comparision operators' operand in readability-math-missing-parentheses (#141345)
Fixes false negative in #141249. 

Add check for math binary operators which are operands of assignment or
comparision operators.

Closes #141249.
2025-06-05 15:18:01 +03:00
Harald-R
7df458b473 Follow style configuration in clangd when inserting missing includes (#140594)
The missing include diagnostic has the capability to introduce the
necessary headers into the source file. However, it does not currently
follow the inclusion style found in the `.clangd` file. For example, if
the file explicitly mentions that headers should be include with angled
brackets, they could be included with quotes instead. More details in
https://github.com/llvm/llvm-project/issues/138740. This PR fixes this
gap, so that the style configuration is followed.
2025-06-05 11:36:01 +02:00
Kazu Hirata
86f8be6a7c [clang-tools-extra] Remove unused local variables (NFC) (#142881) 2025-06-04 22:43:59 -07:00
Erick Velez
8a905baeb4 [clang-doc] add tags to Mustache namespace template (#142045)
namespace-template.mustache only rendered placeholder text. Enum and
record tags were added to the template. Now, we can render an index.html
for the global namespace and other namespaces.

Added tests and deleted some of the disabled unit tests.
2025-06-04 10:09:36 -07:00
Paul Kirth
89cea0d26d [clang-doc] Fix brittle check in test (#142665)
Instead of having a platform specific error diagnostic, use a fixed one
with more direct context for the error.
2025-06-04 09:47:22 -07:00
Matheus Izvekov
c95189f877 [clang-tidy] NFCI: remove non-functional matcher from SizeofExpressionCheck (#142654)
This matcher would never match anything, because all record types
as-written would be wrapped in an ElaboratedType.

Just fixing that leads to a matcher which has too many false positives
to be useful.

The warning message itself is not great either, it has a hard-coded type
name.
2025-06-04 09:26:09 +02:00
Paul Kirth
a56861777a [clang-doc] Reenable time trace support (#141139)
This patch re-enables -ftime-trace support in clang-doc. Initial support
in #97644 was reverted, and never relanded. This patch adds back the
command line option, and leverages the RAII tracing infrastructure more
thoroughly.
2025-06-03 09:56:25 -07:00
Martin Storsjö
67fa6ea7d4 [clang-doc] [test] Generalize error message patterns (#142373)
On Windows, we hit the "no such file or directory" case, not the "Not a
directory" one.

MS STL produces the "no such file or directory" message for
`std::error_code(ENOENT, std::generic_category()).message()`, while
libc++ and libstdc++ produce a similar message with a capital N.

Adjust the error message regex to match for either of them.

That said, this kind of test is very brittle with respect to
portability.
2025-06-03 19:44:55 +03:00
Paul Kirth
b76b3f3b39 [clang-doc] Add test case for #141990 (#142209)
When we landed the fix for the assertion in #141990, we hadn't yet
reduced the test case sufficiently for a regression test.
2025-06-03 09:38:18 -07:00
MarcoFalke
fa36822bfb NFC: fix typo in tidy modernize-deprecated-headers docs 2025-06-03 12:25:01 +02:00
Nathan Ridge
ed14e0da77 [clangd] Log the paths of loaded config files without --log=verbose (#142063)
Users sometimes forget about configuration they've placed in the user
config file, or an ancestor directory of their project.

Logging the paths of loaded config files by default (without
--log=verbose) surfaces more readily where clangd is getting its
configuration from.
2025-05-30 22:31:12 -04:00
fleeting-xx
278ef84d20 Revert "[clangd] [Modules] Fixes to correctly handle module dependencies" (#142162) 2025-05-31 09:21:50 +08:00
Paul Kirth
f1886b1d6d [cmake][clang-tools] Make split-file a dependency for tests (#142048)
clang-doc uses split-file in some tests. We didn't notice the missing
dep, since its always built before clang-tools-extra tests run in CI.
2025-05-30 16:02:43 -07:00
Samarth Narang
ff94ba613e [clang-doc] Refactor error handling to use ExitOnError (#141699)
This patch refactors the clang-doc tool to replace manual error handling
(e.g., checking error codes and calling exit()) with llvm::ExitOnError.

Fixes #140085
2025-05-30 13:34:15 -07:00
fleeting-xx
d490526a81 [clangd] [Modules] Fixes to correctly handle module dependencies (#142090)
Simple module import dependencies, see
[module_dependencies.test](https://github.com/llvm/llvm-project/compare/main...fleeting-xx:llvm-project:fix_clangd_dependent_modules#diff-5510681cbe5b7ed3a72c5e683184e83fa66e911e9abb0e6670b01b87b3ca7b1a),
were not being correctly handled due to a couple of issues.

- The `MDB.getRequiredModules()` call returned a
`std::vector<std::string>` and all `StringRefs` were to entries in that
temporary value. So the `StringRef` elements in
`getAllRequiredModules()`'s return value were bound to values that went
out of scope.
- `ModulesBuilder::ModulesBuilderImpl::getOrBuildModuleFile()` was
iterating over each module dependency name, but only using the original
module name and path for various checks and module compilation.

In addition to fixing the above issues I added support for Windows paths
in modules.test and added a new unit test, module_dependencies.test,
which demonstrates the failure in the previous state and works correctly
after the fixes have been applied.

Please let me know if I've missed anything.

Co-authored-by: Dan Baker <dan@requires.coffee>
2025-05-30 14:45:47 +08:00
Paul Kirth
ddc8db792a [clang-doc] Fix assertions error in Serialize.cpp (#141990)
We can only print and use a default arg, if it is instantiated.
I was unable to reduce the test case for this to something of reasonable
size, but this is easily hit by running clang-doc to generate clang's
documentation. For now, we can fix the assertion quickly to unbreak
users, and add the proper test once it is small enough.
2025-05-29 13:32:07 -07:00
Erick Velez
260836d917 [clang-doc] fix FileCheck for conversion function HTML test (#141976)
The HTML FileCheck was missing the RUN command. Fixing that revealed an
error in the HTML check.
2025-05-29 17:56:17 +00:00
Krzysztof Parzyszek
11e804fcab [clang-doc] Fix build break with BUILD_SHARED_LIBS=ON
The error message:

/usr/bin/ld: CMakeFiles/clang-doc.dir/ClangDocMain.cpp.o: undefined refe
rence to symbol '_Z20getMustacheHtmlFilesN4llvm9StringRefERN5clang3doc15
ClangDocContextE' /usr/bin/ld: /work/kparzysz/git/llvm.org/b/x86/./lib/l
ibclangDocSupport.so.21.0git: error adding symbols: DSO missing from com
mand line
collect2: error: ld returned 1 exit status
make[2]: *** [tools/clang/tools/extra/clang-doc/tool/CMakeFiles/clang-do
c.dir/build.make:107: bin/clang-doc] Error 1
2025-05-28 08:13:31 -05:00
Paul Kirth
1ad5783c07 [clang-doc] Track if a type is a template or builtin (#138067)
Originally part of #133161. This patch adds preliminary tracking
for of TypeInfo, by tracking if the type is a builtin or template.

The new functionality is not yet exercised.

Co-authored-by: Peter Chou <peter.chou@mail.utoronto.ca>
2025-05-27 22:28:56 -07:00
Paul Kirth
79023dbdb3 [clang-doc] Update clang-doc tool to enable mustache templates (#138066)
This patch adds a command line option and enables the Mustache template
HTML backend. This allows users to use the new, more flexible templates
over the old and cumbersome HTML output. Split from #133161.

Co-authored-by: Peter Chou <peter.chou@mail.utoronto.ca>
2025-05-27 22:25:45 -07:00
Paul Kirth
3cd8924c31 [clang-doc] Update serializer for improved template handling (#138065)
This patch updates Serialize.cpp to serialize more data about C++
templates, which are supported by the new mustache HTML template.
Split from #133161.

Co-authored-by: Peter Chou <peter.chou@mail.utoronto.ca>
2025-05-27 22:22:47 -07:00
FabianWolff
317f3bdcc1 [clang-tidy] Fix formatting and add release notes entry (#141584)
Follow-up to #141092.
2025-05-27 21:52:59 +02:00
FabianWolff
47d5e94acb [clang-tidy] readability-redundant-smartptr-get: disable for smart pointers to arrays (#141092)
Currently we generate an incorrect suggestion for shared/unique pointers
to arrays; for instance ([Godbolt](https://godbolt.org/z/Tens1reGP)):
```c++
#include <memory>

void test_shared_ptr_to_array() {
  std::shared_ptr<int[]> i;
  auto s = sizeof(*i.get());
}
```
```
<source>:5:20: warning: redundant get() call on smart pointer [readability-redundant-smartptr-get]
    5 |   auto s = sizeof(*i.get());
      |                    ^~~~~~~
      |                    i
1 warning generated.
```
`sizeof(*i)` is incorrect, though, because the array specialization of
`std::shared/unique_ptr` does not have an `operator*()`. Therefore I
have disabled this check for smart pointers to arrays for now; future
work could, of course, improve on this by suggesting, say,
`sizeof(i[0])` in the above example.
2025-05-27 12:06:08 +02:00
Tommy Chen
4cb25e2d37 [clang-tidy] Add avoid-pragma-once. (#140388)
#139618
2025-05-27 05:57:51 +08:00
Congcong Cai
f1d8e37f2c [NFC][clangd][test] add clang-tidy config to ensure test cases sandbox (#141410)
Under previous test setup, the test result will be influenced by
clang-tidy file in parent folder (between llvm-projects root and build
folder). It is inconventient and leads some confusion.
This PR wants to ensure sandbox to avoid outside's clang-tidy influenece
test result.
2025-05-27 05:56:48 +08:00
Baranov Victor
ac0a880f4e [clang-tidy] added AllowedTypes option to readability-qualified-auto check (#136571)
Added `AllowedTypes` option to `readability-qualified-auto` check

Fixes https://github.com/llvm/llvm-project/issues/63461.
2025-05-26 13:25:35 +03:00
Tom Praschan
926c201323 [clangd] Add support for textDocument/rangesFormatting (#141208)
Uses the protocol changes proposed in
https://github.com/microsoft/language-server-protocol/pull/1556 and
https://github.com/microsoft/vscode/pull/163190

Related issue: https://github.com/clangd/clangd/issues/1635

Old Phabricator review: https://reviews.llvm.org/D150852

Relevant LSP 3.18 spec:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#documentRangesFormattingParams

Old PR: https://github.com/llvm/llvm-project/pull/80180,
https://github.com/llvm/llvm-project/pull/141052
2025-05-26 10:08:18 +02:00
Baranov Victor
eda3e96b40 [clang-tidy] Fix false positives in bugprone-crtp-constructor-accessibility check (#132543)
Fix false positives in `bugprone-crtp-constructor-accessibility` check
on deleted constructors that cannot be used to construct objects, even
if they have public or protected access.

Closes https://github.com/llvm/llvm-project/issues/131737.
2025-05-26 06:25:19 +03:00
Kazu Hirata
ba007a60d0 [clang-tidy] Remove unused includes (NFC) (#141420)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-25 10:55:36 -07:00
Kazu Hirata
4eb91b9a6a [clang] Default-construct values with DenseMap::try_emplace (NFC) (#141373)
try_emplace can default-construct values, so we do not need to do so
on our own.
2025-05-24 14:47:18 -07:00
David Rivera
4675f2287c [clang-tidy] detect arithmetic operations within member list initialization in modernize-use-default-member-init check (#129370)
This aims to address a portion of #122480 by adding matchers on binary
operators. **This allows the detection of explicit arithmetic operations
within initializers.**
2025-05-24 20:15:36 +03:00
Baranov Victor
fb99a850b6 [clang-tidy][NFC] Refactor modernize-use-trailing-return-type-check check code and tests (#140759)
- Deleted unused includes
- Deleted useless braces
- Converted private methods to static function to improve compilations
speed and readability
- Modernized tests to use `cxx-or-later`
2025-05-24 19:55:51 +03:00