aboutsummaryrefslogtreecommitdiff
path: root/clang/test/CodeCompletion
AgeCommit message (Collapse)AuthorFilesLines
2025-09-11[clang] Remove shell requirements from testsAiden Grossman1-1/+1
Most of these tests do not actually have a shell requirement. The shell requirement ended up in the test either from cargo culting (from what I can tell) or because the test authors actually meant to mark Windows as unsupported. This prevents enablement of lit's internal shell within clang. Towards #102699. Reviewers: rnk, efriedma-quic, Sirraide, petrhosek, ilovepi Reviewed By: ilovepi Pull Request: https://github.com/llvm/llvm-project/pull/156905
2025-08-21[clang][CodeComplete] Consider qualifiers of explicit object parameters in ↵Mythreya Kuricheti1-0/+70
overload suggestions (#154041) Fixes https://github.com/llvm/llvm-project/issues/109608
2025-08-20[clang][CodeComplete] Do not suggest unqualified members in explicit-object ↵Mythreya Kuricheti1-1/+36
member functions (#153760) Fixes https://github.com/llvm/llvm-project/issues/141291
2025-07-31[clang][CodeComplete] skip explicit obj param when creating signature string ↵Mythreya Kuricheti1-8/+42
(#146649) Fixes clangd/clangd#2284
2025-07-01[clang][CodeComplete] skip explicit obj param in code completion string ↵Mythreya1-0/+14
(#146258) Fixes clangd/clangd#2339
2025-06-28[Sema][clangd] add noexcept to override functions during code completion ↵Sirui Mu1-0/+14
(#75937) If a virtual function is declared with `noexcept`, functions that override this function in the derived classes must be declared with `noexcept` as well. This PR updates code completion in clang Sema. It adds `noexcept` specifier to override functions in the code completion result if the functions override a `noexcept` virtual function.
2025-05-29[clang] Serialization: support hashing null template arguments (#141890)Matheus Izvekov1-0/+26
2025-05-15[clang] Enforce 1-based indexing for command line source locations (#139457)Naveen Seth Hanig1-0/+11
Fixes #139375 Clang expects command line source locations to be provided using 1-based indexing. Currently, Clang does not reject zero as invalid argument for column or line number, which can cause Clang to crash. This commit extends validation in `ParsedSourceLocation::FromString` to only accept (unsinged) non-zero integers.
2025-04-15[CodeComplete] Don't drop ArrayToPointerDecay when doing member completion ↵Akira Hatanaka1-0/+9
(#134951) Fixes https://github.com/llvm/llvm-project/issues/123146. rdar://138851576
2025-04-11[clang][CodeComplete] Use HeuristicResolver in getAsRecordDecl() (#130473)Nathan Ridge1-2/+4
Fixes https://github.com/llvm/llvm-project/issues/130468
2025-03-17[clang][CodeComplete] Add code completion for if constexpr and consteval ↵Letu Ren1-0/+30
(#124315) Code complete `constexpr` and `consteval` keywords after `if` in the relevant language modes. If pattern completion is enabled, the completions also include placeholders for the condition (in the case of `constexpr`) and statement block.
2025-03-03[clang] Fix CodeComplete crash involving CWG1432 (#129436)Matheus Izvekov1-0/+38
This skips the provisional resolution of CWG1432 just when ordering the candidates for function call code completion, as otherwise this breaks some assumptions the implementation makes about how closely related the candidates are. As a drive-by, deduplicate the implementation with the one used for class template partial ordering, and strenghten an assertion which was previosuly dependent on the order of candidates. Also add a test for the fix for CWG1432 when partial ordering function templates, which was otherwise untested. Fixes #125500
2025-01-30[clang][CodeComplete] Use HeuristicResolver to resolve ↵Nathan Ridge1-0/+18
CXXDependentScopeMemberExpr (#124888)
2025-01-23[clang][CodeComplete] Use HeuristicResolver to resolve DependentNameTypes ↵Nathan Ridge1-0/+16
(#123818) Fixes https://github.com/clangd/clangd/issues/1249
2025-01-22[clang][CodeComplete] Use HeuristicResolver to resolve pointee types (#121315)Nathan Ridge1-0/+17
Fixes https://github.com/clangd/clangd/issues/810
2024-11-26Add code completion for C++20 keywords. (#107982)ykiko1-0/+57
This commit adds code completion for C++20 keywords, fix https://github.com/llvm/llvm-project/issues/107868. 1. complete `concept` in template context - [x] `template<typename T> conce^` -> `concept` - [ ] `conce^` 2. complete `requires` - [x] constraints in template context: `template<typename T> requi^` -> `requires` - [x] requires expression: `int x = requ^` -> `requires (parameters) { requirements }` - [x] nested requirement: `requires { requ^ }` -> `requires expression ;` 3. complete coroutine keywords - [x] `co_await^` in expression: `co_aw^` -> `co_await expression;` - [x] `co_yield` in function body: `co_yi^` -> `co_yield expression;` - [x] `co_return` in function body: `co_re^` -> `co_return expression;` 4. specifiers: `char8_t`, `consteval`, `constinit`
2024-08-28[clang] check deduction consistency when partial ordering function templates ↵Matheus Izvekov1-1/+1
(#100692) This makes partial ordering of function templates consistent with other entities, by implementing [temp.deduct.type]p1 in that case. Fixes #18291
2024-06-20[Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit ↵Mital Ashok1-1/+1
(#95580) This checks if the layout of `std::initializer_list` is something Clang can handle much earlier and deduplicates the checks in CodeGen/CGExprAgg.cpp and AST/ExprConstant.cpp Also now diagnose `union initializer_list` (Fixes #95495), bit-field for the size (Fixes a crash that would happen during codegen if it were unnamed), base classes (that wouldn't be initialized) and polymorphic classes (whose vtable pointer wouldn't be initialized).
2024-05-27[clang][CodeComplete] Recurse into the subexpression of deref operator in ↵Younan Zhang1-0/+16
getApproximateType (#93404) The issue with the previous implementation bc31be7 was that getApproximateType could potentially return a null QualType for a dereferencing operator, which is not what its caller wants.
2024-03-25[clang][CodeComplete] Handle deref operator in getApproximateType (#86466)Nathan Ridge1-2/+18
This allows completing after `(*this).` in a dependent context. Fixes https://github.com/clangd/clangd/issues/1952
2024-03-12[clang][CodeCompletion] Allow debuggers to code-complete reserved ↵Michael Buch1-1/+6
identifiers (#84891)
2023-09-28[clangd][CodeComplete] Improve FunctionCanBeCallYounan Zhang1-0/+11
From two aspects: - For function templates, emit additional template argument placeholders in the context where it can't be a call in order to specify an instantiation explicitly. - Consider expressions with base type specifier such as 'Derived().Base::foo^' a function call. Reviewed By: nridge Differential Revision: https://reviews.llvm.org/D156605
2023-08-28Reland "[clang-repl] support code completion at a REPL."Fred Fu2-0/+7
Original commit message: " This patch enabled code completion for ClangREPL. The feature was built upon three existing Clang components: a list completer for LineEditor, a CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method. The first component serves as the main entry point of handling interactive inputs. Because a completion point for a compiler instance has to be unchanged once it is set, an incremental compiler instance is created for each code completion. Such a compiler instance carries over AST context source from the main interpreter compiler in order to obtain declarations or bindings from previous input in the same REPL session. The most important API codeComplete in Interpreter/CodeCompletion is a thin wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as a code completion point and a ReplCompletionConsumer, which communicates completion results from SemaCodeCompletion back to the list completer for the REPL. In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels were added so that SemaCodeCompletion can treat top level statements like expression statements at the REPL. For example, clang-repl> int foo = 42; clang-repl> f<tab> From a parser's persective, the cursor is at a top level. If we used code completion without any changes, PCC_Namespace would be supplied to Sema::CodeCompleteOrdinaryName, and thus the completion results would not include foo. Currently, the way we use PCC_TopLevelOrExpression and CCC_TopLevelOrExpression is no different from the way we use PCC_Statement and CCC_Statement respectively. Differential revision: https://reviews.llvm.org/D154382 " The new patch also fixes clangd and several memory issues that the bots reported and upload the missing files.
2023-08-23Revert "[clang-repl] support code completion at a REPL."Vassil Vassilev2-7/+0
This reverts commit eb0e6c3134ef6deafe0a4958e9e1a1214b3c2f14 due to failures in clangd such as https://lab.llvm.org/buildbot/#/builders/57/builds/29377
2023-08-23[clang-repl] support code completion at a REPL.Fred Fu2-0/+7
This patch enabled code completion for ClangREPL. The feature was built upon three existing Clang components: a list completer for LineEditor, a CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method. The first component serves as the main entry point of handling interactive inputs. Because a completion point for a compiler instance has to be unchanged once it is set, an incremental compiler instance is created for each code completion. Such a compiler instance carries over AST context source from the main interpreter compiler in order to obtain declarations or bindings from previous input in the same REPL session. The most important API codeComplete in Interpreter/CodeCompletion is a thin wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as a code completion point and a ReplCompletionConsumer, which communicates completion results from SemaCodeCompletion back to the list completer for the REPL. In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels were added so that SemaCodeCompletion can treat top level statements like expression statements at the REPL. For example, clang-repl> int foo = 42; clang-repl> f<tab> From a parser's persective, the cursor is at a top level. If we used code completion without any changes, PCC_Namespace would be supplied to Sema::CodeCompleteOrdinaryName, and thus the completion results would not include foo. Currently, the way we use PCC_TopLevelOrExpression and CCC_TopLevelOrExpression is no different from the way we use PCC_Statement and CCC_Statement respectively. Differential revision: https://reviews.llvm.org/D154382
2022-12-19[lit] Script to automate use of %(line-n). Use in CodeComplete tests.Sam McCall73-241/+241
Tests where the RUN-lines/CHECK-ed output refer to line numbers in the test file are a maintenance burden, as inserting text in the appropriate place invalidates all the subsequent line numbers. Lit supports %(line+n) for this, and FileCheck supports [[@LINE+N]]. But many existing tests don't make use of it and still need to be modified. This commit adds a script that can find line numbers in tests according to a regex and replace them with the appropriate relative-line reference. It contains some options to avoid inappropriately rewriting tests where absolute numbers are appropriate: a "nearby" threshold and a refusal by default to replace only some matched line numbers. I've applied it to CodeComplete tests, this proves the concept but also are the single worst group of tests I've seen in this respect. These changes are likely to hit merge conflicts, but can be regenerated with: ``` find ../clang/test/CodeCompletion/ -type f | grep -v /Inputs/ | xargs ../llvm/utils/relative_lines.py --verbose --near=20 --pattern='-code-completion-at[ =]%s:(\\d+):' --pattern='requires fix-it: {(\d+):\d+-(\d+):\d+}' ```` As requested in https://reviews.llvm.org/D140044 Fixes https://github.com/llvm/llvm-project/issues/59553 Differential Revision: https://reviews.llvm.org/D140217
2022-12-16clang/test/CodeCompletion: Simplify/fix some `touch` commandsDavid Blaikie1-1/+1
These were inconsistent (one `touch` line listed all the files in a single `touch` invocation, but the other listed them as separate commands with `&&`) and incorrect (one `&&` was missing, causing `touch` to try to touch a file called `touch` in the cwd, which might not be accessible/relevant to test execution) So make them consistent and simpler by using the "list all the files on a line in a single `touch` invocation" reducing the visual noise/clutter/etc.
2022-12-16[CodeComplete] Offer completions for headers with extension .hxx in include ↵Nathan Ridge1-8/+9
directives Fixes https://github.com/clangd/clangd/issues/1379 Differential Revision: https://reviews.llvm.org/D140191
2022-12-15[CodeComplete] Complete members of dependent `auto` variablesSam McCall1-34/+42
When the initializer of an `auto` variable is dependent, clang doesn't give the DeclRefExpr a useful dependent type that we can apply heuristics to. However we can dig one up by looking at the initializer. Differential Revision: https://reviews.llvm.org/D140044
2022-12-14[CodeComplete] Provide designated-init completions in (const) reference contextSam McCall1-8/+12
Differential Revision: https://reviews.llvm.org/D140029
2022-09-28[clang][DR2621] using enum NAME lookup fixNathan Sidwell1-1/+1
Although using-enum's grammar is 'using elaborated-enum-specifier', the lookup for the enum is ordinary lookup (and not the tagged-type lookup that normally occurs wth an tagged-type specifier). Thus (a) we can find typedefs and (b) do not find enum tags hidden by a non-tag name (the struct stat thing). This reimplements that part of using-enum handling, to address DR2621, where clang's behaviour does not match std intent (and other compilers). Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D134283
2022-09-26Don't crash when code completing `using enum ^Foo`.Sam McCall1-0/+7
Fixes https://github.com/clangd/clangd/issues/1281 Differential Revision: https://reviews.llvm.org/D134243
2022-08-17[clang] Apply FixIts to members declared via `using` in derived classesDenis Fatkulin1-0/+22
FixIt don't switch to arrow in derrived members with `using` Example code: ``` struct Bar { void foo(); }; struct Baz { using Bar::foo; }; void test(Baz* ptr) { ptr.^ } Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D131088
2022-08-17[clang] Give priority to Class context while parsing declarationsFurkan Usta1-1/+11
Fixes https://github.com/clangd/clangd/issues/290. Reviewed By: kadircet Differential Revision: https://reviews.llvm.org/D130363
2022-02-09Use functions with prototypes when appropriate; NFCAaron Ballman1-2/+2
A significant number of our tests in C accidentally use functions without prototypes. This patch converts the function signatures to have a prototype for the situations where the test is not specific to K&R C declarations. e.g., void func(); becomes void func(void); This is the fifth batch of tests being updated (there are a significant number of other tests left to be updated). Note, the behavior of -ast-print is broken. It prints functions with a prototype (void) as if they have no prototype () in C. Some tests need to disable strict prototype checking when recompiling the results of an -ast-print invocation.
2022-01-26[CodeCompletion][clangd] Clean __uglified parameter names in completion & hoverSam McCall1-0/+25
Underscore-uglified identifiers are used in standard library implementations to guard against collisions with macros, and they hurt readability considerably. (Consider `push_back(Tp_ &&__value)` vs `push_back(Tp value)`. When we're describing an interface, the exact names of parameters are not critical so we can drop these prefixes. This patch adds a new PrintingPolicy flag that can applies this stripping when recursively printing pieces of AST. We set it in code completion/signature help, and in clangd's hover display. All three features also do a bit of manual poking at names, so fix up those too. Fixes https://github.com/clangd/clangd/issues/736 Differential Revision: https://reviews.llvm.org/D116387
2022-01-13[CodeCompletion] (mostly) fix completion in incomplete C++ ctor initializers.Sam McCall1-0/+20
C++ member function bodies (including ctor initializers) are first captured into a buffer and then parsed after the class is complete. (This allows members to be referenced even if declared later). When the boundary of the function body cannot be established, its buffer is discarded and late-parsing never happens (it would surely fail). For code completion this is the wrong tradeoff: the point of the parse is to generate completions as a side-effect. Today, when the ctor body wasn't typed yet there are no init list completions. With this patch we parse such an init-list if it contains the completion point. There's one caveat: the parser has to decide where to resume parsing members after a broken init list. Often the first clear recovery point is *after* the next member, so that member is missing from completion/signature help etc. e.g. struct S { S() m //<- completion here int maaa; int mbbb; } Here "int maaa;" is treated as part of the init list, so "maaa" is not available as a completion. Maybe in future indentation can be used to recognize that this is a separate member, not part of the init list. Differential Revision: https://reviews.llvm.org/D116294
2022-01-12[clang][CodeComplete] Perform approximate member search in basesKadir Cetinkaya1-0/+15
Differential Revision: https://reviews.llvm.org/D117037
2022-01-11[CodeCompletion] Complete designators for fields in anonymous structs/unionsSam McCall1-0/+8
Fixes https://github.com/clangd/clangd/issues/836 Differential Revision: https://reviews.llvm.org/D116717
2022-01-04[CodeCompletion] Signature help for aggregate initialization.Sam McCall1-5/+21
The "parameter list" is the list of fields which should be initialized. We introduce a new OverloadCandidate kind for this. It starts to become harder for CC consumers to handle all the cases for params, so I added some extra APIs on OverloadCandidate to abstract them. Includes some basic support for designated initializers. The same aggregate signature is shown, the current arg jumps after the one you just initialized. This follows C99 semantics for mixed designated/positional initializers (which clang supports in C++ as an extension) and is also a useful prompt for C++ as C++ designated initializers must be in order. Related bugs: - https://github.com/clangd/clangd/issues/965 - https://github.com/clangd/clangd/issues/306 Differential Revision: https://reviews.llvm.org/D116326
2022-01-03[CodeCompletion] Signature help for braced constructor callsSam McCall1-0/+37
Implementation is based on the "expected type" as used for designated-initializers in braced init lists. This means it can deduce the type in some cases where it's not written: void foo(Widget); foo({ /*help here*/ }); Only basic constructor calls are in scope of this patch, excluded are: - aggregate initialization (no help is offered for aggregates) - initializer_list initialization (no help is offered for these constructors) Fixes https://github.com/clangd/clangd/issues/306 Differential Revision: https://reviews.llvm.org/D116317
2022-01-03[CodeCompletion] Signature help for template argument listsSam McCall1-0/+28
Provide signature while typing template arguments: Foo< ^here > Here the parameters are e.g. "typename x", and the result type is e.g. "struct" (class template) or "int" (variable template) or "bool (std::string)" (function template). Multiple overloads are possible when a template name is used for several overloaded function templates. Fixes https://github.com/clangd/clangd/issues/299 Differential Revision: https://reviews.llvm.org/D116352
2021-11-18[clang][clangd] Improve signature help for variadic functions.Adam Czachorowski1-0/+18
This covers both C-style variadic functions and template variadic w/ parameter packs. Previously we would return no signatures when working with template variadic functions once activeParameter reached the position of the parameter pack (except when it was the only param, then we'd still show it when no arguments were given). With this commit, we now show signathure help correctly. Additionally, this commit fixes the activeParameter value in LSP output of clangd in the presence of variadic functions (both kinds). LSP does not allow the activeParamter to be higher than the number of parameters in the active signature. With "..." or parameter pack being just one argument, for all but first argument passed to "..." we'd report incorrect activeParameter value. Clients such as VSCode would then treat it as 0, as suggested in the spec) and highlight the wrong parameter. In the future, we should add support for per-signature activeParamter value, which exists in LSP since 3.16.0. This is not part of this commit. Differential Revision: https://reviews.llvm.org/D111318
2021-11-10[CodeCompletion] Generally consider header files without extensionChristian Kandeler1-7/+29
Real-world use case: The Qt framework's headers have the same name as the respective class defined in them, and Qt's traditional qmake build tool uses -I (rather than -isystem) to pull them in. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D112996
2021-09-28Diagnose -Wunused-value based on CFG reachabilityYuanfang Chen1-1/+1
(This relands 59337263ab45d7657e and makes sure comma operator diagnostics are suppressed in a SFINAE context.) While at it, add the diagnosis message "left operand of comma operator has no effect" (used by GCC) for comma operator. This also makes Clang diagnose in the constant evaluation context which aligns with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96) Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D103938
2021-09-23Revert "Diagnose -Wunused-value based on CFG reachability"Yuanfang Chen1-1/+1
This reverts commit cbbf2e8c8ae7730ff0121f4868de4a7d188feb65. It seems causing diagnoses in SFINAE context.
2021-09-22Diagnose -Wunused-value based on CFG reachabilityYuanfang Chen1-1/+1
While at it, add the diagnosis message "left operand of comma operator has no effect" (used by GCC) for comma operator. This also makes Clang diagnose in the constant evaluation context which aligns with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96) Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D103938
2021-09-21Revert "Diagnose -Wunused-value based on CFG reachability"Aaron Ballman1-1/+1
This reverts commit 63e0d038fc20c894a3d541effa1bc2b1fdea37b9. It causes test failures: http://lab.llvm.org:8011/#/builders/119/builds/5612 https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8835548361443044001/+/u/clang/test/stdout
2021-09-20Diagnose -Wunused-value based on CFG reachabilityYuanfang Chen1-1/+1
While at it, add the diagnosis message "left operand of comma operator has no effect" (used by GCC) for comma operator. This also makes Clang diagnose in the constant evaluation context which aligns with GCC/MSVC behavior. (https://godbolt.org/z/7zxb8Tx96) Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D103938
2021-08-19[CodeCompletion] Provide placeholders for known attribute argumentsSam McCall1-62/+64
Completion now looks more like function/member completion: used alias(Aliasee) abi_tag(Tags...) Differential Revision: https://reviews.llvm.org/D108109