Commit Graph

7268 Commits

Author SHA1 Message Date
Nathan Ridge e37653da13 [clangd] Type hints for C++14 return type deduction
Differential Revision: https://reviews.llvm.org/D103789
2021-06-21 01:13:00 -04:00
Felix Berger bdd5da9dec [clang-tidy] performance-unnecessary-copy-initialization: Directly examine the initializing var's initializer.
This fixes false positive cases where a reference is initialized outside of a
block statement and then its initializing variable is modified. Another case is
when the looped over container is modified.

Differential Revision: https://reviews.llvm.org/D103021

Reviewed-by: ymandel
2021-06-18 15:25:17 -04:00
Haojian Wu 6765b9c3f1 [clangd] Explicitly fail if the file passed to --check is not valid.
Differential Revision: https://reviews.llvm.org/D104455
2021-06-17 16:41:06 +02:00
Kadir Cetinkaya 204014ec75
[clangd] Fix feature modules to drop diagnostics
Ignored diagnostics were only checked after level adjusters and assumed
it would stay the same for the rest. But it can also be modified by
FeatureModules.

Differential Revision: https://reviews.llvm.org/D103387
2021-06-17 09:29:29 +02:00
Kadir Cetinkaya b662651586
[clangd] Use command line adjusters for inserting compile flags
This fixes issues with `--` in the compile flags.

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

Differential Revision: https://reviews.llvm.org/D99523
2021-06-17 09:24:53 +02:00
Sam McCall 6aca6032c5 [AST] Include the TranslationUnitDecl when traversing with TraversalScope
Given `int foo, bar;`, TraverseAST reveals this tree:
  TranslationUnitDecl
   - foo
   - bar

Before this patch, with the TraversalScope set to {foo}, TraverseAST yields:
  foo

After this patch it yields:
  TranslationUnitDecl
  - foo

Also, TraverseDecl(TranslationUnitDecl) now respects the traversal scope.

---

The main effect of this today is that clang-tidy checks that match the
translationUnitDecl(), either in order to traverse it or check
parentage, should work.

Differential Revision: https://reviews.llvm.org/D104071
2021-06-11 14:29:45 +02:00
Simon Pilgrim 61cdaf66fe [ADT] Remove APInt/APSInt toString() std::string variants
<string> is currently the highest impact header in a clang+llvm build:

https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html

One of the most common places this is being included is the APInt.h header, which needs it for an old toString() implementation that returns std::string - an inefficient method compared to the SmallString versions that it actually wraps.

This patch replaces these APInt/APSInt methods with a pair of llvm::toString() helpers inside StringExtras.h, adjusts users accordingly and removes the <string> from APInt.h - I was hoping that more of these users could be converted to use the SmallString methods, but it appears that most end up creating a std::string anyhow. I avoided trying to use the raw_ostream << operators as well as I didn't want to lose having the integer radix explicit in the code.

Differential Revision: https://reviews.llvm.org/D103888
2021-06-11 13:19:15 +01:00
Haojian Wu d30c202d27 [clangd] don't rename if the triggering loc is not actually being renamed.
See context: https://github.com/clangd/clangd/issues/765

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101816
2021-06-11 13:51:50 +02:00
Haojian Wu 1a53fb0596 [clang-tidy] NarrowingConversionsCheck should support inhibiting conversions of
mixed integer and floating point types with WarnOnEquivalentBitWidth=0.

Also standardize control flow of handleX conversion functions to make it easier to be consistent.

Patch by Stephen Concannon!

Differential Revision: https://reviews.llvm.org/D103894
2021-06-11 13:02:48 +02:00
Ivan Murashko 47d138c939 [clang-tidy] LIT test fix for Remark diagnostic
There is a followup fix for a unit test introduced at D102906. The test file was placed into a temp folder and test assumed that it would be visible without the full path specification.

This behaviour can be changed in future and it would be good to specify full path to the file at the test.

Test Plan:
```
ninja check-clang-tools
```

Reviewed By: DmitryPolukhin

Differential Revision: https://reviews.llvm.org/D104021
2021-06-11 02:02:36 -07:00
Guillaume Chatelet 89c41c335d [clang-tidy] Allow disabling integer narrowing conversions for cppcoreguidelines-narrowing-conversions
Differential Revision: https://reviews.llvm.org/D104018
2021-06-10 12:41:57 +00:00
Simon Pilgrim 0ce61d47c0 Add explicit braces to silence warning about ambiguous 'else' inside the EXPECT_EQ macro. NFCI. 2021-06-10 10:55:24 +01:00
Felix Berger efa4dbc32c [clang-tidy] performance-unnecessary-copy-initialization: Look at the canonical type when checking for aliases.
This fixes a false positive case where for instance a pointer is obtained and declared using `auto`.

Differential Revision: https://reviews.llvm.org/D103018

Reviewed-by: ymandel
2021-06-09 16:36:53 -04:00
Felix Berger 5dbe3bf4b8 [clang-tidy] performance-unnecessary-copy-initialization: Remove the complete statement when the copied variable is unused.
It is not useful to keep the statement around and can lead to compiler
warnings when -Wall (-Wunused-variable specifically) turned on.

Differential Revision: https://reviews.llvm.org/D102175

Reviewed-by: ymandel
2021-06-09 15:52:48 -04:00
Matheus Izvekov aef5d8fdc7 [clang] NFC: Rename rvalue to prvalue
This renames the expression value categories from rvalue to prvalue,
keeping nomenclature consistent with C++11 onwards.

C++ has the most complicated taxonomy here, and every other language
only uses a subset of it, so it's less confusing to use the C++ names
consistently, and mentally remap to the C names when working on that
context (prvalue -> rvalue, no xvalues, etc).

Renames:
* VK_RValue -> VK_PRValue
* Expr::isRValue -> Expr::isPRValue
* SK_QualificationConversionRValue -> SK_QualificationConversionPRValue
* JSON AST Dumper Expression nodes value category: "rvalue" -> "prvalue"

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D103720
2021-06-09 12:27:10 +02:00
Nathan Sidwell b2d0c16e91 [clang] p1099 using enum part 2
This implements the 'using enum maybe-qualified-enum-tag ;' part of
1099. It introduces a new 'UsingEnumDecl', subclassed from
'BaseUsingDecl'. Much of the diff is the boilerplate needed to get the
new class set up.

There is one case where we accept ill-formed, but I believe this is
merely an extended case of an existing bug, so consider it
orthogonal. AFAICT in class-scope the c++20 rule is that no 2 using
decls can bring in the same target decl ([namespace.udecl]/8). But we
already accept:

struct A { enum { a }; };
struct B : A { using A::a; };
struct C : B { using A::a;
using B::a; }; // same enumerator

this patch permits mixtures of 'using enum Bob;' and 'using Bob::member;' in the same way.

Differential Revision: https://reviews.llvm.org/D102241
2021-06-08 11:11:46 -07:00
Kirill Bobyrev d12000ca55
[clangd] Bump recommended gRPC version (1.33.2 -> 1.36.3)
Context: https://github.com/clangd/clangd/pull/783

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D103393
2021-06-07 15:36:33 +02:00
Nathan Sidwell ddda05add5 [clang][NFC] Break out BaseUsingDecl from UsingDecl
This is a pre-patch for adding using-enum support.  It breaks out
the shadow decl handling of UsingDecl to a new intermediate base
class, BaseUsingDecl, altering the decl hierarchy to

def BaseUsing : DeclNode<Named, "", 1>;
  def Using : DeclNode<BaseUsing>;
def UsingPack : DeclNode<Named>;
def UsingShadow : DeclNode<Named>;
  def ConstructorUsingShadow : DeclNode<UsingShadow>;

