10325 Commits

Author SHA1 Message Date
Congcong Cai
bd49d278c6
[clang-tidy][NFC] update test name and config for bugprone-unintended-char-ostream-output (#134868) 2025-04-08 23:46:13 +08:00
Congcong Cai
5aae0ee660
[clang-tidy] give dummy path when create ClangTidyContext (#134670)
#121323 changed the way the absolute path is computed. Empty file name
will cause absolute path ignore current folder.
This patch add "dummy" file name to avoid this issue
Fixed: #134502
2025-04-08 10:47:39 +08:00
Matheus Izvekov
d057811655
[clang] fix diagnostic printing of expressions ignoring LangOpts (#134693)
Currently when printing a template argument of expression type, the
expression is converted immediately into a string to be sent to the
diagnostic engine, unsing a fake LangOpts.

This makes the expression printing look incorrect for the current
language, besides being inneficient, as we don't actually need to print
the expression if the diagnostic would be ignored.

This fixes a nastiness with the TemplateArgument constructor for
expressions being implicit, and all current users just passing an
expression to a diagnostic were implicitly going through the template
argument path.

The expressions are also being printed unquoted. This will be fixed in a
subsequent patch, as the test churn is much larger.
2025-04-07 23:19:32 -03:00
Nicolas van Kempen
15750a0ab2
[clang-tidy] Use --match-full-lines instead of --strict-whitespace in check_clang_tidy (#133756)
See Discourse post here:
https://discourse.llvm.org/t/rfc-using-match-full-lines-in-clang-tidy-tests/85553

I've added `--match-partial-fixes` to all tests that were failing,
unless I noticed the fix was quick and trivial.
2025-04-07 16:34:07 -04:00
Baranov Victor
da6e2454ff
[clang-tidy] Improve bugprone-capturing-this-in-member-variable check: add support of bind functions. (#132635)
Improve `bugprone-capturing-this-in-member-variable` check:
Added support of `bind`-like functions that capture and store `this`
pointer in class member.

Closes https://github.com/llvm/llvm-project/issues/131220.
2025-04-07 09:57:55 +08:00
Zahira Ammarguellat
ebb0e6cb25
[NFC] Remove dead code detected by code sanitizer. (#134385)
The code sanitizer is failing with this error: `Execution cannot reach
this statement.`
The execution code path would early exit at line 928 if `(Lil && Ril) =
true`.
2025-04-04 15:21:47 -04:00
Jan Svoboda
1688c3062a
[clang] Do not share ownership of PreprocessorOptions (#133467)
This PR makes it so that `CompilerInvocation` is the sole owner of the
`PreprocessorOptions` instance.
2025-04-04 10:11:14 -07:00
Baranov Victor
547d054ef1
[clang-tidy][NFC][doc] improve "options" sections of misc-, cppcore- and other checks (#133694)
Improved "options" sections of various checks:

1. Added Options keyword to be a delimiter between "body" and "options"
parts of docs
2. Added default values where were absent.
3. Changed double-tick to single-tick in default values.

---------

Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
2025-04-04 14:21:48 +02:00
Zahira Ammarguellat
babbc6f842
[NFC] Fixes proposed by code sanitizer. (#134138) 2025-04-04 08:04:16 -04:00
Matheus Izvekov
49fd0bf35d
[clang] support pack expansions for trailing requires clauses (#133190) 2025-04-03 12:36:15 -03:00
Carlos Galvez
6333fa5160
[clang-tidy] Fix broken HeaderFilterRegex when read from config file (#133582)
PR https://github.com/llvm/llvm-project/pull/91400 broke the usage of
HeaderFilterRegex via config file, because it is now created at a
different point in the execution and leads to a different value.

The result of that is that using HeaderFilterRegex only in the config
file does NOT work, in other words clang-tidy stops triggering warnings
on header files, thereby losing a lot of coverage.

This patch reverts the logic so that the header filter is created upon
calling the getHeaderFilter() function.

Additionally, this patch adds 2 unit tests to prevent regressions in the
future:

- One of them, "simple", tests the most basic use case with a single
top-level .clang-tidy file.

- The second one, "inheritance", demonstrates that the subfolder only
gets warnings from headers within it, and not from parent headers.

Fixes #118009
Fixes #121969
Fixes #133453

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-04-03 09:28:34 +02:00
Matheus Izvekov
ad1ca5f4a2
[clang] Concepts: support pack expansions for type constraints (#132626)
This reverts an earlier attempt
(adb0d8ddceb143749c519d14b8b31b481071da77 and
50e5411e4247421fd606f0a206682fcdf0303ae3) to support these expansions,
which was limited to type arguments and which subverted the purpose
of SubstTemplateTypeParmType.

This propagates the ArgumentPackSubstitutionIndex along with the
AssociatedConstraint, so that the pack expansion works, without
needing any new transforms or otherwise any changes to the template
instantiation process.

This keeps the tests from the reverted commits, and adds a few more
showing the new solution also works for NTTPs.

Fixes https://github.com/llvm/llvm-project/issues/131798
2025-04-01 21:11:56 -03:00
Matheus Izvekov
dc17429ae6
[clang] improved preservation of template keyword (#133610) 2025-04-01 17:15:18 -03:00
Kazu Hirata
ee3c892b35
[clang-tidy] Use DenseMap::insert_range (NFC) (#133844)
We can safely switch to insert_range here because
SyntheticStmtSourceMap starts out empty in the constructor.  Also
TheCFG->synthetic_stmts() comes from DenseMap, so we know that the
keys are unique.  That is, operator[] and insert are equivalent in
this particular case.
2025-03-31 22:11:06 -07:00
Nicolas van Kempen
3b3d1a5c26
[NFC][clang-tidy] Add type annotations to check_clang_tidy (#133140)
```
> python3 -m mypy --strict clang-tools-extra/test/clang-tidy/check_clang_tidy.py
Success: no issues found in 1 source file
```
2025-03-30 18:48:19 -04:00
Baranov Victor
52639d69ac
[clang-tidy][NFC][doc] improve "options" sections of bugprone- and modernize- checks (#133525)
Improved "options" sections of `bugprone-` and `modernize-` checks:

1. Added `Options` keyword to be a delimiter between "body" and
"options" parts of docs
2. Added default values where was absent.
3. Improved readability of some default values by converting `1` to
`true`.
2025-03-30 20:26:23 +02:00
Kazu Hirata
884b19ab40
[clang-tools-extra] Use *Set::insert_range (NFC) (#133589) 2025-03-29 12:22:13 -07:00
Mohamed Emad
515d1ae679
[clang-doc] Add --repository-line-prefix argument (#131280)
This PR adds a new command-line option that allows users to specify the
prefix used for line-based anchors in repository URLs. Different
repository interfaces use different formats for line anchors (GitHub
uses `#L123`, googlesource uses `#123`, etc.). This option enables users
to customize the line prefix to match their repository platform without
requiring hard-coded values for each service.

Fixes #59814
2025-03-28 16:45:09 -07:00
Paul Kirth
d4dc5712c4
[clang-doc] Allow setting a base directory for hosted pages (#132482)
Currently, when we set URLs from JS, we set them only using the protocol
and host locations. This works fine when docs are served from the base
directory of the site, but if you want to nest it under another
directory, our JS fails to set the correct path, leading to broken
links.

This patch adds a --base option to specify the path prefix to use, which
is set in the generated index_json.js file. index.json can then fill in
the prefix appropriately when generating links in a browser. This flag
has no effect for non HTML output.

Given an index hosted at: www.docs.com/base_directory/index.html
we used to generate the following link:
    www.docs.com/file.html
Using --base base_directory we now generate:
    www.docs.com/base_directory/file.html

This allows such links to work when hosting pages without using a custom
index.js.
2025-03-28 12:49:43 -07:00
Baranov Victor
d6dcd985c0
[clang-tidy] Fix thread_local false positives in misc-use-internal-linkage check (#132573)
Based on C++ standard (see issue
https://github.com/llvm/llvm-project/issues/131679) and
[StackOverflow](https://stackoverflow.com/questions/22794382/are-c11-thread-local-variables-automatically-static)
`thread_local` variables are implicitly `static` so we should not
suggest adding `static` on a `thread_local` variables. I'd appreciate if
someone else will confirm this too because reading standard is tricky.

However, many people still use `static` and `thread_local` together:
[github
code-search](https://github.com/search?type=code&q=%22static+thread_local%22+language%3AC%2B%2B).
Maybe disabling warnings on `thread_local` should be made as a flag?
WDYT?

Closes https://github.com/llvm/llvm-project/issues/131679.
2025-03-28 21:33:58 +08:00
Baranov Victor
ecdbd26ba4
[clang-tidy][NFC] improve documentation for bugprone-argument-comment check (#133436)
Improve docs for `bugprone-argument-comment` check by writing explicitly
default values for options.
Before this change, it was unclear what values are default.
2025-03-28 14:33:53 +01:00
Congcong Cai
01e505b992
[clang-tidy][misc-const-correctness] fix fp when using const array type. (#133018)
Fixed: #132931
const array is immutable in C/C++ language design, we don't need to
check constness for it.
2025-03-28 06:21:15 +08:00
Kazu Hirata
aacc4e9a38 [modularize] Fix the build
This patch fixes:

  clang-tools-extra/modularize/ModularizeUtilities.cpp:293:15: error:
  no member named 'parseModuleMapFile' in 'clang::ModuleMap'; did you
  mean 'loadModuleMapFile'?
2025-03-25 12:41:41 -07:00
Michael Spencer
57f2e76e30
[clang] Consistently use "load" to refer to populating clang::ModuleMap (#132970)
Now that we have ModuleMapFile.cpp which parses module maps, it's
confusing what ModuleMap::parseModuleMapFile actually does. HeaderSearch
already called this loading a module map, so consistently use that term
in ModuleMap too.

An upcoming patch will allow just parsing a module map without loading
the modules from it.
2025-03-25 12:32:58 -07:00
Jan Svoboda
7a370748c0
[clang][lex] Store non-owning options ref in HeaderSearch (#132780)
This makes it so that `CompilerInvocation` can be the only entity that
manages ownership of `HeaderSearchOptions`, making it possible to
implement copy-on-write semantics.
2025-03-25 12:14:06 -07:00
Alex Hoppen
3bcbb47258
[clangd] Use SymbolName to represent Objective-C selectors (#82061)
This is a cleaner design than using identifier and an optional `Selector`. It also allows rename of Objective-C method names if no declaration is at hand and thus no `Selector` instance can be formed. For example, when finding the ranges to rename based on an index that’s not clangd’s built-in index.
2025-03-25 14:34:00 -04:00
Chuanqi Xu
e5f100676e
[clangd] [C++20] [Modules] Add modules suffix for 'Header' Source Switch (#131591)
Support the trivial "header"/source switch for module interfaces.

I initially thought the naming are bad and we should rename it. But
later I feel it is better to split patches as much as possible.

From the codes it looks like there are problems. e.g., `isHeaderFile`.
But let's try to fix them in different patches.
2025-03-25 09:43:13 +08:00
Paul Kirth
c1ed4f6423
[clang-doc] Format test files (#132428)
Many of the test files had an inconsistent formatting. This patch ran
clang-format over them using the project's .clang-format file, with
column limit = 0, to prevent test directives from being split over
multiple lines.
2025-03-24 17:27:16 -07:00
Carlos Galvez
0fb4ef40b1
Revert "[clang-tidy] Avoid processing declarations in system headers … (#132743)
…(#128150)"

This was too aggressive, and leads to problems for downstream users:
https://github.com/llvm/llvm-project/pull/128150#issuecomment-2739803409

Let's revert and reland it once we have addressed the problems.

This reverts commit e4a8969e56572371201863594b3a549de2e23f32.

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-03-24 20:47:57 +01:00
Kazu Hirata
76b999d70f
[clang-tidy] Avoid repeated map lookups (NFC) (#132656) 2025-03-24 00:13:21 -07:00
Kazu Hirata
4a7643400c
[clang-tools-extra] Use *Set::insert_range (NFC) (#132589)
DenseSet, SmallPtrSet, SmallSet, SetVector, and StringSet recently
gained C++23-style insert_range.  This patch replaces:

  Dest.insert(Src.begin(), Src.end());

with:

  Dest.insert_range(Src);
2025-03-23 00:23:19 -07:00
Baranov Victor
2909c420f6
[clang-tidy] modernize-use-starts-ends-with: fix false positives on find and rfind (#129564)
Also document cases with two or three arguments (matching default arguments)
this check matches.

Closes https://github.com/llvm/llvm-project/issues/129498.
2025-03-22 08:07:58 -04:00
Mohamed Emad
98dc8bb892
[clang-doc][NFC] fix description typo (#132310)
Fix the description typo for `JsScripts` in the context

discussed in #131280
2025-03-21 16:08:14 -07:00
Matheus Izvekov
14f7bd63b9
Reland: [clang] preserve class type sugar when taking pointer to member (#132401)
Original PR: #130537
Originally reverted due to revert of dependent commit. Relanding with no
changes.

This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the base class.

Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.

The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntatically, and
they represent the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.

This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.

As usual, includes a few drive-by fixes in order to make use of the
improvements.
2025-03-21 13:20:52 -03:00
Matheus Izvekov
1416566449
Reland: [clang] NFC: Clear some uses of MemberPointerType::getClass (#132317)
Relands Original PR: https://github.com/llvm/llvm-project/pull/131965
Addresses
https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
* Fixes isIncompleteType for injected classes

This clears up some uses of getClass on MemberPointerType when
equivalent uses of getMostRecentCXXRecordDecl would be just as simple or
simpler.
    
This is split-off from a larger patch which removes getClass, in order
to facilitate review.
2025-03-21 10:54:24 -03:00
Paul Kirth
3fbc9b9efc
[clang-doc] Correct improper file paths in HTML output (#132103)
In index.js the logic of the ternary operator was backwards, preventing
us from generating the correct file paths, or relative paths in the HTML
output.
2025-03-20 14:11:42 -07:00
Paul Kirth
3923a6b09c
[clang-doc][NFC] Remove unnecessary directory cleanup (#132101)
The tests all remove the directory at test start, and it only prevents
inspecting the test artifacts to remove them at the end of the test run.
2025-03-20 14:08:46 -07:00
Paul Kirth
a87a64b2e4
[clang-doc] Avoid deref of invalid std::optional (#131939)
Since our existing guard is insufficient to prevent accessing the
std::optional when in an invalid state, guard the access with
`.value_or()`. This maintains the desired behavior, without running into
UB.

The new test should prevent regressions.

Fixes #131697
2025-03-20 14:04:58 -07:00
Matheus Izvekov
335a4614de
Revert "[clang] NFC: Clear some uses of MemberPointerType::getClass" (#132281)
Reverts llvm/llvm-project#131965

Reverted due to issue reported here:
https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-20 17:54:21 -03:00
Matheus Izvekov
5151e6d7fe
Revert "Reland: [clang] preserve class type sugar when taking pointer to member" (#132280)
Reverts llvm/llvm-project#132234

Needs to be reverted due to dependency.

This blocks reverting another PR, see here:
https://github.com/llvm/llvm-project/pull/131965#issuecomment-2741619498
2025-03-20 17:52:48 -03:00
Matheus Izvekov
578f38cd08
Reland: [clang] preserve class type sugar when taking pointer to member (#132234)
Original PR: #130537
Reland after updating lldb too.

This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the base class.

Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.

The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntatically, and
they represent the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.

This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.

As usual, includes a few drive-by fixes in order to make use of the
improvements.
2025-03-20 15:33:54 -03:00
Matheus Izvekov
6cd62ad08c
Revert "[clang] improve class type sugar preservation in pointers to members" (#132215)
Reverts llvm/llvm-project#130537

This missed updating lldb, which we didn't notice due to lack of
pre-commit CI.
2025-03-20 11:09:25 -03:00
Matheus Izvekov
9b1f905b48
[clang] improve class type sugar preservation in pointers to members (#130537)
This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the class.

Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.

The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntactically, and it
also represents the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.

This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.

As usual, includes a few drive-by fixes in order to make use of the
improvements, and removing some duplications, for example
CheckBaseClassAccess is deduplicated from across SemaAccess and
SemaCast.
2025-03-20 10:30:24 -03:00
Mythreya
9cdbc47144
[clangd] Add HeaderInsertion config option (#128503)
This is the config file equivalent of the `--header-insertion` command line option

Fixes https://github.com/clangd/clangd/issues/2032
2025-03-20 02:22:29 -04:00
Matheus Izvekov
fd7be0d2e9
[clang] NFC: Clear some uses of MemberPointerType::getClass (#131965) 2025-03-19 21:36:10 -03:00
Paul Kirth
77ac5a2d57
[clang-doc] Enable MD tests in basic-project (#131924)
For some reason the MD tests don't appear to have ever run, despite
having checks. This patch adds a new set of RUN lines that will
exercise the markdown generation.
2025-03-19 16:14:24 -07:00
Alexander Shaposhnikov
297f0b3f4c
[CudaSPIRV] Allow using integral non-type template parameters as attribute args (#131546)
Allow using integral non-type template parameters as attribute arguments
of
reqd_work_group_size and work_group_size_hint.

Test plan:
ninja check-all
2025-03-19 10:11:18 -07:00
Paul Kirth
93b7c1b4b2
[clang-doc] Add testing without --repository for HTML documentation (#131894)
https://github.com/llvm/llvm-project/issues/131697 reported a crash when
--repository was unused, so make sure we test the project in both
configurations.
2025-03-19 08:24:10 -07:00
Aaron Ballman
449cdfacc0
Suppress pedantic diagnostic for a file not ending in EOL (#131794)
WG14 added N3411 to the list of papers which apply to older versions of
C in C2y, and WG21 adopted CWG787 as a Defect Report in C++11. So we no
longer should be issuing a pedantic diagnostic about a file which does
not end with a newline character.

We do, however, continue to support -Wnewline-eof as an opt-in
diagnostic.
2025-03-19 07:49:16 -04:00
Jan Voung
6f659b0060
[clang][dataflow] For bugprone-unchecked-optional-access report range (#131055)
Report the range in diagnostics, in addition to the location
in case the range helps disambiguate a little in chained `->`
expressions.
```
b->a->f->x = 1;
^~~~~~~
```
instead of just:
```
b->a->f->x = 1;
^
```
As a followup we should probably also report the location/range
of an `->` if that operator is used. Like:
```
b->a->f->x = 1;
       ^~
```
2025-03-17 16:04:15 -04:00