4157 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
87729bcbb8
[clangd] Migrate away from std::nullopt (NFC) (#145841)
ArrayRef has a constructor that accepts std::nullopt.  This
constructor dates back to the days when we still had llvm::Optional.

Since the use of std::nullopt outside the context of std::optional is
kind of abuse and not intuitive to new comers, I would like to move
away from the constructor and eventually remove it.

This patch replaces std::nullopt with {}.
2025-06-26 08:40:55 -07:00
someoneinjd
8513066f2c
[clangd] Implement LSP 3.17 positionEncoding (#142903)
This PR adds support for the `positionEncoding` client capability
introduced in LSP 3.17. Clangd can now negotiate the position encoding
with the client during initialization.

Fix https://github.com/clangd/clangd/issues/1746

Co-authored-by: kadir çetinkaya <kadircetinkaya.06.tr@gmail.com>
2025-06-17 19:23:14 +02:00
Aleksandr Platonov
ca5040990e
[clangd] Collect references in array designators (#140356) 2025-06-13 18:32:42 +03:00
Aaron Ballman
9eef4d1c5f
Remove delayed typo expressions (#143423)
This removes the delayed typo correction functionality from Clang
(regular typo correction still remains) due to fragility of the
solution.

An RFC was posted here:
https://discourse.llvm.org/t/rfc-removing-support-for-delayed-typo-correction/86631
and while that RFC was asking for folks to consider stepping up to be
maintainers, and we did have a few new contributors show some interest,
experiments show that it's likely worth it to remove this functionality
entirely and focus efforts on improving regular typo correction.

This removal fixes ~20 open issues (quite possibly more), improves
compile time performance by roughly .3-.4%
(https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=AaronBallman&sortBy=date),
and does not appear to regress diagnostic behavior in a way we wouldn't
find acceptable.

Fixes #142457
Fixes #139913
Fixes #138850
Fixes #137867
Fixes #137860
Fixes #107840
Fixes #93308
Fixes #69470
Fixes #59391
Fixes #58172
Fixes #46215
Fixes #45915
Fixes #45891
Fixes #44490
Fixes #36703
Fixes #32903
Fixes #23312
Fixes #69874
2025-06-13 06:45:40 -04:00
Longsheng Mou
52360d195b
[NFC] Use llvm::includes instead of std::includes (#143542)
This PR follows up #143297.
2025-06-12 09:27:27 +08:00
Hans Wennborg
5471d933af Disable clangd/test/module_dependencies.test on Windows
The test fails (sometimes); see discussion on https://github.com/llvm/llvm-project/pull/142828
2025-06-10 13:04:51 +02: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
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
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
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
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
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
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
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
Daan De Meyer
5ff175233e
[clang-tools-extra] Add include mappings for <sys/uio.h> (#141216) 2025-05-23 16:40:28 +02:00
Jan Svoboda
13e1a2cb22 Reapply "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22 12:52:03 -07:00
Kazu Hirata
e2a885537f Revert "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c.

Multiple builtbot failures have been reported:
https://github.com/llvm/llvm-project/pull/139584
2025-05-22 12:44:20 -07:00
Jan Svoboda
9e306ad460
[clang] Remove intrusive reference count from DiagnosticOptions (#139584)
The `DiagnosticOptions` class is currently intrusively
reference-counted, which makes reasoning about its lifetime very
difficult in some cases. For example, `CompilerInvocation` owns the
`DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and
only exposes an accessor returning `DiagnosticOptions &`. One would
think this gives `CompilerInvocation` exclusive ownership of the object,
but that's not the case:

```c++
void shareOwnership(CompilerInvocation &CI) {
  llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions();
  // ...
}
```

This is a perfectly valid pattern that is being actually used in the
codebase.

I would like to ensure the ownership of `DiagnosticOptions` by
`CompilerInvocation` is guaranteed to be exclusive. This can be
leveraged for a copy-on-write optimization later on. This PR changes
usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and
`lldb` to not be intrusively reference-counted.
2025-05-22 12:33:52 -07:00
Daan De Meyer
dabc84c890
[clang-tools-extra] Add include mappings for getopt.h (#140726) 2025-05-21 16:41:44 +02:00
Kazu Hirata
5bd3c44b79
[clang-tools-extra] Remove redundant control flow statements (NFC) (#140846) 2025-05-21 00:29:17 -07:00
Jan Svoboda
72b2219b3e Revert "[clang][modules] Timestamp-less validation API (#139987)"
This reverts commit 7a242387c950c7060143da6da0e6fb91f36bb458. Even after 175f8a44, the Modules/fmodules-validate-once-per-build-session.c test is not fixed on the clang-armv8-quick build bot. (Failure occurs on line 114.)
2025-05-19 12:57:54 -07:00
Jan Svoboda
7a242387c9 Reland "[clang][modules] Timestamp-less validation API (#139987)"
This reverts commit 18b885f66babff3a10451bc811ffc077d61ed8ee, effectively reapplying #139987. This commit fixes unit tests (for example ASTUnitTest.SaveLoadPreservesLangOptionsInPrintingPolicy) where the `ASTUnit::ModCache` pointer dereferenced within `ASTUnit::serialize()` was null. This commit makes sure each factory function does initialize `ASTUnit::ModCache`.
2025-05-19 10:40:55 -07:00
Kazu Hirata
04c73adfe2
[clang-tools-extra] Use llvm::is_contained (NFC) (#140456) 2025-05-18 09:46:15 -07:00
Kazu Hirata
1a40edf2c0
[clang-tools-extra] Use llvm::find_if (NFC) (#140411) 2025-05-17 17:01:37 -07:00
Kazu Hirata
ab1fea49e2
[clang-tools-extra] Use llvm::replace (NFC) (#140200) 2025-05-16 07:30:46 -07:00
Zahira Ammarguellat
38e0f983ad
[CLANGD] [NFC] Fix proposed by static analyzer. (#140116)
This fixes an issue reported by the sanitizer with the following error
message:
`copy_constructor_call: IndexOpts` is passed by value as a parameter to`
clang::index::IndexingOptions::IndexingOptions` instead of being moved.
2025-05-16 07:56:36 -04:00
Qinkun Bao
18b885f66b
Revert "[clang][modules] Timestamp-less validation API" (#139987)
Reverts llvm/llvm-project#138983
2025-05-14 21:02:57 -04:00
Jan Svoboda
960afcc90e
[clang][modules] Timestamp-less validation API (#138983)
Timestamps are an implementation detail of the cross-process module
cache implementation. This PR hides it from the `ModuleCache` API, which
simplifies the in-process implementation.
2025-05-14 14:31:23 -07:00
Kazu Hirata
75e0865837
[clang-tools-extra] Use llvm::unique (NFC) (#139663) 2025-05-12 23:24:24 -07:00
Noustaa
bfd2ef7659
[clangd] Add CodePatterns config option under Completion (#137613)
Allows enabling/disabling code pattern & snippet suggestions
during code completion.

Resolves https://github.com/clangd/clangd/discussions/1867
2025-05-12 14:22:27 -04:00
Kazu Hirata
841d2e59bb
[clangd] Use StringRef::consume_back_insensitive (NFC) (#139456) 2025-05-11 09:45:16 -07:00
Kazu Hirata
4b6762b0d4
[clang-tools-extra] Remove unused local variables (NFC) (#139382) 2025-05-10 09:30:54 -07:00
Kazu Hirata
5d305b618f
[clang-tools-extra] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#138774) 2025-05-06 20:16:54 -07:00
Nathan Ridge
1b0a0c7382
[clangd] Store documentation when indexing standard library (#133681)
Fixes https://github.com/clangd/clangd/issues/2344
2025-05-05 03:13:25 -04:00
Jan Svoboda
b69dcb8734
[clang][frontend] Require invocation to construct CompilerInstance (#137668)
This PR makes it so that `CompilerInvocation` needs to be provided to
`CompilerInstance` on construction. There are a couple of benefits in my
view:
* Making it impossible to mis-use some `CompilerInstance` APIs. For
example there are cases, where `createDiagnostics()` was called before
`setInvocation()`, causing the `DiagnosticEngine` to use the
default-constructed `DiagnosticOptions` instead of the intended ones.
* This shrinks `CompilerInstance`'s state space.
* This makes it possible to access **the** invocation in
`CompilerInstance`'s constructor (to be used in a follow-up).
2025-05-01 07:31:30 -07:00
Thomas Du Plessis
ac9e1df3ef
[clangd] Add container field to remote index Refs grpc method (#71605)
Fixes https://github.com/clangd/clangd/issues/1358
2025-05-01 03:11:30 -04:00
Jan Svoboda
985410f87f
[clang] Hide the TargetOptions pointer from CompilerInvocation (#106271)
This PR hides the reference-counted pointer that holds `TargetOptions`
from the public API of `CompilerInvocation`. This gives
`CompilerInvocation` an exclusive control over the lifetime of this
member, which will eventually be leveraged to implement a copy-on-write
behavior.

There are two clients that currently share ownership of that pointer:

* `TargetInfo` - This was refactored to hold a non-owning reference to
`TargetOptions`. The options object is typically owned by the
`CompilerInvocation` or by the new `CompilerInstance::AuxTargetOpts` for
the auxiliary target. This needed a bit of care in `ASTUnit::Parse()` to
keep the `CompilerInvocation` alive.
* `clangd::PreambleData` - This was refactored to exclusively own the
`TargetOptions` that get moved out of the `CompilerInvocation`.
2025-04-28 07:43:26 -07:00
Hampus Adolfsson
bea110db3e
[clangd] Strip invalid fromRanges for outgoing calls (#134657)
`CallHierarchyOutgoingCall::fromRanges` are interpreted as ranges in the
same file as the item for which 'outgoingCalls' was called.

It's possible for outgoing calls to be in a different file than that
item if the item is just a declaration (e.g. in a header file). Now,
such calls are dropped instead of being returned to the client.

This is the same as the change made in #111616, but now for outgoing
calls.

Fixes clangd/clangd#2350

---------

Co-authored-by: Nathan Ridge <zeratul976@hotmail.com>
2025-04-24 03:28:35 -04:00
Mythreya
665914fea1
[clangd] Improve BlockEnd inlayhint presentation (#136106)
* Only show for blocks 10 lines or taller (including braces)
 * Add parens for function call: "// if foo" -> "// if foo()" or "// if foo(...)"
 * Print literal nullptr
 * Escaping for abbreviated strings

Fixes https://github.com/clangd/clangd/issues/1807.

Based on the original PR at https://github.com/llvm/llvm-project/pull/72345.

Co-authored-by: daiyousei-qz <qyzheng2@outlook.com>
2025-04-23 02:36:48 -04:00