Differential Revision: https://reviews.llvm.org/D101777
2021-06-07 06:29:28 -07:00
Kadir Cetinkaya 4728aca9a8
[clangd] Drop TestTUs dependency on gtest
TestTU now prints errors to llvm::errs and aborts on failures via
llvm_unreachable, rather than executing ASSERT_FALSE.

We'd like to make use of these testing libraries in different test suits that
might be compiling with a different gtest version than LLVM has.

Differential Revision: https://reviews.llvm.org/D103685
2021-06-07 13:25:22 +02:00
Adam Czachorowski eba3ee04d4 [clangd] Run code completion on each token coverd by --check-lines
In --check mode we do not run code completion because it is too slow,
especially on larger files. With the introducation of --check-lines we
can narrow down the scope and thus we can afford to do code completion.

We vlog() the top completion result, but that's not really the point.
The most value will come from being able to reproduce crashes that occur
during code completion and require preamble build or index (and thus are
more difficult to reproduce with -code-complete-at).

Differential Revision: https://reviews.llvm.org/D103538
2021-06-04 17:51:42 +02:00
Nathan Ridge f976b9997e [clangd] Improve resolution of static method calls in HeuristicResolver
Differential Revision: https://reviews.llvm.org/D101741
2021-06-02 20:30:19 -04:00
Kadir Cetinkaya 9e9ac41388
[clangd] Drop optional on ExternalIndexSpec
Differential Revision: https://reviews.llvm.org/D100308
2021-06-02 23:26:37 +02:00
Kadir Cetinkaya dc10bf1a4e
[clangd][Protocol] Drop optional from WorkspaceEdit::changes
This is causing weird code patterns in various places and I can't see
any difference between None and empty change list. Neither in the current use
cases nor in the spec.

Differential Revision: https://reviews.llvm.org/D103449
2021-06-02 22:59:18 +02:00
Kadir Cetinkaya 6c2a4e28f4
[clangd] TUScheduler uses last active file for file-less queries
This enables requests like workspaceSymbols to be dispatched using the
file user was most recently operating on. A replacement for D103179.

Differential Revision: https://reviews.llvm.org/D103476
2021-06-02 22:50:24 +02:00
David Goldman 2f951ca98b [clangd] Add support for the `defaultLibrary` semantic token modifier
This allows us to differentiate symbols from the system (e.g. system
includes or sysroot) differently than symbols defined in the user's
project, which can be used by editors to display them differently.

This is currently based on `FileCharacteristic`, but we can
consider alternatives such as `Sysroot` and file paths in the future.

Differential Revision: https://reviews.llvm.org/D101554
2021-06-02 10:24:29 -04:00
David Goldman 13a8aa3ee1 [clang] RecursiveASTVisitor visits ObjCPropertyRefExpr's class receiver
We now make up a TypeLoc for the class receiver to simplify visiting,
notably for indexing, availability, and clangd.

Differential Revision: https://reviews.llvm.org/D101645
2021-06-01 14:45:25 -04:00
David Goldman 2a030e680e [clangd][ObjC] Fix issue completing a method decl by name
When completing an Objective-C method declaration by name, we need to
preserve the leading text as a `qualifier` so we insert it properly
before the first typed text chunk.

Differential Revision: https://reviews.llvm.org/D100798
2021-06-01 13:35:05 -04:00
Yang Fan 5b747197f8
[clangd] Fix -Wunused-variable warning (NFC)
GCC warning:
```
/llvm-project/clang-tools-extra/clangd/InlayHints.cpp: In member function ‘bool clang::clangd::InlayHintVisitor::VisitVarDecl(clang::VarDecl*)’:
/llvm-project/clang-tools-extra/clangd/InlayHints.cpp:81:15: warning: unused variable ‘AT’ [-Wunused-variable]
   81 |     if (auto *AT = D->getType()->getContainedAutoType()) {
      |               ^~

```
2021-06-01 16:15:09 +08:00
Nathan Ridge 0be2657c2f [clangd] Type hints for variables with 'auto' type
Differential Revision: https://reviews.llvm.org/D102148
2021-06-01 02:21:02 -04:00
Kadir Cetinkaya e972068840
[clangd] Move gtest include to TestTU.cpp from TestTU.h 2021-05-31 07:56:56 +02:00
Roman Lebedev be6b9e8ae7
Revert "[clang-tidy] Simplify static assert check"
This patch starts to produce a very obvious false-positives,
despite the fact the preexisting tests already cover the pattern.
they clearly don't actually cover it.

https://godbolt.org/z/3zdqvbfxj

This reverts commit 1709bb8c73.
2021-05-30 16:44:31 +03:00
Kadir Cetinkaya 8f79203a22
[clangd] New ParsingCallback for semantics changes
Previously notification of the Server about semantic happened strictly
before notification of the AST thread.
Hence a racy Server could make a request (like semantic tokens) after
the notification, with the assumption that it'll be served fresh
content. But it wasn't true if AST thread wasn't notified about the
change yet.

This change reverses the order of those notifications to prevent racy
interactions.

Differential Revision: https://reviews.llvm.org/D102761
2021-05-26 16:57:30 +02:00
Ivan Murashko 7f2f0247f8 Remark was added to clang tooling Diagnostic
The diff adds Remark to Diagnostic::Level for clang tooling. That makes
Remark diagnostic level ready to use in clang-tidy checks: the
clang-diagnostic-module-import becomes visible as a part of the change.
2021-05-24 11:21:44 -04:00
Haojian Wu 775ca3a89c [clang-tidy] Fix a crash for raw-string-literal check.
getSourceText could return an empty string for error cases (e.g. invalid
source locaiton), this patch makes the code more robust.

The crash did happen in our internal codebase, but unfortunately I
didn't manage to get a reproduce case. One thing I can confirm from
the core dump is that the crash is caused by calling isRawStringLiteral
on an empty Text.

