0
0
mirror of https://github.com/llvm/llvm-project.git synced 2025-04-18 15:36:58 +00:00

10347 Commits

Author SHA1 Message Date
Nicolas van Kempen
09680dc18d
[NFC][clang-tidy] Remove {{^}} clauses in some tests (3/N) ()
`check_clang_tidy` now matches full lines only, so `{{^}}` clauses are
no longer necessary.

I am splitting those changes over multiple PRs to make review easier.
Numbering them but the actual order doesn't matter.
2025-04-17 13:55:34 -04:00
Nicolas van Kempen
d56afced16
[NFC][clang-tidy] Remove {{^}} clauses in some tests (2/N) ()
`check_clang_tidy` now matches full lines only, so `{{^}}` clauses are
no longer necessary.

I am splitting those changes over multiple PRs to make review easier.
Numbering them but the actual order doesn't matter.
2025-04-17 13:54:31 -04:00
yronglin
d83b639b4c
Reland [clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc ()
This PR reland https://github.com/llvm/llvm-project/pull/135808, fixed
some missed changes in LLDB.
I found this issue when I working on
https://github.com/llvm/llvm-project/pull/107168.

Currently we have many similiar data structures like:
- std::pair<IdentifierInfo *, SourceLocation>.
- Element type of ModuleIdPath.
- IdentifierLocPair.
- IdentifierLoc.

This PR unify these data structures to IdentifierLoc, moved
IdentifierLoc definition to SourceLocation.h, and deleted other similer
data structures.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-04-17 22:40:47 +08:00
Mohamed Emad
eef978290c
[clang-doc][NFC] clean unused variable in HTML generator ()
While reading the code, I found some dead variables that are not used
anymore but it still declared without removing them.
2025-04-16 17:16:12 -07:00
Matheus Izvekov
fe94f11407
[clang] Fix elaborated keyword canonicalization () 2025-04-16 16:27:24 -03:00
Michael Buch
99c08ff1cb
Revert "[clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc" ()
Reverts 

Example from the LLDB macOS CI:
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/24084/execution/node/54/log/?consoleFull
```
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp:360:49: error: no viable conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'clang::ModuleIdPath' (aka 'ArrayRef<IdentifierLoc>')
  clang::Module *top_level_module = DoGetModule(clang_path.front(), false);
                                                ^~~~~~~~~~~~~~~~~~
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'const llvm::ArrayRef<clang::IdentifierLoc> &' for 1st argument
  class LLVM_GSL_POINTER [[nodiscard]] ArrayRef {
                                       ^
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'llvm::ArrayRef<clang::IdentifierLoc> &&' for 1st argument
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:70:18: note: candidate constructor not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'std::nullopt_t' for 1st argument
    /*implicit*/ ArrayRef(std::nullopt_t) {}
```
2025-04-16 17:05:53 +02:00
yronglin
d3153ad66c
[clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc ()
I found this issue when I working on
https://github.com/llvm/llvm-project/pull/107168.

Currently we have many similiar data structures like:
 - `std::pair<IdentifierInfo *, SourceLocation>`.
 - Element type of `ModuleIdPath`.
 - `IdentifierLocPair`.
 - `IdentifierLoc`.
 
This PR unify these data structures to `IdentifierLoc`, moved
`IdentifierLoc` definition to SourceLocation.h, and deleted other
similer data structures.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-04-16 20:53:25 +08:00
Mythreya
a56f966417
[clangd][docs] Fix incorrect docstring for header-insertion "Never" ()
Docstring fix for changes introduced in PR 
2025-04-16 09:00:14 +02:00
Nicolas van Kempen
68383fc208
[NFC][clang-tidy] Remove {{^}} clauses in some tests (1/N) ()
`check_clang_tidy` now matches full lines only, so `{{^}}` clauses are
no longer necessary.

I am splitting those changes over multiple PRs to make review easier.
Numbering them but the actual order doesn't matter.
2025-04-15 13:42:54 -04:00
Paul Kirth
9cdc3aab3e
[clang-doc] Use SmartMutex when visiting the AST ()
The SmartMutex will allow us to have a cheap mutex implementation when
using the Standalone executor, since it's single threaded. Performance
should be about the same for AllTUs executor.
2025-04-14 17:27:03 -07:00
Matheus Izvekov
13b55ad3bb
[clang] implement printing of canonical expressions ()
This patch extends the canonicalization printing policy to cover
expressions
and template names, and wires that up to the template argument printer,
covering expressions, and to the expression within a dependent decltype.

This is helpful for debugging, or if these expressions somehow end up
in diagnostics, as without this patch they can print as completely
unrelated
expressions, which can be quite confusing.

This is because expressions are not uniqued, unlike types, and
when a template specialization containing an expression is the first to
be
canonicalized, the expression ends up appearing in the canonical type of
subsequent equivalent specializations.

Fixes https://github.com/llvm/llvm-project/issues/92292
2025-04-14 12:59:36 -03:00
Yoann Congal
3de9301538
[clangd] Add a build option to disable building dexp ()
Building dexp on Debian 11 currently causes intermittent failures [0] [1].

Adding the CLANGD_BUILD_DEXP option to disable dexp from the build
allows Debian 11 users to build clang (albeit without the dexp tool).

This option is set to "Build Dexp" by default so, no change is expected
without manual setting.

[0]: https://bugzilla.yoctoproject.org/show_bug.cgi?id=15803
[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1101322
2025-04-13 18:03:46 -04:00
Congcong Cai
06814834a6
[clang-tidy] treat unsigned char and signed char as char type by default in bugprone-unintended-char-ostream-output ()
Add `AllowedTypes` options to support custom defined char like type.
treat `unsigned char` and `signed char` as char like type by default.
The allowed types only effect when the var decl or explicit cast to this
non-canonical type names.

Fixed: 
2025-04-13 12:09:50 +08:00
Congcong Cai
302bc41410
[clang-tidy] matchesAnyListedTypeName support non canonical types () 2025-04-13 12:06:48 +08:00
Paul Kirth
b71123f127
[clang-doc] Pre-commit tests for static members and functions ()
Issue  mentions that static members are not included in
the documentation generated by clang-doc. This patch adds
some basic testing for that property, with the current incorrect
behavior. Follow up patches will address the missing documentation.
2025-04-12 10:54:27 -07:00
Matheus Izvekov
761787d425
Reland: [clang] Improved canonicalization for template specialization types ()
This relands https://github.com/llvm/llvm-project/pull/135119, after
fixing crashes seen in LLDB CI reported here:
https://github.com/llvm/llvm-project/pull/135119#issuecomment-2794910840

Fixes https://github.com/llvm/llvm-project/pull/135119

This changes the TemplateArgument representation to hold a flag
indicating whether a tempalte argument of expression type is supposed to
be canonical or not.

This gets one step closer to solving
https://github.com/llvm/llvm-project/issues/92292

This still doesn't try to unique as-written TSTs. While this would
increase the amount of memory savings and make code dealing with the AST
more well-behaved, profiling template argument lists is still too
expensive for this to be worthwhile, at least for now.

This also fixes the context creation of TSTs, so that they don't in some
cases get incorrectly flagged as sugar over their own canonical form.
This is captured in the test expectation change of some AST dumps.

This fixes some places which were unnecessarily canonicalizing these
TSTs.
2025-04-12 14:26:30 -03:00
Dmitry Vasilyev
cbba9600ae
Revert "[clang] Improved canonicalization for template specialization types" ()
Reverts llvm/llvm-project#135119 because of the assert in ASTContext.cpp, line 5619.
See  for details.
2025-04-11 17:55:11 +04:00
Björn Svensson
0276915a6c
[clang-tidy] Fix cert-err33-c to ignore functions with same prefixes as target ()
PR  introduced regex matching for `CheckedFunctions` in
`UnusedReturnValueCheck` which is used by the checker `cert-err33-c`.

Add a testcase and fix false positives by adding end-of-string to target
regex's.

---------

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
2025-04-11 10:08:29 +02:00
Nathan Ridge
fa0498fdae
[clang][HeuristicResolver] Apply default argument heuristic in resolveDeclRefExpr as well ()
This is a follow-up to https://github.com/llvm/llvm-project/pull/131074.

After moving the default argument heuristic to `simplifyType` in that
patch, the heuristic no longer applied to the 
`DependentScopeDeclRefExpr` case, because that wasn't using
`simplifyType`.

This patch fixes that, with an added testcase.
2025-04-11 02:35:04 -04:00
Matheus Izvekov
3954d258a5
[clang] Improved canonicalization for template specialization types ()
This changes the TemplateArgument representation to hold a flag
indicating whether a template argument of expression type is supposed to
be canonical or not.

This gets one step closer to solving
https://github.com/llvm/llvm-project/issues/92292

This still doesn't try to unique as-written TSTs. While this would
increase the amount of memory savings and make code dealing with the AST
more well-behaved, profiling template argument lists is still too
expensive for this to be worthwhile, at least for now. Without this
uniquing, this patch stands neutral in terms of performance impact.

This also fixes the context creation of TSTs, so that they don't in some
cases get incorrectly flagged as sugar over their own canonical form.
This is captured in the test expectation change of some AST dumps.

This fixes some places which were unnecessarily canonicalizing these
TSTs.
2025-04-10 14:23:02 -03:00
PeterChou1
6d98d45c9c
reland [clang-doc][NFC] refactor out file helpers ()
Split from https://github.com/llvm/llvm-project/pull/133161

refactor the code to extract file helpers used in HTML generators for
use in other generators for clang-doc

This patch fixes the error where compiling with
-DLLVM_LINK_LLVM_DYLIB=ON broke the buildbot
2025-04-10 07:58:29 -04:00
PeterChou1
e10f67a827
[clang-doc][NFC] refactor out file helpers ()
Split from https://github.com/llvm/llvm-project/pull/133161

refactor the code to extract file helpers used in HTML generators for
use in other generators for clang-doc
2025-04-09 17:21:28 -04:00
Congcong Cai
bd49d278c6
[clang-tidy][NFC] update test name and config for bugprone-unintended-char-ostream-output () 2025-04-08 23:46:13 +08:00
Congcong Cai
5aae0ee660
[clang-tidy] give dummy path when create ClangTidyContext ()
 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: 
2025-04-08 10:47:39 +08:00
Matheus Izvekov
d057811655
[clang] fix diagnostic printing of expressions ignoring LangOpts ()
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 ()
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. ()
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. ()
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 ()
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 ()
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. () 2025-04-04 08:04:16 -04:00
Matheus Izvekov
49fd0bf35d
[clang] support pack expansions for trailing requires clauses () 2025-04-03 12:36:15 -03:00
Carlos Galvez
6333fa5160
[clang-tidy] Fix broken HeaderFilterRegex when read from config file ()
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 
Fixes 
Fixes 

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 ()
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 () 2025-04-01 17:15:18 -03:00
Kazu Hirata
ee3c892b35
[clang-tidy] Use DenseMap::insert_range (NFC) ()
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 ()
```
> 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 ()
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) () 2025-03-29 12:22:13 -07:00
Mohamed Emad
515d1ae679
[clang-doc] Add --repository-line-prefix argument ()
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 
2025-03-28 16:45:09 -07:00
Paul Kirth
d4dc5712c4
[clang-doc] Allow setting a base directory for hosted pages ()
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 ()
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 ()
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. ()
Fixed: 
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 ()
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 ()
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 ()
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 ()
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 ()
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