aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCodeComplete.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-06-25[Sema][CodeComplete][ObjC] Don't split the first selector fragmentDavid Goldman1-34/+38
Summary: Standardize the formatting of selector fragments to include the ':', e.g. for `- (void)foobar:(int)foobar;`, report `{foobar:}` instead of `{foobar}{:}`. This was normally the case except for a couple of places where it was split. This also improves integration with clangd since it relies upon the `:` to identify ObjC selectors. NOTE: It is possible to have selector fragments that are just `:` with no text, we now handle this properly for the first fragment. Reviewers: sammccall, doug.gregor Subscribers: ilya-biryukov, dexonsmith, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82306
2020-06-08[Sema][CodeComplete][ObjC] Don't include arrow/dot fixitsDavid Goldman1-2/+12
Summary: Exempt ObjC from arrow/dot fixits since this has limited value for Objective-C, where properties (referenced by dot syntax) are normally backed by ivars (referenced by arrow syntax). In addition, the current implementation doesn't properly mark the fix it condition for Objective-C. This was initially added in https://reviews.llvm.org/D41537 for C++ and then later C, don't believe the Objective-C changes were intentional. Reviewers: sammccall, yvvan Subscribers: jfb, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D81263
2020-04-23[NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ObjCDeclSpec.Puyan Lotfi1-24/+37
This is a code clean up of the PropertyAttributeKind and ObjCPropertyAttributeKind enums in ObjCPropertyDecl and ObjCDeclSpec that are exactly identical. This non-functional change consolidates these enums into one. The changes are to many files across clang (and comments in LLVM) so that everything refers to the new consolidated enum in DeclObjCCommon.h. 2nd Landing Attempt... Differential Revision: https://reviews.llvm.org/D77233
2020-04-23Revert "[NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ↵Puyan Lotfi1-37/+24
ObjCDeclSpec." This reverts commit 2aa044ed088ae41461ad7029c055014df6c60976. Reverting due to bot failure in lldb.
2020-04-22[NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ObjCDeclSpec.Puyan Lotfi1-24/+37
This is a code clean up of the PropertyAttributeKind and ObjCPropertyAttributeKind enums in ObjCPropertyDecl and ObjCDeclSpec that are exactly identical. This non-functional change consolidates these enums into one. The changes are to many files across clang (and comments in LLVM) so that everything refers to the new consolidated enum in DeclObjCCommon.h. Differential Revision: https://reviews.llvm.org/D77233
2020-03-31[CodeComplete] Member completion for concept-constrained types.Sam McCall1-12/+409
Summary: The basic idea is to walk through the concept definition, looking for t.foo() where t has the constrained type. In this patch: - nested types are recognized and offered after :: - variable/function members are recognized and offered after the correct dot/arrow/colon trigger - member functions are recognized (anything directly called). parameter types are presumed to be the argument types. parameters are unnamed. - result types are available when a requirement has a type constraint. These are printed as constraints, except same_as<T> which prints as T. Not in this patch: - support for merging/overloading when two locations describe the same member. The last one wins, for any given name. This is probably important... - support for nested template members (T::x<int>) - support for completing members of (instantiations of) template template parameters Reviewers: nridge, saar.raz Subscribers: mgrang, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73649
2020-02-19[Sema][CodeComplete] Handle symlinks for include code completionDavid Goldman1-1/+10
Summary: Previously any symlinks would be ignored since the directory traversal doesn't follow them. With this change we now follow symlinks (via a `stat` call in order to figure out the target type of the symlink if it is valid). Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D74790
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-5/+5
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28[clang][CodeComplete] Support for designated initializersKadir Cetinkaya1-16/+65
Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73271
2020-01-20[clang][CodeComplete] Propogate printing policy to FunctionDeclKadir Cetinkaya1-2/+6
Summary: Printing policy was not propogated to functiondecls when creating a completion string which resulted in canonical template parameters like `foo<type-parameter-0-0>`. This patch propogates printing policy to those as well. Fixes https://github.com/clangd/clangd/issues/76 Reviewers: ilya-biryukov Subscribers: jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72715
2020-01-15[Concepts] Type ConstraintsSaar Raz1-1/+5
Add support for type-constraints in template type parameters. Also add support for template type parameters as pack expansions (where the type constraint can now contain an unexpanded parameter pack). Differential Revision: https://reviews.llvm.org/D44352
2020-01-11Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim1-6/+6
Use castAs<> instead of getAs<> since the pointers are dereferenced immediately and castAs will perform the null assertion for us.
2020-01-10[CodeComplete] Suggest 'return nullptr' in functions returning pointersIlya Biryukov1-0/+7
Reviewers: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72497
2019-12-17[Sema] Fixes -Wrange-loop-analysis warningsMark de Wever1-1/+1
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71529
2019-11-22[clangd] Show lambda signature for lambda autocompletionsKirill Bobyrev1-3/+27
The original bug report can be found [here](https://github.com/clangd/clangd/issues/85) Given the following code: ```c++ void function() { auto Lambda = [](int a, double &b) {return 1.f;}; La^ } ``` Triggering the completion at `^` would show `(lambda)` before this patch and would show signature `(int a, double &b) const`, build a snippet etc with this patch. Reviewers: sammccall Reviewed by: sammccall Differential revision: https://reviews.llvm.org/D70445
2019-11-19[CGDebugInfo] Emit subprograms for decls when AT_tail_call is understood ↵Vedant Kumar1-14/+2
(reland with fixes) Currently, clang emits subprograms for declared functions when the target debugger or DWARF standard is known to support entry values (DW_OP_entry_value & the GNU equivalent). Treat DW_AT_tail_call the same way to allow debuggers to follow cross-TU tail calls. Pre-patch debug session with a cross-TU tail call: ``` * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt] frame #1: 0x0000000100000f99 main`main at a.c:8:10 [opt] ``` Post-patch (note that the tail-calling frame, "helper", is visible): ``` * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt] frame #1: 0x0000000100000f80 main`helper [opt] [artificial] frame #2: 0x0000000100000f99 main`main at a.c:8:10 [opt] ``` This was reverted in 5b9a072c because it attached declaration subprograms to inlinable builtin calls, which interacted badly with the MergeICmps pass. The fix is to not attach declarations to builtins. rdar://46577651 Differential Revision: https://reviews.llvm.org/D69743
2019-11-15[CodeComplete] Constructor overload candidates report as vector(int) instead ↵Sam McCall1-0/+4
of vector<string>(int) Summary: This is shorter, shouldn't be confusing (is consistent with how they're declared), and avoids messy cases that are printed as myclass<type-param-0-0>(int) in the case of partial specialization. Fixes part of https://github.com/clangd/clangd/issues/76 Reviewers: hokein, lh123 Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70307
2019-10-28[clangd] Do not insert parentheses when completing a using declarationIlya Biryukov1-17/+16
Summary: Would be nice to also fix this in clang, but that looks like more work if we want to preserve signatures in informative chunks. Fixes https://github.com/clangd/clangd/issues/118 Reviewers: kadircet Reviewed By: kadircet Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69382
2019-10-04[CodeComplete] Ensure object is the same in compareOverloads()Ilya Biryukov1-0/+3
Summary: This fixes a regression that led to size() not being available in clangd when completing 'deque().^' and using libc++. Reviewers: sammccall Reviewed By: sammccall Subscribers: jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68335 llvm-svn: 373710
2019-07-18[CodeComplete] Fix ASTUnit cached completion of macros from preamble, broken ↵Sam McCall1-4/+2
in r342528 Summary: The problem is the default LoadExternal with no completer, which happens when loading global results. Reviewers: ilya-biryukov, nik Subscribers: arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64864 llvm-svn: 366409
2019-07-16Fix parameter name comments using clang-tidy. NFC.Rui Ueyama1-5/+5
This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
2019-06-14Use getOperatorSpelling to get the spelling of an overloaded operatorRichard Smith1-2/+3
rather than duplicating operator name tables in multiple places. llvm-svn: 363446
2019-06-10Re-land "[CodeComplete] Improve overload handling for C++ qualified and ↵Sam McCall1-20/+121
ref-qualified methods." ShadowMapEntry is now really, truly a normal class. llvm-svn: 362950
2019-06-10Revert "[CodeComplete] Improve overload handling for C++ qualified and ↵Sam McCall1-112/+20
ref-qualified methods." This reverts commit r362924, which causes a double-free of ShadowMapEntry. llvm-svn: 362944
2019-06-10Revert "Revert "[CodeComplete] Improve overload handling for C++ qualified ↵Sam McCall1-20/+112
and ref-qualified methods."" This reverts commit r362830, and relands r362785 with the leak fixed. llvm-svn: 362924
2019-06-07Revert "[CodeComplete] Improve overload handling for C++ qualified and ↵Vlad Tsyrklevich1-111/+14
ref-qualified methods." This reverts commit f1f6e0fc2468e9c120b22b939507c527d08b8ee8, it was causing LSan failures on the sanitizer bots: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/32809 llvm-svn: 362830
2019-06-07[CodeComplete] Improve overload handling for C++ qualified and ref-qualified ↵Sam McCall1-14/+111
methods. Summary: - when a method is not available because of the target value kind (e.g. an && method on a Foo& variable), then don't offer it. - when a method is effectively shadowed by another method from the same class with a) an identical argument list and b) superior qualifiers, then don't offer it. Reviewers: ilya-biryukov Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62582 llvm-svn: 362785
2019-06-04[CodeComplete] Include more text into typed chunks of pattern completionsIlya Biryukov1-12/+4
Summary: To allow filtering on any of the words in the editors. In particular, the following completions were changed: - 'using namespace <#name#>' Typed text before: 'using', after: 'using namespace'. - 'else if (#<condition#>)' Before: 'else', after: 'else if'. - 'using typename <#qualifier#>::<#name#>' Before: 'using', after: 'using typename'. Reviewers: sammccall Reviewed By: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62615 llvm-svn: 362479
2019-06-03[CodeComplete] Add a bit more whitespace to completed patternsIlya Biryukov1-0/+17
Summary: E.g. we now turn `while(<#cond#>){` into `while (<#cond#>) {` This slightly improves the final output. Should not affect clients that format the result on their own. Reviewers: gribozavr Reviewed By: gribozavr Subscribers: jkorous, arphaman, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62616 llvm-svn: 362363
2019-05-29[CodeComplete] Add semicolon when completing patterns for 'static_assert' ↵Ilya Biryukov1-0/+2
and 'typedef This is a trivial follow-up to r360042, which added semicolons to other pattern completions, so sending without review. llvm-svn: 361974
2019-05-28[CodeComplete] Set preferred type for qualified-idIlya Biryukov1-5/+11
Reviewers: kadircet Reviewed By: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62514 llvm-svn: 361838
2019-05-28[CodeComplete] Consistently break after '{' in multi-line patternsIlya Biryukov1-0/+8
Summary: Completion can return multi-line patterns in some cases, e.g. for (<#init#>; <#cond#>; <#inc#>) { <#body#> } However, most patterns break the line only before closing brace, resulting in code like: namespace <#name#> { <#decls#> } While some (e.g. the 'for' example above) are breaking lines after the opening brace too. This change ensures all patterns consistently break after the opening brace, this leads to nicer UX when using those in an actual editor. Reviewers: gribozavr Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62405 llvm-svn: 361829
2019-05-27[CodeComplete] Complete 'return true/false' in boolean functionsIlya Biryukov1-11/+26
Reviewers: kadircet Reviewed By: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62391 llvm-svn: 361753
2019-05-24[CodeComplete] Add whitespace around braces in lambda completionsIlya Biryukov1-0/+3
This produces nicer output. Trivial follow-up to r361461, so sending without review. llvm-svn: 361645
2019-05-24[CodeComplete] Filter override completions by function nameIlya Biryukov1-18/+29
Summary: We put only part of the signature starting with a function name into "typed text" chunks now, previously the whole signature was "typed text". This leads to meaningful fuzzy match scores, giving better signals to compare with other completion items. Ideally, we would not display the result type to the user, but that requires adding a new kind of completion chunk. Reviewers: kadircet Reviewed By: kadircet Subscribers: jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62298 llvm-svn: 361623
2019-05-23[CodeComplete] Only show lambda completions if patterns are requestedIlya Biryukov1-0/+2
This is a trivial follow-up to r361461, so sending without review. llvm-svn: 361510
2019-05-23[CodeComplete] Complete a lambda when preferred type is a functionIlya Biryukov1-0/+71
Summary: Uses a heuristic to detect std::function and friends. Reviewers: kadircet Reviewed By: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62238 llvm-svn: 361461
2019-05-16[CodeComplete] Complete enumerators when preferred type is an enumIlya Biryukov1-21/+44
Reviewers: kadircet Reviewed By: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62010 llvm-svn: 360912
2019-05-09[c++20] Add support for explicit(bool), as described in P0892R2.Richard Smith1-1/+2
Patch by Tyker! Differential Revision: https://reviews.llvm.org/D60934 llvm-svn: 360311
2019-05-06[CodeComplete] Add a trailing semicolons to some pattern completionsIlya Biryukov1-0/+9
Summary: Where semicolon is required in any case. Here's a list of completions that now have a semicolon: - namespace <name> = <target>; - using namespace <name>; - using <qualifier>::<name>; - continue; - break; - goto <label>; - return; - return <expression>; Reviewers: gribozavr Reviewed By: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61589 llvm-svn: 360042
2019-05-06Revert r359949 "[clang] adding explicit(bool) from c++2a"Hans Wennborg1-4/+2
This caused Clang to start erroring on the following: struct S {   template <typename = int> explicit S(); }; struct T : S {}; struct U : T {   U(); }; U::U() {} $ clang -c /tmp/x.cc /tmp/x.cc:10:4: error: call to implicitly-deleted default constructor of 'T' U::U() {}    ^ /tmp/x.cc:5:12: note: default constructor of 'T' is implicitly deleted because base class 'S' has no default constructor struct T : S {};            ^ 1 error generated. See discussion on the cfe-commits email thread. This also reverts the follow-ups r359966 and r359968. > this patch adds support for the explicit bool specifier. > > Changes: > - The parsing for the explicit(bool) specifier was added in ParseDecl.cpp. > - The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class. > - Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted. > - Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration. > - The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected. > - Test for Semantic and Serialization were added. > > This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback. > Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky. > > Patch by Tyker > > Differential Revision: https://reviews.llvm.org/D60934 llvm-svn: 360024
2019-05-04[clang] adding explicit(bool) from c++2aNicolas Lesser1-2/+4
this patch adds support for the explicit bool specifier. Changes: - The parsing for the explicit(bool) specifier was added in ParseDecl.cpp. - The storage of the explicit specifier was changed. the explicit specifier was stored as a boolean value in the FunctionDeclBitfields and in the DeclSpec class. now it is stored as a PointerIntPair<Expr*, 2> with a flag and a potential expression in CXXConstructorDecl, CXXDeductionGuideDecl, CXXConversionDecl and in the DeclSpec class. - Following the AST change, Serialization, ASTMatchers, ASTComparator and ASTPrinter were adapted. - Template instantiation was adapted to instantiate the potential expressions of the explicit(bool) specifier When instantiating their associated declaration. - The Add*Candidate functions were adapted, they now take a Boolean indicating if the context allowing explicit constructor or conversion function and this boolean is used to remove invalid overloads that required template instantiation to be detected. - Test for Semantic and Serialization were added. This patch is not yet complete. I still need to check that interaction with CTAD and deduction guides is correct. and add more tests for AST operations. But I wanted first feedback. Perhaps this patch should be spited in smaller patches, but making each patch testable as a standalone may be tricky. Patch by Tyker Differential Revision: https://reviews.llvm.org/D60934 llvm-svn: 359949
2019-04-24Use llvm::stable_sortFangrui Song1-16/+13
llvm-svn: 359098
2019-04-04[CodeComplete] Fix crash when completing ObjC block parameter with a broken typeSam McCall1-0/+5
Summary: The fix isn't great, but it's hard to fix properly because the completion code sensibly uses ParmVarDecl to represent parameters, but the AST-building code sensibly doesn't synthesize them if the type is broken. Also this case is apparently really rare, so it's probably not worth bending over backwards for. Reviewers: ilya-biryukov Subscribers: javed.absar, kristof.beyls, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60258 llvm-svn: 357686
2019-03-26Basic: Return a reference from FileManager::getVirtualFileSystem, NFCDuncan P. N. Exon Smith1-2/+3
FileManager constructs a VFS in its constructor if it isn't passed one, and there's no way to reset it. Make that contract clear by returning a reference from its accessor. https://reviews.llvm.org/D59388 llvm-svn: 357038
2019-03-25[Sema][NFCI] Don't allocate storage for the various ↵Bruno Ricci1-2/+3
CorrectionCandidateCallback unless we are going to do some typo correction The various CorrectionCandidateCallbacks are currently heap-allocated unconditionally. This was needed because of delayed typo correction. However these allocations represent currently 15.4% of all allocations (number of allocations) when parsing all of Boost (!), mostly because of ParseCastExpression, ParseStatementOrDeclarationAfterAttrtibutes and isCXXDeclarationSpecifier. Note that all of these callback objects are small. Let's not do this. Instead initially allocate the callback on the stack, and only do a heap allocation if we are going to do some typo correction. Do this by: 1. Adding a clone function to each callback, which will do a polymorphic clone of the callback. This clone function is required to be implemented by every callback (of which there is a fair amount). Make sure this is the case by making it pure virtual. 2. Use this clone function when we are going to try to correct a typo. This additionally cut the time of -fsyntax-only on all of Boost by 0.5% (not that much, but still something). No functional changes intended. Differential Revision: https://reviews.llvm.org/D58827 Reviewed By: rnk llvm-svn: 356925
2019-02-27Support framework import/include auto-completionDavid Goldman1-6/+28
Frameworks filesystem representations: UIKit.framework/Headers/%header% Framework import format: #import <UIKit/%header%> Thus the completion code must map the input format of <UIKit/> to the path of UIKit.framework/Headers as well as strip the ".framework" suffix when auto-completing the framework name. llvm-svn: 355008
2019-02-26[CodeComplete] Propagate preferred type for function arguments in more casesIlya Biryukov1-2/+22
Summary: See the added test for some new cases. This change also removes special code completion calls inside the ParseExpressionList function now that we properly propagate expected type to the function responsible for parsing elements of the expression list (ParseAssignmentExpression). Reviewers: kadircet Reviewed By: kadircet Subscribers: xbolva00, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58541 llvm-svn: 354864
2019-02-21[CodeComplete] Collect visited contexts when scope specifier is invalid.Eric Liu1-1/+14
Summary: This will allow completion consumers to guess the specified scope by putting together scopes in the context with the specified scope (e.g. when the specified namespace is not imported yet). Reviewers: ilya-biryukov Subscribers: jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58446 llvm-svn: 354570
2019-02-11Make some helper functions static. NFC.Benjamin Kramer1-2/+2
llvm-svn: 353705