Differential Revision: https://reviews.llvm.org/D102770
2021-05-20 09:16:43 +02:00
Haojian Wu 9f36306cc9 [clang-tidy] Fix a crash on invalid code for memset-usage check.
Differential Revision: https://reviews.llvm.org/D102714
2021-05-19 09:53:18 +02:00
Georgy Komarov ab92a4c26f
[clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type
We can only use ASTContext::getTypeInfo for complete types.

This fixes bugzilla issue 50313.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D102569
2021-05-17 16:50:47 +03:00
Kadir Cetinkaya ec2f7376e3
[clangd][QueryDriver] Dont check for existence of driver
Execute implementations already checks for permissions and existence
and returns relevant errors as necessary, so instead of printing our own errors,
we just print theirs.

This also fixes a case in windows where the driver might be missing the `.exe`
suffix. Previously, clangd would reject such a driver because sys::fs::exists is
strict, whereas the underlying Execute implementation would check with `.exe`
suffix too.

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

Differential Revision: https://reviews.llvm.org/D102431
2021-05-17 12:38:17 +02:00
Utkarsh Saxena 0e7c7d461d
[clangd] Set FileSystem for tweaks in Check tool.
Tweaks like DefineOutline depend on FS to be set at `apply()` time.
After https://reviews.llvm.org/D93978, tweaks run from Check tool lost
access to FS. This makes the available to apply() once again.

Differential Revision: https://reviews.llvm.org/D102519
2021-05-17 11:10:07 +02:00
Benjamin Kramer fde5b24963 [clangd] Make unit test compatible with gtest 1.10.0 2021-05-14 19:37:46 +02:00
Kadir Cetinkaya ed339111bf
[clangd] Always default to raw pch format
Clang would emit a fatal error when it encounters an unregistered PCH
format. This change ensures clangd will always use raw format no matter what
user specifies.

As side effects:

- serializing an AST in an unknown format might throw off build
systems. I suppose this would only be an issue when build system and clangd are
racing for same PCM modules, hopefully this should be rare and both clangd or
the build system should recover on the next run.

- whenever clang reads a serialized AST it seems to be checking for file
signature and emitting non-fatal errors. so this should be fine again.

The only other valid module format in clang is `obj` but it is part of codegen,
i don't think it is worth the dependency. Hence chosing to not register it, at
least yet.

Differential Revision: https://reviews.llvm.org/D102418
2021-05-14 16:34:57 +02:00
Artem Dergachev 5ad2eeeada [clang-tidy] bugprone-infinite-loop: React to ObjC ivars and messages.
If the loop condition is a value of an instance variable, a property value,
or a message result value, it's a good indication that the loop is not infinite
and we have a really hard time proving the opposite so suppress the warning.

Differential Revision: https://reviews.llvm.org/D102294
2021-05-13 11:25:02 -07:00
Artem Dergachev 46c6c08c94 [clang-tidy] bugprone-infinite-loop: forFunction() -> forCallable().
Take advantage of the new ASTMatcher added in D102213 to fix massive false negatives of the infinite loop checker on Objective-C.

Differential Revision: https://reviews.llvm.org/D102214
2021-05-13 11:25:01 -07:00
Georgy Komarov e07753c881
[clang-tidy] Fix test that requires Windows platofrm
This commit fixes the cppcoreguidelines-pro-type-vararg test when it
runs on a Windows host, but the toolchain is targeted a non-Windows
platform.

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D102337
2021-05-13 15:51:53 +03:00
Pratyush Das 99d63ccff0 Add type information to integral template argument if required.
Non-comprehensive list of cases:
 * Dumping template arguments;
 * Corresponding parameter contains a deduced type;
 * Template arguments are for a DeclRefExpr that hadMultipleCandidates()

Type information is added in the form of prefixes (u8, u, U, L),
suffixes (U, L, UL, LL, ULL) or explicit casts to printed integral template
argument, if MSVC codeview mode is disabled.

Differential revision: https://reviews.llvm.org/D77598
2021-05-12 19:00:08 +00:00
Stephen Concannon 211761332e [clang-tidy] Allow opt-in or out of some commonly occuring patterns in NarrowingConversionsCheck.
Within clang-tidy's NarrowingConversionsCheck.
* Allow opt-out of some common occurring patterns, such as:
  - Implicit casts between types of equivalent bit widths.
  - Implicit casts occurring from the return of a ::size() method.
  - Implicit casts on size_type and difference_type.
* Allow opt-in of errors within template instantiations.

This will help projects adopt these guidelines iteratively.
Developed in conjunction with Yitzhak Mandelbaum (ymandel).

Patch by Stephen Concannon!

Differential Revision: https://reviews.llvm.org/D99543
2021-05-12 20:51:25 +02:00
Malcolm Parsons 5389a05836 [docs] Fix documentation for bugprone-dangling-handle
string_view isn't experimental anymore.
This check has always handled both forms.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D102313
2021-05-12 17:20:15 +01:00
Nathan James 4c59ab34f7
[clang-tidy][NFC] Simplify a lot of bugprone-sizeof-expression matchers
There should be a follow up to this for changing the traversal mode, but some of the tests don't like that.

Reviewed By: steveire

Differential Revision: https://reviews.llvm.org/D101614
2021-05-12 13:18:41 +01:00
Hana Joo 163325086c
[clang-tidy] Enable the use of IgnoreArray flag in pro-type-member-init rule
The `IgnoreArray` flag was not used before while running the rule. Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=47288 | b/47288 ]]

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D101239
2021-05-12 12:57:21 +01:00
Kadir Cetinkaya 888307ee62
[clangd][remote-client] Set HasMore to true for failure
Currently client was setting the HasMore to true iff stream said so.
Hence if we had a broken stream for whatever reason (e.g. hitting deadline for a
huge response), HasMore would be false, which is semantically incorrect (e.g.
will throw rename off).

Differential Revision: https://reviews.llvm.org/D101915
2021-05-11 08:22:24 +02:00
Kadir Cetinkaya daf3cb3b8a
[clangd][index-sever] Limit results in repsonse
This is to prevent server from being DOS'd by possible malicious
parties issuing requests that can yield huge responses.

One possible drawback is on rename workflow. As it really requests all
occurences, but it has an internal limit on 50 files currently.
We are putting the limit on 10000 elements per response So for rename to regress
one should have 10k refs to a symbol in less than 50 files. This seems unlikely
and we fix it if there are complaints by giving up on the response based on the
number of files covered instead.

Differential Revision: https://reviews.llvm.org/D101914
2021-05-11 08:22:23 +02:00
David Blaikie 174606877d Clangd Matchers.h: Fix -Wdeprecated-copy by making the defaulted copy ctor and deleted copy assignment operators explicit 2021-05-10 14:31:11 -07:00
Artem Dergachev 91ca3269a1 [clang-tidy] Aliasing: Add support for aggregates with references.
When a variable is used in an initializer of an aggregate
for its reference-type field this counts as aliasing.

Differential Revision: https://reviews.llvm.org/D101791
2021-05-10 14:00:31 -07:00
Artem Dergachev 9b292e0edc [clang-tidy] Aliasing: Add more support for captures.
D96215 takes care of the situation where the variable is captured into
a nearby lambda. This patch takes care of the situation where
the current function is the lambda and the variable is one of its captures
from an enclosing scope.

The analogous problem for ^{blocks} is already handled automagically
by D96215.

Differential Revision: https://reviews.llvm.org/D101787
2021-05-10 14:00:30 -07:00
Artem Dergachev 43f4331edf [clang-tidy] Aliasing: Add support for captures.
The utility function clang::tidy::utils::hasPtrOrReferenceInFunc() scans the
function for pointer/reference aliases to a given variable. It currently scans
for operator & over that variable and for declarations of references to that
variable.

This patch makes it also scan for C++ lambda captures by reference
and for Objective-C block captures.

Differential Revision: https://reviews.llvm.org/D96215
2021-05-10 14:00:30 -07:00
Christian Kandeler f088af37e6
[clangd] Fix data type of WorkDoneProgressReport::percentage
According to the specification, this should be an unsigned integer.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101616
2021-05-10 14:57:20 +02:00
Frank Derry Wanye 83af66e18e new altera ID dependent backward branch check
This lint check is a part of the FLOCL (FPGA Linters for OpenCL) project
out of the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who write code
in OpenCL.

The altera ID dependent backward branch lint check finds ID dependent
variables and fields used within loops, and warns of their usage. Using
these variables in loops can lead to performance degradation.
2021-05-06 17:01:39 -04:00
David Goldman 159dd447fe [clangd][ObjC] Highlight Objc Ivar refs
Treat them just like we do for properties - as a `property` semantic
token although ideally we could differentiate the two.

Differential Revision: https://reviews.llvm.org/D101785
2021-05-06 11:41:49 -04:00
Queen Dela Cruz 16c7829784
[clangd] Check if macro is already in the IdentifierTable before loading it
Having nested macros in the C code could cause clangd to fail an assert in clang::Preprocessor::setLoadedMacroDirective() and crash.

 #1 0x00000000007ace30 PrintStackTraceSignalHandler(void*) /qdelacru/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x00000000007aaded llvm::sys::RunSignalHandlers() /qdelacru/llvm-project/llvm/lib/Support/Signals.cpp:76:20
 #3 0x00000000007ac7c1 SignalHandler(int) /qdelacru/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007f096604db20 __restore_rt (/lib64/libpthread.so.0+0x12b20)
 #5 0x00007f0964b307ff raise (/lib64/libc.so.6+0x377ff)
 #6 0x00007f0964b1ac35 abort (/lib64/libc.so.6+0x21c35)
 #7 0x00007f0964b1ab09 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21b09)
 #8 0x00007f0964b28de6 (/lib64/libc.so.6+0x2fde6)
 #9 0x0000000001004d1a clang::Preprocessor::setLoadedMacroDirective(clang::IdentifierInfo*, clang::MacroDirective*, clang::MacroDirective*) /qdelacru/llvm-project/clang/lib/Lex/PPMacroExpansion.cpp:116:5

An example of the code that causes the assert failure:
```
...
```

During code completion in clangd, the macros will be loaded in loadMainFilePreambleMacros() by iterating over the macro names and calling PreambleIdentifiers->get(). Since these macro names are store in a StringSet (has StringMap underlying container), the order of the iterator is not guaranteed to be same as the order seen in the source code.

When clangd is trying to resolve nested macros it sometimes attempts to load them out of order which causes a macro to be stored twice. In the example above, ECHO2 macro gets resolved first, but since it uses another macro that has not been resolved it will try to resolve/store that as well. Now there are two MacroDirectives stored in the Preprocessor, ECHO and ECHO2. When clangd tries to load the next macro, ECHO, the preprocessor fails an assert in clang::Preprocessor::setLoadedMacroDirective() because there is already a MacroDirective stored for that macro name.

In this diff, I check if the macro is already inside the IdentifierTable and if it is skip it so that it is not resolved twice.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101870
2021-05-06 08:24:06 +02:00
Kirill Bobyrev e623ce6188
[clangd] Split CC and refs limit and increase refs limit to 1000
Related discussion: https://github.com/clangd/clangd/discussions/761

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101902
2021-05-05 23:39:48 +02:00
Harald van Dijk 7907c46fe6
Make clangd CompletionModel not depend on directory layout.
The current code accounts for two possible layouts, but there is at
least a third supported layout: clang-tools-extra may also be checked
out as clang/tools/extra with the releases, which was not yet handled.
Rather than treating that as a special case, use the location of
CompletionModel.cmake to handle all three cases. This should address the
problems that prompted D96787 and the problems that prompted the
proposed revert D100625.

Reviewed By: usaxena95

Differential Revision: https://reviews.llvm.org/D101851
2021-05-05 19:25:34 +01:00
Nathan James e1c729c568
[clang-tidy][NFC] Update tests and Default options to use boolean value
Change instances where options which are boolean are assigned the value 1|0 to use true|false instead.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D101721
2021-05-04 18:17:56 +01:00
Georgy Komarov c2e9baf2e8
[clang-tidy] Fix cppcoreguidelines-pro-type-vararg false positives with __builtin_ms_va_list
This commit fixes cppcoreguidelines-pro-type-vararg false positives on
'char *' variables.

The incorrect warnings generated by clang-tidy can be illustrated with
the following minimal example:

```
goid foo(char* in) {
  char *tmp = in;
}
```

The problem is that __builtin_ms_va_list desugared as 'char *', which
leads to false positives.

Fixes bugzilla issue 48042.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D101259
2021-05-04 13:49:20 +03:00
Kirill Bobyrev 34593ae998 Introduce clangd-server-monitor tool
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101516
2021-05-04 12:48:21 +02:00
Kadir Cetinkaya f800ac8309
[clangd] Fix hover crash on broken code
Differential Revision: https://reviews.llvm.org/D101743
2021-05-04 11:42:31 +02:00
Utkarsh Saxena c3d5f306e9
[clangd] Find implementors only when index is present.
Differential Revision: https://reviews.llvm.org/D101750
2021-05-03 17:16:33 +02:00
Nathan James 53df522a0c [clang-tidy][NFC] Short circuit getting enum options suggestions.
Use the MaxEditDistance to skip checking candidates we know we'll skip.
2021-05-03 11:20:27 +01:00
Nathan Ridge 1f8963c801 [clangd] Parameter hints for dependent calls
Differential Revision: https://reviews.llvm.org/D100742
2021-05-03 02:03:16 -04:00
Nathan Ridge 3504e50b6d [clangd] Fix test failure in initialize-params.test
Differential Revision: https://reviews.llvm.org/D101740
2021-05-03 01:37:09 -04:00
Nathan Ridge 1f1fb5e8e6 [clangd] Fix build error in SemanticHighlighting.cpp 2021-05-03 01:19:07 -04:00
Nathan Ridge cea736e5b8 [clangd] Hide inlay hints capability behind a command-line flag
Differential Revision: https://reviews.llvm.org/D101275
2021-05-03 01:01:57 -04:00
Nathan Ridge 43cbf2bb84 [clangd] Avoid including HeuristicResolver.h from ParsedAST.h
Differential Revision: https://reviews.llvm.org/D101270
2021-05-03 00:55:22 -04:00
Nathan James 172a801678 [clang-tidy][NFC] Remove redudnant expr and qualType matchers from bugprone-sizeof-expression. 2021-05-01 08:54:00 +01:00
Nathan James 6815037085
[clangd][NFC] Remove unnecessary string captures in lambdas.
Due to a somewhat annoying, but necessary, shortfall in -Wunused-lambda-capture, These unused captures aren't warned about.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D101611
2021-04-30 13:27:24 +01:00
Nathan James c3846bcfe1
[clangd][NFC] Reserve storage when creating semantic token encoding.
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101461
2021-04-28 22:39:54 +01:00
David Goldman 39866d249a [clangd][ObjC] Improve support for class properties
Class properties are always implicit short-hands for the getter/setter
class methods.

We need to explicitly visit the interface decl `UIColor` in `UIColor.blueColor`,
otherwise we instead show the method decl even while hovering over
`UIColor` in the expression.

Differential Revision: https://reviews.llvm.org/D99975
2021-04-28 10:06:27 -04:00
Utkarsh Saxena d7cb2305a1
[clangd] Add SymbolID to LocatedSymbol.
This is useful for running in batch mode.
Getting the SymbolID from via getSymbolInfo may give SymbolID
of a symbol different from that located by LocateSymbolAt (they
have different semantics of choosing the symbol.)

Differential Revision: https://reviews.llvm.org/D101388
2021-04-28 15:05:53 +02:00
Nathan James 858a9583e1
[clang-query] Add check to prevent setting srcloc when no introspection is available.
Checks if introspection support is available set output kind parser.
If it isn't present the auto complete will not suggest `srcloc` and an error query will be reported if a user tries to access it.

Reviewed By: steveire

Differential Revision: https://reviews.llvm.org/D101365
2021-04-28 11:21:35 +01:00
David Goldman c20e4fbfa6 [clangd] Improve handling of Objective-C protocols in types
Improve support for Objective-C protocols for types/type locs

Differential Revision: https://reviews.llvm.org/D98984
2021-04-27 10:20:35 -04:00
David Goldman 53e1cb88f2 [clangd] run clang-format on FindTargetTests.cpp's FindExplicitReferencesTest
Addressing comments in https://reviews.llvm.org/D98984

Differential Revision: https://reviews.llvm.org/D101328
2021-04-27 10:07:41 -04:00
Kadir Cetinkaya 4581bf31bb
[clangd] Dont index deeply nested symbols
This is fix for some timeouts and OOM problems faced while indexing an
auto-generated file with thousands of nested lambdas.

Differential Revision: https://reviews.llvm.org/D101066
2021-04-27 12:34:56 +02:00
Nathan Ridge c624e70149 [clangd] Rename HeuristicResolver::resolveCallExpr() to resolveTypeOfCallExpr()
Differential Revision: https://reviews.llvm.org/D100741
2021-04-25 19:20:14 -04:00
Nathan Ridge 6f6cf2da8d [clangd] Omit parameter hint for setter functions
Differential Revision: https://reviews.llvm.org/D100731
2021-04-25 19:20:12 -04:00
Nathan Ridge 753b247d71 [clangd] Omit parameter hint if parameter name comment is present
Differential Revision: https://reviews.llvm.org/D100715
2021-04-25 19:20:10 -04:00
Nathan Ridge d941863de2 [clangd] Use HeuristicResolver to produce a better semantic token for name referring to UnresolvedUsingValueDecl
Fixes https://github.com/clangd/clangd/issues/686

Differential Revision: https://reviews.llvm.org/D99056
2021-04-25 16:45:04 -04:00
Nathan Ridge ddfe13e757 [clangd] Produce semantic token for name referring to UnresolvedUsingValueDecl
For now, use the token kind Unknown. We may be able to improve on this
using HeuristicResolver.

Differential Revision: https://reviews.llvm.org/D99052
2021-04-25 16:43:58 -04:00
Stephen Kelly 8d018c79ee Add srcloc output to clang-query
Differential Revision: https://reviews.llvm.org/D93325
2021-04-25 12:12:04 +01:00
Christian Kandeler 81dae18dff [clangd] Allow AST request without range
If no range is given, return the translation unit AST.
This is useful for tooling operations that require e.g. the full path to
a node.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D101057
2021-04-23 21:35:42 +02:00
Chris Hamilton cae3b70ceb [PR49761] Fix variadic arg handling in matcher
Mishandling of variadic arguments in a function call caused a crash
(runtime assert fail) in bugprone-infinite-loop tidy checker.  Fix
is to limit argument matching to the lesser of the number of variadic
params in the prototype or the number of actual args in the call.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D101108
2021-04-23 12:07:14 -05:00
Kadir Cetinkaya a46bbc14f0
[cland] Dont emit missing newline warnings when building preamble
When building preamble, clangd truncates file contents. This yielded
errnous warnings in some cases.

This patch fixes the issue by turning off no-newline-at-eof warnings whenever
the file has more contents than the preamble.

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

Differential Revision: https://reviews.llvm.org/D100501
2021-04-23 08:56:32 +02:00
Georgy Komarov 9a930aa5bd
[clang-tidy] Avoid bugprone-macro-parentheses warnings after goto argument
clang-tidy should not generate warnings for the goto argument without
parentheses, because it would be a syntax error.

The only valid case where an argument can be enclosed in parentheses is
"Labels as Values" gcc extension: https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html.
This commit adds support for the label-as-values extension as implemented in clang.

Fixes bugzilla issue 49634.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D99924
2021-04-22 10:14:10 +03:00
Nathan James 6b4e8f82a3
[clangd] Use dirty filesystem when performing cross file tweaks
Cross file tweaks can now use the dirty buffer contents easily when performing cross file effects.
This can be noted on the DefineOutline tweak, now working when the target file is unsaved

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D93978
2021-04-20 17:13:44 +01:00
Pan, Tao 8969762fb1 [clangd][test] Fix build error of FeatureModulesTests
clang-tools-extra/clangd/unittests/FeatureModulesTests.cpp:33:58: error:
could not convert ‘(const char*)""’ from ‘const char*’ to
llvm::StringLiteral’
       llvm::StringLiteral kind() const override { return ""; };

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D100612
2021-04-19 08:56:07 +08:00
Sam McCall ecf93a716c [clangd] Only allow remote index to be enabled from user config.
Differential Revision: https://reviews.llvm.org/D100542
2021-04-15 14:51:23 +02:00
Balázs Kéri bda20282cb [clang-tidy] Add exception flag to bugprone-unhandled-exception-at-new test. 2021-04-14 10:01:05 +02:00
Balázs Kéri 530456caf9 [clang-tidy] Add new check 'bugprone-unhandled-exception-at-new'.
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97196
2021-04-14 09:33:11 +02:00
Nathan Ridge cbc9c4ea90 [clangd] Add support for inline parameter hints
Differential Revision: https://reviews.llvm.org/D98748
2021-04-14 02:31:20 -04:00
Roman Lebedev 46b8ea2fff
[clang-tidy] Add check for implicit widening of multiplication result
Overflows are never fun.
In most cases (in most of the code), they are rare,
because usually you e.g. don't have as many elements.

However, it's exceptionally easy to fall into this pitfail
in code that deals with images, because, assuming 4-channel 32-bit FP data,
you need *just* ~269 megapixel image to case an overflow
when computing at least the total byte count.

In [[ https://github.com/darktable-org/darktable | darktable ]], there is a *long*, painful history of dealing with such bugs:
* https://github.com/darktable-org/darktable/pull/7740
* https://github.com/darktable-org/darktable/pull/7419
* eea1989f2c
* 70626dd95b
* https://github.com/darktable-org/darktable/pull/670
* 38c69fb1b2

and yet they clearly keep resurfacing still.

It would be immensely helpful to have a diagnostic for those patterns,
which is what this change proposes.

Currently, i only diagnose the most obvious case, where multiplication
is directly widened with no other expressions inbetween,
(i.e. `long r = (int)a * (int)b` but not even e.g. `long r = ((int)a * (int)b)`)
however that might be worth relaxing later.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D93822
2021-04-13 21:41:22 +03:00
Kadir Cetinkaya b5b2c81055
[clangd] Propagate data in diagnostics
Differential Revision: https://reviews.llvm.org/D98505
2021-04-13 17:45:09 +02:00
Kadir Cetinkaya bce3ac4f22
[clangd] Introduce ASTHooks to FeatureModules
These can be invoked at different stages while building an AST to let
FeatureModules implement features on top of it. The patch also
introduces a sawDiagnostic hook, which can mutate the final clangd::Diag
while reading a clang::Diagnostic.

Differential Revision: https://reviews.llvm.org/D98499
2021-04-13 17:45:09 +02:00
Kadir Cetinkaya bb6d96ced8
[clangd] Enable modules to contribute tweaks.
First patch to enable diagnostic fix generation through modules. The
workflow will look like:
- ASTWorker letting modules know about diagnostics while building AST,
modules can read clang::Diagnostic and mutate clangd::Diagnostic through
that hook.
- Modules can implement and expose tweaks to fix diagnostics or act as
general refactorings.
- Tweak::Selection will contain information about the diagnostic
associated with the codeAction request to enable modules to fail their
diagnostic fixing tweakson prepare if need be.

Differential Revision: https://reviews.llvm.org/D98498
2021-04-13 17:45:08 +02:00
Kadir Cetinkaya ecc6965b23
Revert "Revert "[clangd] Provide a way to disable external index""
This reverts commit c2ad7c2370 while
adding the handling for the new enum value into the switch statement.
2021-04-13 11:24:32 +02:00
Nathan James 27dfcd978e
[clang-tidy] Add <utility> include to misc-uniqueptr-reset-release
This is the only remaining check that creates `std::move` includes but doesn't add a `<utility>` include.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D97683
2021-04-12 23:32:15 +01:00
Sterling Augustine c2ad7c2370 Revert "[clangd] Provide a way to disable external index"
This reverts commit 63bc9e4435.

This breaks llvm-project/clang-tools-extra/clangd/tool/ClangdMain.cpp:570:11:

with error: enumeration value 'None' not handled in switch [-Werror,-Wswitch]
2021-04-12 14:39:13 -07:00
Richard Smith fc1e146e44 Fix documentation typo. 2021-04-12 11:39:08 -07:00
Alexander Kornienko 8883cb3e40 Fix nits. 2021-04-12 18:46:13 +02:00
Jens Massberg 8a944d82cd [clang-tidy] Add option to ignore macros in readability-function-cognitive-complexity check.
(this was originally part of https://reviews.llvm.org/D96281 and has been split off into its own patch)

If a macro is used within a function, the code inside the macro
doesn't make the code less readable. Instead, for a reader a macro is
more like a function that is called. Thus the code inside a macro
shouldn't increase the complexity of the function in which it is called.
Thus the flag 'IgnoreMacros' is added. If set to 'true' code inside
macros isn't considered during analysis.

This isn't perfect, as now the code of a macro isn't considered at all,
even if it has a high cognitive complexity itself. It might be better if
a macro is considered in the analysis like a function and gets its own
cognitive complexity. Implementing such an analysis seems to be very
complex (if possible at all with the given AST), so we give the user the
option to either ignore macros completely or to let the expanded code
count to the calling function's complexity.

See the code example from vgeof (originally added as note in https://reviews.llvm.org/D96281)

   bool doStuff(myClass* objectPtr){
         if(objectPtr == nullptr){
             LOG_WARNING("empty object");
             return false;
         }
         if(objectPtr->getAttribute() == nullptr){
             LOG_WARNING("empty object");
             return false;
         }
         use(objectPtr->getAttribute());
     }

The LOG_WARNING macro itself might have a high complexity, but it do not make the
the function more complex to understand like e.g. a 'printf'.

By default 'IgnoreMacros' is set to 'false', which is the original behavior of the check.

Reviewed By: lebedev.ri, alexfh

Differential Revision: https://reviews.llvm.org/D98070
2021-04-12 18:46:12 +02:00
Kadir Cetinkaya 63bc9e4435
[clangd] Provide a way to disable external index
Users can reset any external index set by previous fragments by
putting a `None` for the external block, e.g:

```
Index:
  External: None
```

Differential Revision: https://reviews.llvm.org/D100106
2021-04-12 16:43:23 +02:00
Mikael Holmen 2dd22da965 [libtooling][clang-tidy] Fix compiler warnings in testcase [NFC]
Without the fix we get:

06:31:09 In file included from ../../clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp:3:
06:31:09 ../utils/unittest/googletest/include/gtest/gtest.h:1392:11: error: comparison of integers of different signs: 'const int' and 'const unsigned int' [-Werror,-Wsign-compare]
06:31:09   if (lhs == rhs) {
06:31:09       ~~~ ^  ~~~
06:31:09 ../utils/unittest/googletest/include/gtest/gtest.h:1421:12: note: in instantiation of function template specialization 'testing::internal::CmpHelperEQ<int, unsigned int>' requested here
06:31:09     return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
06:31:09            ^
06:31:09 ../../clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp:60:3: note: in instantiation of function template specialization 'testing::internal::EqHelper<false>::Compare<int, unsigned int>' requested here
06:31:09   EXPECT_EQ(4, Errors[0].Message.FileOffset);
06:31:09   ^
06:31:09 ../utils/unittest/googletest/include/gtest/gtest.h:1924:63: note: expanded from macro 'EXPECT_EQ'
06:31:09                       EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
06:31:09                                                               ^
06:31:09 ../utils/unittest/googletest/include/gtest/gtest.h:1392:11: error: comparison of integers of different signs: 'const int' and 'const unsigned long' [-Werror,-Wsign-compare]
06:31:09   if (lhs == rhs) {
06:31:09       ~~~ ^  ~~~
06:31:09 ../utils/unittest/googletest/include/gtest/gtest.h:1421:12: note: in instantiation of function template specialization 'testing::internal::CmpHelperEQ<int, unsigned long>' requested here
06:31:09     return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
06:31:09            ^
06:31:09 ../../clang-tools-extra/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp:64:3: note: in instantiation of function template specialization 'testing::internal::EqHelper<false>::Compare<int, unsigned long>' requested here
06:31:09   EXPECT_EQ(1, Errors[0].Message.Ranges.size());
06:31:09   ^
06:31:09 ../utils/unittest/googletest/include/gtest/gtest.h:1924:63: note: expanded from macro 'EXPECT_EQ'
06:31:09                       EqHelper<GTEST_IS_NULL_LITERAL_(val1)>::Compare, \
06:31:09                                                               ^
06:31:09 2 errors generated.
2021-04-12 08:26:46 +02:00
Whisperity 8fa3975247 [libtooling][clang-tidy] Fix off-by-one rendering issue with SourceRanges
There was an off-by-one issue with calculating the *exact* end location
of token ranges (as given by SomeDecl->getSourceRange()) which resulted in:

  xxx(something)
      ^~~~~~~~   // Note the missing ~ under the last character.

In addition, a test is added to keep the behaviour in check in the future.

This patch hotfixes commit 3b677b81ce.
2021-04-10 18:52:55 +02:00
Whisperity 3b677b81ce [libtooling][clang-tidy] Fix diagnostics not highlighting fed SourceRanges
Fixes bug http://bugs.llvm.org/show_bug.cgi?id=49000.

This patch allows Clang-Tidy checks to do

    diag(X->getLocation(), "text") << Y->getSourceRange();

and get the highlight of `Y` as expected:

    warning: text [blah-blah]
        xxx(something)
        ^   ~~~~~~~~~

Reviewed-By: aaron.ballman, njames93

Differential Revision: http://reviews.llvm.org/D98635
2021-04-10 16:43:44 +02:00
Kadir Cetinkaya b9b708eef8
[clangd] Log a message when gRPC support is off, but remote-index is configured
Before this change clangd would emit a diagnostic whenever remote-index
was configured but binary didn't have grpc support.

This can be annoying when projects are configuring remote-index through their
configs but developers have a clangd binary without the support.

Differential Revision: https://reviews.llvm.org/D100103
2021-04-09 15:52:51 +02:00
Adam Czachorowski 3b4936ba29 [clangd] Add --check-lines to restrict --check to specific lines
This will allow us to add code completion, which is too expensive at
every token, to --check too.

Differential Revision: https://reviews.llvm.org/D98970
2021-04-09 13:47:20 +02:00
crr0004 43637c0dfe
Fix crash when an invalid URI is parsed and error handling is attempted
When you pass in a payload with an invalid URI in a build with assertions enabled, it will crash.
Consuming the error from the failed URI parse prevents the error.

The crash is caused by the [llvm::expected](https://llvm.org/doxygen/classllvm_1_1Expected.html) having protection around trying to deconstruct without consuming the error first.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D99872
2021-04-07 12:32:33 +02:00
Vince Bridgers c060945b23 [docs] Update documentation for bugprone-misplaced-widening-cast
The default setting for CheckImplicitCasts was changed in
https://reviews.llvm.org/D32164 but the documentation was not updated.
This simple change just syncs the documentation with the behavior of
that checker.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D99991
2021-04-06 16:18:50 -05:00
Felix Berger ddebed8e97 [clang-tidy] performance-* checks: Match AllowedTypes against qualified type names when they contain "::".
This allows users to be more precise and exclude a type in a specific namespace
from triggering the check instead of excluding all types with the same
unqualified name.

This change should not interfere with correctly configured clang-tidy setups
since an AllowedType with "::" would never match.

Differential Revision: https://reviews.llvm.org/D98738

Reviewed-by: ymandel, hokein
2021-04-06 15:41:35 -04:00
oToToT 14a7296c01
[clang][clangd] Avoid inconsistent target creation
As proposed in D97109, I tried to make target creation consistent in `clang` and `clangd` by replacing the original procedure with a single function introduced in D97493.

This also helps `clangd` works with CUDA, OpenMP, etc.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D98128
2021-04-06 23:23:34 +08:00
Abhina Sreeskantharajan 82b3e28e83 [SystemZ][z/OS][Windows] Add new OF_TextWithCRLF flag and use this flag instead of OF_Text
Problem:
On SystemZ we need to open text files in text mode. On Windows, files opened in text mode adds a CRLF '\r\n' which may not be desirable.

Solution:
This patch adds two new flags

  - OF_CRLF which indicates that CRLF translation is used.
  - OF_TextWithCRLF = OF_Text | OF_CRLF indicates that the file is text and uses CRLF translation.

Developers should now use either the OF_Text or OF_TextWithCRLF for text files and OF_None for binary files. If the developer doesn't want carriage returns on Windows, they should use OF_Text, if they do want carriage returns on Windows, they should use OF_TextWithCRLF.

So this is the behaviour per platform with my patch:

z/OS:
OF_None: open in binary mode
OF_Text : open in text mode
OF_TextWithCRLF: open in text mode

Windows:
OF_None: open file with no carriage return
OF_Text: open file with no carriage return
OF_TextWithCRLF: open file with carriage return

The Major change is in llvm/lib/Support/Windows/Path.inc to only set text mode if the OF_CRLF is set.
```
  if (Flags & OF_CRLF)
    CrtOpenFlags |= _O_TEXT;
```

These following files are the ones that still use OF_Text which I left unchanged. I modified all these except raw_ostream.cpp in recent patches so I know these were previously in Binary mode on Windows.
./llvm/lib/Support/raw_ostream.cpp
./llvm/lib/TableGen/Main.cpp
./llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
./llvm/unittests/Support/Path.cpp
./clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
./clang/lib/Frontend/CompilerInstance.cpp
./clang/lib/Driver/Driver.cpp
./clang/lib/Driver/ToolChains/Clang.cpp

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D99426
2021-04-06 07:23:31 -04:00
Kadir Cetinkaya 6d2fb3cefb
[clangd] Perform merging for stale symbols in MergeIndex
Clangd drops symbols from static index whenever the dynamic index is
authoritative for the file. This results in regressions when static and
dynamic index contains different set of information, e.g.
IncludeHeaders.

After this patch, we'll choose to merge symbols from static index with
dynamic one rather than just dropping. This implies correctness problems
when the definition/documentation of the symbol is deleted. But seems
like it is worth having in more cases.

We still drop symbols if dynamic index owns the file and didn't report
the symbol, which means symbol is deleted.

Differential Revision: https://reviews.llvm.org/D98538
2021-03-30 11:09:51 +02:00
Stephen Kelly ea2225a10b [clang-tidy] Simplify readability checks to not need ignoring* matchers
Differential Revision: https://reviews.llvm.org/D98296
2021-03-28 11:25:41 +01:00
Utkarsh Saxena aa979084df [clang][Syntax] Optimize expandedTokens for token ranges.
`expandedTokens(SourceRange)` used to do a binary search to get the
expanded tokens belonging to a source range. Each binary search uses
`isBeforeInTranslationUnit` to order two source locations. This is
inherently very slow.
By profiling clangd we found out that users like clangd::SelectionTree
spend 95% of time in `isBeforeInTranslationUnit`. Also it is worth
noting that users of `expandedTokens(SourceRange)` majorly use ranges
provided by AST to query this funciton. The ranges provided by AST are
token ranges (starting at the beginning of a token and ending at the
beginning of another token).

Therefore we can avoid the binary search in majority of the cases by
maintaining an index of ExpandedToken by their SourceLocations. We still
do binary search for ranges which are not token ranges but such
instances are quite low.

Performance:
`~/build/bin/clangd --check=clang/lib/Serialization/ASTReader.cpp`
Before: Took 2:10s to complete.
Now: Took 1:13s to complete.

Differential Revision: https://reviews.llvm.org/D99086
2021-03-25 18:54:15 +01:00
Kadir Cetinkaya 7f5abb6373
[clangd] Fix a use-after-free
Clangd was storing reference to a possibly-dead string in compiled
config. This patch fixes the issue by copying suppression strings from
fragments into compiled Config.

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

Differential Revision: https://reviews.llvm.org/D99326
2021-03-25 18:26:17 +01:00
Nathan James 02d7ef3181
[clang-tidy] Fix mpi checks when running multiple TUs per clang-tidy process
Both the mpi-type-mismatch and mpi-buffer-deref check make use of a static MPIFunctionClassifier object.
This causes issue as the classifier is initialized with the first ASTContext that produces a match.
If the check is enabled on multiple translation units in a single clang-tidy process, this classifier won't be reinitialized for each TU. I'm not an expert in the MPIFunctionClassifier but I'd imagine this is a source of UB.
It is suspected that this bug may result in the crash caused here: https://bugs.llvm.org/show_bug.cgi?id=48985. However even if not the case, this should still be addressed.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98275
2021-03-25 14:38:37 +00:00
Alexander Lanin 0becc4d721 fix readability-braces-around-statements Stmt type dependency
Replaces Token based approach to identify EndLoc of Stmt with AST traversal.
This also improves handling of macros.

Fixes Bugs 22785, 25970 and 35754.
2021-03-25 09:44:41 -04:00
Dmitry Polukhin 338d162755 [clang-tidy] Ignore all spaces in the list of checks
This diff patch fixes issue with new line character after check name and before comma. Also ignores all other types of spaces like TAB.

Test Plan: ninja check-clang-tools

Differential Revision: https://reviews.llvm.org/D99180
2021-03-24 06:43:13 -07:00
Frank Derry Wanye 5a87f81fe9 new altera unroll loops check
This lint check is a part of the FLOCL (FPGA Linters for OpenCL)
project out of the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who write code
in OpenCL.

The altera unroll loops check finds inner loops that have not been
unrolled, as well as fully-unrolled loops that should be partially
unrolled due to unknown loop bounds or a large number of loop
iterations.

Based on the Altera SDK for OpenCL: Best Practices Guide.
2021-03-22 13:09:53 -04:00
Kadir Cetinkaya f71404c37c
[clangd] Replace usages of dummy with more descriptive words
Dummy is a word with inappropriate associations. This patch updates the
references to it in clangd code base with more precise ones.

The only user-visible change is the default variable name used when extracting a
variable. It will be named as `placeholder` from now on.

Differential Revision: https://reviews.llvm.org/D99065
2021-03-22 12:49:24 +01:00
serge-sans-paille f51ab18716 Make clangd CompletionModel usable even with non-standard (but supported) layout
llvm supports specifying a non-standard layout where each project lies in its
own place. Do not assume a fixed layout and use the appropriate cmake variable
instead.

Differential Revision: https://reviews.llvm.org/D96787
2021-03-22 10:05:25 +01:00
Nathan Ridge 2e58226d8d [clangd] Fix linker error when linking clang-index-server with shared libraries
Fixes https://github.com/clangd/clangd/issues/723

Differential Revision: https://reviews.llvm.org/D99049
2021-03-22 02:38:58 -04:00
Nathan James 4dd92d61db
[clang-tidy] Fix bugprone-terminating-continue when continue appears inside a switch
Don't emit a warning if the `continue` appears in a switch context as changing it to `break` will break out of the switch rather than a do loop containing the switch.
Fixes https://llvm.org/PR49492.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98338
2021-03-20 10:59:37 +00:00
Vassil Vassilev 0cb7e7ca0c Make iteration over the DeclContext::lookup_result safe.
The idiom:
```
DeclContext::lookup_result R = DeclContext::lookup(Name);
for (auto *D : R) {...}
```

is not safe when in the loop body we trigger deserialization from an AST file.
The deserialization can insert new declarations in the StoredDeclsList whose
underlying type is a vector. When the vector decides to reallocate its storage
the pointer we hold becomes invalid.

This patch replaces a SmallVector with an singly-linked list. The current
approach stores a SmallVector<NamedDecl*, 4> which is around 8 pointers.
The linked list is 3, 5, or 7. We do better in terms of memory usage for small
cases (and worse in terms of locality -- the linked list entries won't be near
each other, but will be near their corresponding declarations, and we were going
to fetch those memory pages anyway). For larger cases: the vector uses a
doubling strategy for reallocation, so will generally be between half-full and
full. Let's say it's 75% full on average, so there's N * 4/3 + 4 pointers' worth
of space allocated currently and will be 2N pointers with the linked list. So we
break even when there are N=6 entries and slightly lose in terms of memory usage
after that. We suspect that's still a win on average.

Thanks to @rsmith!

Differential revision: https://reviews.llvm.org/D91524
2021-03-17 08:59:04 +00:00
Nathan James 9a5af541ee
[clang-tidy] Remove readability-deleted-default
The deprecation notice was cherrypicked to the release branch in f8b3298924 so its safe to remove this for the 13.X release cycle.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98612
2021-03-16 14:03:33 +00:00
Kirill Bobyrev 524fe51509
[clangd] Add basic monitoring info request for remote index server
This allows requesting information about the server uptime and start time. This is the first patch in a series of monitoring changes, hence it's not immediately useful. Next step is propagating the index freshness information and then probably loading metadata into the index server.

The way to test new behaviour through command line:

```
$ grpc_cli call localhost:50051 Monitor/MonitoringInfo ''
connecting to localhost:50051
uptime_seconds: 42
index_age_seconds: 609568
Rpc succeeded with OK status
```

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D98246
2021-03-16 13:37:58 +01:00
Kadir Cetinkaya 2772c3a975
[clangd] Introduce pullDiags endpoint
Implement initial support for pull-based diagnostics in ClangdServer.
This is planned for LSP 3.17, and initial proposal is in
d15eb0671e/protocol/src/common/proposed.diagnostic.ts (L111).

We chose to serve the requests only when clangd has a fresh preamble
available. In case of a stale preamble we just drop the request on the
floor.

This patch doesn't plumb this to LSP layer yet, as pullDiags is still a
proposal with only an implementation in vscode.

Differential Revision: https://reviews.llvm.org/D98623
2021-03-16 12:52:15 +01:00
Sam McCall 128ce70eef [CodeCompletion] Avoid spurious signature help for init-list args
Somewhat surprisingly, signature help is emitted as a side-effect of
computing the expected type of a function argument.
The reason is that both actions require enumerating the possible
function signatures and running partial overload resolution, and doing
this twice would be wasteful and complicated.

Change #1: document this, it's subtle :-)

However, sometimes we need to compute the expected type without having
reached the code completion cursor yet - in particular to allow
completion of designators.
eb4ab3358c did this but introduced a
regression - it emits signature help in the wrong location as a side-effect.

Change #2: only emit signature help if the code completion cursor was reached.

Currently there is PP.isCodeCompletionReached(), but we can't use it
because it's set *after* running code completion.
It'd be nice to set this implicitly when the completion token is lexed,
but ConsumeCodeCompletionToken() makes this complicated.

Change #3: call cutOffParsing() *first* when seeing a completion token.

After this, the fact that the Sema::Produce*SignatureHelp() functions
are even more confusing, as they only sometimes do that.
I don't want to rename them in this patch as it's another large
mechanical change, but we should soon.

Change #4: prepare to rename ProduceSignatureHelp() to GuessArgumentType() etc.

Differential Revision: https://reviews.llvm.org/D98488
2021-03-16 12:46:40 +01:00
Sam McCall ca13f5595a [clangd] Add `limit` extension on completion and workspace-symbols
This overrides the --limit-results command-line flag, and is not constrained
by it.
See https://github.com/clangd/clangd/issues/707

Differential Revision: https://reviews.llvm.org/D97801
2021-03-16 12:28:01 +01:00
Sam McCall 3b99731c4e [clangd] Turn off implicit cancellation based on client capabilities
Capability is in upcoming 3.17: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/

(This is also useful for C++ embedders)

Differential Revision: https://reviews.llvm.org/D98414
2021-03-16 12:27:40 +01:00
Sam McCall 43d0b1c9c1 [clangd] Reject renames to non-identifier characters
Differential Revision: https://reviews.llvm.org/D98424
2021-03-16 12:18:29 +01:00
Kirill Bobyrev 9bcf0eff99
[clangd] Optionally add reflection for clangd-index-server
This was originally landed without the optional part and reverted later:

8080ea4c4b

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D98404
2021-03-15 21:07:25 +01:00
Dmitry Polukhin da55af7f1d [clang-tidy] Enable modernize-concat-nested-namespaces also on headers
For some reason the initial implementation of the check had an explicit check
for the main file to avoid being applied in headers. This diff removes this
check and add a test for the check on a header.

Similar approach was proposed in D61989 but review there got stuck.

Test Plan: added new test case

Differential Revision: https://reviews.llvm.org/D97563
2021-03-15 07:32:45 -07:00
Nathan James 0333dde923
[clang-tidy] Fix readability-identifer-naming duplicating prefix or suffix for replacements.
If a identifier has a correct prefix/suffix but a bad case, the fix won't strip them when computing the correct case, leading to duplication when the are added back.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D98521
2021-03-15 14:20:48 +00:00
Kadir Cetinkaya dc9c09632f
[clangd] Make ProjectAwareIndex optionally sync
Depends on D98029.

Differential Revision: https://reviews.llvm.org/D98165
2021-03-11 20:30:35 +01:00
Kadir Cetinkaya ac292dafa7
[clangd] Add config block for Completion and option for AllScopes
Depends on D98029

Differential Revision: https://reviews.llvm.org/D98037
2021-03-11 20:30:35 +01:00
Kadir Cetinkaya cec62ae28a
[clangd] Fix buildbots without grpc enabled 2021-03-11 13:46:52 +01:00
Kadir Cetinkaya 4f1bbc0b84
[clangd] Introduce a CommandLineConfigProvider
This enables unifying command line flags with config options in clangd
internals. This patch changes behaviour in 2 places:
- BackgroundIndex was previously disabled when -remote-index was
provided. After this patch, it will be enabled but all files will have
bkgindex policy set to Skip.
- -index-file was loaded at startup (at least load was initiated), now
the load will happen through ProjectAwareIndex with first index query.

Unfortunately this doesn't simplify any options initially, as
- CompileCommandsDir is also used by clangd --check workflow, which
doesn't use configs.
- EnableBackgroundIndex option controls whether the component will be
created at all, which implies creation of extra threads registering a
listener for compilation database discoveries.

Differential Revision: https://reviews.llvm.org/D98029
2021-03-11 13:35:05 +01:00
Kadir Cetinkaya b1a5df174e
[clangd] Drop explicit specifier on define out-of-line
Explicit specifier can only be mentioned on the in-line declaration of a
constructor, so don't carry it over to the definition.

Differential Revision: https://reviews.llvm.org/D98164
2021-03-11 13:27:24 +01:00
Sam McCall b8c58374f6 [clangd] Group filename calculations in SymbolCollector, and cache mroe.
Also give CanonicalIncludes a less powerful interface (canonicalizes
symbols vs headers separately) so we can cache its results better.

Prior to this:
 - path->uri conversions were not consistently cached, this is
   particularly cheap when we start from a FileEntry* (which we often can)
 - only a small fraction of header-to-include calculation was cached

This is a significant speedup at least for dynamic indexing of preambles.
On my machine, opening XRefs.cpp:

```
PreambleCallback 1.208 -> 1.019 (-15.7%)
BuildPreamble    5.538 -> 5.214 (-5.8%)
```

Differential Revision: https://reviews.llvm.org/D98371
2021-03-11 12:59:26 +01:00
Nathan James 7044f1d875
[clangd] Use Dirty Filesystem for cross file rename.
Refactor cross file rename to use a Filesystem instead of a function for getting buffer contents of open files.

Depends on D94554

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95043
2021-03-10 13:41:29 +00:00
Kadir Cetinkaya 99b01cf28d
Revert "[clangd] Enable reflection for clangd-index-server"
This reverts commit 8080ea4c4b.

As discussed offline we should only do that for debug builds.
2021-03-10 14:12:37 +01:00
Jinzheng Tu 481079e284 [NFC] Unify FIME with FIXME in comments
There are 5 occurrences FIME and 15333 FIXME. All of them should be FIXME.

Reviewed By: alexfh

Differential Revision: https://reviews.llvm.org/D98321
2021-03-10 14:00:51 +01:00
Kirill Bobyrev 8080ea4c4b [clangd] Enable reflection for clangd-index-server
This allows sending requests through CLI and more debugging
opportunities. Example:

```bash
$ grpc_cli ls localhost:50051
clang.clangd.remote.v1.SymbolIndex
grpc.reflection.v1alpha.ServerReflection
grpc.health.v1.Health
```
2021-03-10 09:07:39 +01:00