Summary:
After this commit, clangd will only keep the last 3 accessed ASTs in
memory. Preambles for each of the opened files are still kept in
memory to make completion and AST rebuilds fast.
AST rebuilds are usually fast enough, but having the last ASTs in
memory still considerably improves latency of operations like
findDefinition and documeneHighlight, which are often sent multiple
times a second when moving around the code. So keeping some of the last
accessed ASTs in memory seems like a reasonable tradeoff.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: malaperle, arphaman, klimek, javed.absar, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47063
llvm-svn: 333737
Summary:
In rL327851 the createUniqueFile() and createTemporaryFile()
variants that do not return the file descriptors were changed to
create empty files, rather than only check if the paths are free.
This change was done in order to make the functions race-free.
That change led to clang-tidy (and possibly other tools) leaving
behind temporary assembly files, of the form placeholder-*, when
using a target that does not support the internal assembler.
The temporary files are created when building the Compilation
object in stripPositionalArgs(), as a part of creating the
compilation database for the arguments after the double-dash. The
files are created by Driver::GetNamedOutputPath().
Fix this issue by cleaning out temporary files at the deletion of
Compilation objects.
This fixes https://bugs.llvm.org/show_bug.cgi?id=37091.
Reviewers: klimek, sepavloff, arphaman, aaron.ballman, john.brawn, mehdi_amini, sammccall, bkramer, alexfh, JDevlieghere
Reviewed By: aaron.ballman, JDevlieghere
Subscribers: erichkeane, lebedev.ri, Ka-Ka, cfe-commits
Differential Revision: https://reviews.llvm.org/D45686
llvm-svn: 333637
Summary:
Also fix USR generation for classes in unit tests. The previous USR
only works for class members, which happens to work when completing class name
inside the class, where constructors are suggested by sema.
Reviewers: sammccall, ilya-biryukov
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47466
llvm-svn: 333519
This patch silences few clang-tidy warnings, removes unwanted trailing
whitespace and enforces coding guidelines.
The functionality is not affected since the cleanup is rather straightforward,
all clangd tests are still green.
Reviewers: ioeric, ilya-biryukov
Reviewed By: ioeric
Subscribers: MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47471
llvm-svn: 333411
Summary:
They cause lots of deserialization and are not actually used.
The ParsedAST accessor that previously returned those was renamed from
getTopLevelDecls to getLocalTopLevelDecls in order to avoid
confusion.
This change should considerably improve the speed of findDefinition
and other features that try to find AST nodes, corresponding to the
locations in the source code.
Reviewers: ioeric, sammccall
Reviewed By: sammccall
Subscribers: klimek, mehdi_amini, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47331
llvm-svn: 333371
The commit includes two changes:
1. Set DisableFree to false when building the ParsedAST.
This is sane default, since clangd never wants to leak the AST.
2. Make sure CompilerInstance created in code completion is passed to
the FrontendAction::BeginSourceFile call.
We have to do this to make sure the memory buffers of remapped
files are properly freed.
Our tests do not produce any warnings under asan anymore.
The changes are mostly trivial, just moving the code around. So
sending without review.
llvm-svn: 333370
This fix is still quite fragile, the underlying problem is that the
code should not rely on source ranges coming from the preamble to be
correct when reading from the text buffers.
This is probably not possible to achieve in practice, so we would
probably have to keep the contents of old headers around for the
lifetime of the preamble.
llvm-svn: 333369
It turns out that our fix did not solve the problem completely and the
crash due to stale preamble is still there under asan.
Disabling the test for now, will reenable it when landing a proper fix
for the problem.
llvm-svn: 333280
Summary:
This is more efficient and avoids data races when reading files that
come from the preamble. The staleness can occur when reading a file
from disk that changed after the preamble was built. This can lead to
crashes, e.g. when parsing comments.
We do not to rely on symbols from the main file anyway, since any info
that those provide can always be taken from the AST.
Reviewers: ioeric, sammccall
Reviewed By: ioeric
Subscribers: malaperle, klimek, javed.absar, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47272
llvm-svn: 333196
Summary:
To fix a crash in code completion that occurrs when reading doc
comments from files that were updated after the preamble was
computed. In that case, the files on disk could've been changed and we
can't rely on finding the comment text with the same range anymore.
The current workaround is to not provide comments from the headers at
all and rely on the dynamic index instead.
A more principled solution would be to store contents of the files
read inside the preamble, but it is way harder to implement properly,
given that it would definitely increase the sizes of the preamble.
Together with D47272, this should fix all preamble-related crashes
we're aware of.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: klimek, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47274
llvm-svn: 333189
Summary:
This assumes that .inc files are supposed to be included via headers
that include them.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47187
llvm-svn: 333188
Summary:
Currently, we only handle the first callback from sema code completion
and ignore results from potential following callbacks. This causes
causes loss of completion results when multiple contexts are tried by Sema.
For example, we wouldn't get any completion result in the following completion
as the first attemped context is natural language which has no
candidate. The parser would backtrack and tried a completion with AST
semantic, which would find candidate "::x".
```
void f(const char*, int);
#define F(x) f(#x, x)
int x;
void main() {
F(::^);
}
```
To fix this, we only process a sema callback when it gives completion results or
the context supports index-based completion.
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47256
llvm-svn: 333174
Summary:
Checks for narrowing conversions, e.g.
int i = 0;
i += 0.1;
This has what some might consider false positives for:
i += ceil(d);
Reviewers: alexfh, hokein
Subscribers: srhines, nemanjai, mgorny, JDevlieghere, xazax.hun, kbarton
Differential Revision: https://reviews.llvm.org/D38455
llvm-svn: 333066
bool foo(A &S) {
if (S != (A)S)
return false;
return true;
}
is fixed into (w/o this patch)
...
return !S != (A)S; // negotiation affects first operand only
}
instead of (with this patch)
...
return S == (A)S; // note == instead of !=
}
Differential Revision: https://reviews.llvm.org/D47122
llvm-svn: 333003
Summary:
Now that the clients who relied on stats for files from preamble are
gone.
Reviewers: ioeric, sammccall
Reviewed By: ioeric
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D47066
llvm-svn: 332976
This was broken by r332590 but is likely caused by a bug in clang-move.
http://lab.llvm.org:8011/builders/clang-x86-windows-msvc2015/builds/12007
I don't have a windows machine to effectively debug the issue, so I'll investigate
further but for now disable the failing test on windows to unbreak build bots.
llvm-svn: 332620
Summary: The alpha checkers can already be enabled using the clang driver, this allows them to be enabled using the clang-tidy as well. This can make it easier to test the alpha checkers with projects which already support the compile_commands.json. It will also allow more people to give feedback and patches about the alpha checkers since they can run it as part of clang tidy checks.
Reviewers: aaron.ballman, hokein, ilya-biryukov, alexfh, lebedev.ri, xbolva00
Reviewed By: aaron.ballman, alexfh, lebedev.ri, xbolva00
Subscribers: xbolva00, NoQ, dcoughlin, lebedev.ri, xazax.hun, cfe-commits
Patch by Paul Fultz II!
Differential Revision: https://reviews.llvm.org/D46159
llvm-svn: 332609
Currently, diagnoses code that calls container.data()[some_index] when the container exposes a suitable operator[]() method that can be used directly.
Patch by Shuai Wang.
llvm-svn: 332519
Summary:
Previously, `google-readability-casting` was disabled for Objective-C.
The Google Objective-C++ style allows both Objective-C and
C++ style in the same file. Since clang-tidy doesn't have a good
way to allow multiple styles per file, this disables the
check for Objective-C++.
Test Plan: New tests added. Ran tests with:
% make -j16 check-clang-tools
Before diff, confirmed tests failed:
https://reviews.llvm.org/P8081
After diff, confirrmed tests passed.
Reviewers: alexfh, Wizard, hokein, stephanemoore
Reviewed By: alexfh, Wizard, stephanemoore
Subscribers: stephanemoore, cfe-commits, bkramer, klimek
Differential Revision: https://reviews.llvm.org/D46659
llvm-svn: 332516
Summary:
And add tests for the comment extraction code.
clangd will now show non-doxygen comments in completion for results
coming from Sema and Dynamic index.
Static index does not include the comments yet, I will enable it in
a separate commit after investigating which implications it has for
the size of the index.
Reviewers: sammccall, hokein, ioeric
Reviewed By: sammccall
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46002
llvm-svn: 332460
Summary:
Previous implementation used to extract brief text from doxygen comments.
Brief text parsing slows down completion and is not suited for
non-doxygen comments.
This commit switches to providing comments that mimic the ones
originally written in the source code, doing minimal reindenting and
removing the comments markers to make the output more user-friendly.
It means we lose support for doxygen-specific features, e.g. extracting
brief text, but provide useful results for non-doxygen comments.
Switching the doxygen support back is an option, but I suggest to see
whether the current approach gives more useful results.
Reviewers: sammccall, hokein, ioeric
Reviewed By: sammccall
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D45999
llvm-svn: 332459
Summary:
This uses heuristics to identify private proto symbols. For example,
top-level symbols whose name contains "_" are considered private. These symbols
are not expected to be used by users.
Reviewers: ilya-biryukov, malaperle
Reviewed By: ilya-biryukov
Subscribers: sammccall, klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46751
llvm-svn: 332456
Summary: D46524 (rL332378) introduced a link failure when built with
`-DSHARED_LIB=ON`, which this patch fixes.
Reviewers: ioeric
Subscribers: klimek, mgorny, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46906
llvm-svn: 332438
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM
Differential Revision: https://reviews.llvm.org/D44976
llvm-svn: 332371
Summary:
o Remove IncludeInsertion LSP command.
o Populate include insertion edits synchromously in completion items.
o Share the code completion compiler instance and precompiled preamble to get existing inclusions in main file.
o Include insertion logic lives only in CodeComplete now.
o Use tooling::HeaderIncludes for inserting new includes.
o Refactored tests.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46497
llvm-svn: 332363
Summary:
clangd will populate #include insertions as addtionalEdits in completion items.
The code completion tests in ClangdServerTest will be added back in D46497.
Reviewers: ilya-biryukov, sammccall
Reviewed By: ilya-biryukov
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46676
llvm-svn: 332362
Summary: Separate unit tests for the new function will be added in followup patch which will further refactor Headers.h
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46675
llvm-svn: 332237
Summary:
We used to query the index when completing after class qualifiers,
e.g. 'ClassName::^'. We should not do that for the same reasons we
don't query the index for member access expressions.
Reviewers: sammccall, ioeric
Reviewed By: sammccall
Subscribers: klimek, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46795
llvm-svn: 332226
Adding a check to restrict system includes to a whitelist. Given a list
of includes that are explicitly allowed, the check issues a fixit to
remove any system include not on that list from the source file.
Differential Revision: https://reviews.llvm.org/D43778
llvm-svn: 332125
This commit relands r331905.
r331904 added SrcMgr::CharacteristicKind to the InclusionDirective
callback, this revision updates instances of it in clang-tools-extra.
llvm-svn: 332023
Adding a check to restrict system includes to a whitelist. Given a list
of includes that are explicitly allowed, the check issues a fixit to
remove any system include not on that list from the source file.
Differential Revision: https://reviews.llvm.org/D43778
llvm-svn: 331930
[revision] added SrcMgr::CharacteristicKind to the InclusionDirective
callback, this revision updates instances of it in clang-tools-extra.
Differential Revision: https://reviews.llvm.org/D46615
llvm-svn: 331905
That broke every single .clang-tidy config out there
which happened to specify AnalyzeTemporaryDtors option:
YAML:5:24: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: false
^~~~~
Error parsing <...>/.clang-tidy: Invalid argument
More so, that error isn't actually a error, the
clang-tidy does not exit with $? != 0, it continues
with the default config.
Surely this breakage isn't the intended behavior.
But if it is, feel free to revert this commit.
llvm-svn: 331822
Summary:
As discussed in D45931, currently, profiling output of clang-tidy is somewhat not great.
It outputs one profile at the end of the execution, and that profile contains the data
from the last TU that was processed. So if the tool run on multiple TU's, the data is
not accumulated, it is simply discarded.
It would be nice to improve this.
This differential is the first step - make this profiling info per-TU,
and output it after the tool has finished processing each TU.
In particular, when `ClangTidyASTConsumer` destructor runs.
Next step will be to add a CSV (JSON?) printer to store said profiles under user-specified directory prefix.
Reviewers: alexfh, sbenza
Reviewed By: alexfh
Subscribers: Eugene.Zelenko, mgorny, xazax.hun, mgrang, klimek, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D46504
llvm-svn: 331763
This adds the name of the referenced decl, in addition to its USR, to
the saved data, so that the backend can look at an info in isolation and
still be able to construct a human-readable name for it.
Differential Revision: https://reviews.llvm.org/D46281
llvm-svn: 331539
This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not considered
as [[no-return]], and a lot of false-positive warnings about nullptr
dereferenced are emitted.
Differential Revision: https://reviews.llvm.org/D46325
llvm-svn: 331474
Remove the `AnalyzeTemporaryDtors` option, since the corresponding
`cfg-temporary-dtors` option of the Static Analyzer defaults to `true` since
r326461.
llvm-svn: 331456
It's useless and not safe to replace UTF-8 encoded with escaped ASCII to raw UTF-8 chars:
"\xE2\x98\x83" ---> <snowman>
So don't do it.
llvm-svn: 331297
Summary:
The `google-runtime-int` check currently fires on calls like:
printf("%lu", (unsigned long)foo);
However, the style guide says:
> Where possible, avoid passing arguments of types specified by
> bitwidth typedefs to printf-based APIs.
http://google.github.io/styleguide/cppguide.html#64-bit_Portability
This diff relaxes the check to not fire on parameters to functions
with the `__format__` attribute. (I didn't specifically check
for `__printf__` since there are a few variations.)
Test Plan: New tests added. Ran tests with:
% make -j16 check-clang-tools
Reviewers: alexfh, bkramer
Reviewed By: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D46293
llvm-svn: 331268
Summary:
This adds a few common Apple first-party API prefixes as acronyms to
`objc-property-declaration`.
Here's a list showing where these come from:
http://nshipster.com/namespacing/
Test Plan: New tests added. Ran tests with:
% make -j16 check-clang-tools
Reviewers: Wizard, hokein
Subscribers: klimek, xazax.hun, cfe-commits
Differential Revision: https://reviews.llvm.org/D46206
llvm-svn: 331267
Summary:
This patch adds index support for GoToDefinition -- when we don't get the
definition from local AST, we query our index (Static&Dynamic) index to
get it.
Since we currently collect top-level symbol in the index, it doesn't support all
cases (e.g. class members), we will extend the index to include more symbols in
the future.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45717
llvm-svn: 331189
Summary:
The Language Server Protocol unfortunately mandates that locations in files
be represented by line/column pairs, where the "column" is actually an index
into the UTF-16-encoded text of the line.
(This is because VSCode is written in JavaScript, which is UTF-16-native).
Internally clangd treats source files at UTF-8, the One True Encoding, and
generally deals with byte offsets (though there are exceptions).
Before this patch, conversions between offsets and LSP Position pretended
that Position.character was UTF-8 bytes, which is only true for ASCII lines.
Now we examine the text to convert correctly (but don't actually need to
transcode it, due to some nice details of the encodings).
The updated functions in SourceCode are the blessed way to interact with
the Position.character field, and anything else is likely to be wrong.
So I also updated the other accesses:
- CodeComplete needs a "clang-style" line/column, with column in utf-8 bytes.
This is now converted via Position -> offset -> clang line/column
(a new function is added to SourceCode.h for the second conversion).
- getBeginningOfIdentifier skipped backwards in UTF-16 space, which is will
behave badly when it splits a surrogate pair. Skipping backwards in UTF-8
coordinates gives the lexer a fighting chance of getting this right.
While here, I clarified(?) the logic comments, fixed a bug with identifiers
containing digits, simplified the signature slightly and added a test.
This seems likely to cause problems with editors that have the same bug, and
treat the protocol as if columns are UTF-8 bytes. But we can find and fix those.
Reviewers: hokein
Subscribers: klimek, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46035
llvm-svn: 331029
Summary:
This is a convenient function when we try to get std::string of
SymbolID.
Reviewers: ioeric
Subscribers: klimek, ilya-biryukov, MaskRay, jkorous, cfe-commits
Differential Revision: https://reviews.llvm.org/D46065
llvm-svn: 330835
Summary:
Add support for checking class template member functions.
Also add the following functions to be checked by default:
- std::unique_ptr::release
- std::basic_string::empty
- std::vector::empty
Reviewers: alexfh, hokein, aaron.ballman, ilya-biryukov
Reviewed By: aaron.ballman
Subscribers: jbcoe, xazax.hun, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D45891
Patch by khuttun (Kalle Huttunen)
llvm-svn: 330772
Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.
The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.
Reviewers: sammccall, ilya-biryukov
Reviewed By: sammccall
Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44882
llvm-svn: 330637
Request in delimited input ended by EOF shouldn't be an error state.
Comments at the end of test file shouldn't be logged as an error state.
Input mirroring should work for the last request in delimited test file.
llvm-svn: 330608
We do now both:
- stop reformatting a sequence after a closing brace in more cases, in
order to not misindent after an incorrect closing brace
- format the closing brace when formatting the line containing the
opening brace
llvm-svn: 330580
Summary: using ivar in class extension is not supported in 32-bit architecture of MacOS.
Reviewers: alexfh, hokein
Reviewed By: alexfh
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D45912
llvm-svn: 330559
This commit has been breaking most bots for a day now. There is a fix
proposed in https://reviews.llvm.org/D45912 but when I applied that
I just got different errors. Reverting to get our bots back to green.
llvm-svn: 330528
The patch introduces a new command line option '-check-suffix' for check_clang_tidy.py
to allow multiple %check_clang_tidy% in a single test file.
Sample:
// RUN: %check_clang_tidy -check-suffix=FLAG-1 %s misc-unused-using-decls %t -- -- <options-set-1>
// RUN: %check_clang_tidy -check-suffix=FLAG-2 %s misc-unused-using-decls %t -- -- <options-set-2>
...
+// CHECK-MESSAGES-FLAG-1: :[[@LINE-4]]:10: warning: using decl 'B' is unused [misc-unused-using-decls]
+// CHECK-MESSAGES-FLAG-2: :[[@LINE-7]]:10: warning: using decl 'A' is unused [misc-unused-using-decls]
+// CHECK-FIXES-FLAG-1-NOT: using a::A;$
+// CHECK-FIXES-FLAG-2-NOT: using a::B;$
Differential Revision: https://reviews.llvm.org/D45776
llvm-svn: 330511
Add a new target for install: install-clang-apply-replacements.
So if you need clang-tidy and clang-apply-replacements tools only,
you may build and install only these tools:
make install-clang-tidy install-clang-apply-replacements
Differential Revision: https://reviews.llvm.org/D45160
llvm-svn: 330509
Summary: This makes C++/objC not totally broken, without hurting C files too much.
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D45442
llvm-svn: 330418
Summary: This is to support general acronyms in Objective-C like 2G/3G/4G/... and coordinates X, Y, Z and W.
Reviewers: benhamilton
Reviewed By: benhamilton
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D45750
llvm-svn: 330286
Summary:
When running the FileIndexTest, it shows "Failed to create an URI
for file XXX: not a valid absolute file path" warnings, and the
generated Symbols is missing Location information.
Reviewers: ioeric
Subscribers: klimek, ilya-biryukov, jkorous-apple, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45692
llvm-svn: 330182
Summary:
Previsouly, class completions items from the index were missing
template parameters in both the snippet and the label.
Reviewers: sammccall, hokein
Reviewed By: sammccall
Subscribers: klimek, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45482
llvm-svn: 330004
Summary:
LSP is using Line & column as symbol position, clangd needs to transfer file
offset to Line & column when sending results back to LSP client, which is a high
cost, especially for finding workspace symbol -- we have to read the file
content from disk (if it isn't loaded in memory).
Saving these information in the index will make the clangd life eaiser.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45513
llvm-svn: 329997
Summary:
Pretty straight-forward, just count all the variable declarations in the function's body, and if more than the configured threshold - do complain.
Note that this continues perverse practice of disabling the new option by default.
I'm not certain where is the balance point between not being too noisy, and actually enforcing the good practice.
If we really want to not disable this by default, but also to not cause too many new warnings, we could default to 50 or so.
But that is a lot of variables too...
I was able to find one coding style referencing variable count:
- https://www.kernel.org/doc/html/v4.15/process/coding-style.html#functions
> Another measure of the function is the number of local variables. They shouldn’t exceed 5-10, or you’re doing something wrong.
Reviewers: hokein, xazax.hun, JonasToth, aaron.ballman, alexfh
Reviewed By: aaron.ballman
Subscribers: kimgr, Eugene.Zelenko, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D44602
llvm-svn: 329902
'tooling::fixit::getText' considers a length of "int *" to be 5 instead of 3
in a new algorithm in https://reviews.llvm.org/rCTE329873. It was the root of
the test failure.
llvm-svn: 329881
Summary:
By converting Replacements by AtomicChange, clang-apply-replacements is able like clang-tidy to automatically cleanup and format changes.
This should permits to close this ticket: https://bugs.llvm.org/show_bug.cgi?id=35051 and attempt to follow hints from https://reviews.llvm.org/D43500 comments.
Reviewers: klimek, ioeric
Reviewed By: ioeric
Subscribers: malcolm.parsons, mgorny, cfe-commits
Differential Revision: https://reviews.llvm.org/D43764
Patch by Jeremy Demeule.
llvm-svn: 329813
This check attempts to catch buggy uses of the `TEMP_FAILURE_RETRY`
macro, which is provided by both Bionic and glibc.
Differential Revision: https://reviews.llvm.org/D45059
llvm-svn: 329759
The threshold option is 'MinTypeNameLength' with default value '5'.
With MinTypeNameLength == 5 'int'/'bool' and 'const int'/'const bool'
will not be converted to 'auto', while 'unsigned' will be.
Differential Revision: https://reviews.llvm.org/D45405
llvm-svn: 329730
Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.
With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.
Reviewers: simark, ilya-biryukov, sammccall
Reviewed By: simark, ilya-biryukov, sammccall
Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D44764
llvm-svn: 329725
Adding alias to google-build-namespaces to the Fuchsia module (checks
for anonymous namespaces in headers).
Differential Revision: https://reviews.llvm.org/D45447
llvm-svn: 329720
LLVM_ON_WIN32 is set exactly with MSVC and MinGW (but not Cygwin) in
HandleLLVMOptions.cmake, which is where _WIN32 defined too. Just use the
default macro instead of a reinvented one.
See thread "Replacing LLVM_ON_WIN32 with just _WIN32" on llvm-dev and cfe-dev.
No intended behavior change.
llvm-svn: 329695
Explicitly include and build lib/Testing/Support from LLVM sources when
doing a stand-alone build. This is necessary since clangd tests started
to depend on LLVMTestingSupport library which is neither installed
by LLVM, nor built by clang itself.
Since completely separate build of clang-tools-extra is not supported,
this relies on variables set by clang CMakeLists.
Differential Revision: https://reviews.llvm.org/D45409
llvm-svn: 329594
Summary:
Calculating the include path from absolute file path does not always
work for all build system, e.g. bazel uses symlink as the build working
directory. The absolute file path from editor and clang is diverged from
each other. We need to address it properly in build sysmtem integration.
This patch worksarounds the issue by providing a hook in URI which allows
clients to provide their customized include path.
Reviewers: sammccall
Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45426
llvm-svn: 329578
Summary:
This allows the extension to work with LSP 3.0 and is useful for testing.
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewers: ilya-biryukov
Subscribers: hokein, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45285
llvm-svn: 329574
Summary:
Fix bugs:
- don't count occurrences of decls where we don't spell the name
- findDefinitions at MACRO(^X) goes to the definition of MACRO
Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45356
llvm-svn: 329571
There's an error for PSP4 platform only:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\algorithm(95):
error C2719: '_Pred': formal parameter with requested alignment of 8 won't be aligned
llvm-svn: 329495
class A {...int virtual foo() {...}...};
class B: public A {...int foo() override {...}...};
class C: public B {...int foo() override {... A::foo()...}};
^^^^^^^^ warning: qualified name A::foo refers to a member overridden in subclass; did you mean 'B'? [bugprone-parent-virtual-call]
Differential Revision: https://reviews.llvm.org/D44295
llvm-svn: 329448
This is triggering on a pattern that's both too broad (const
std::string& members can be used safely) and too narrow (std::string is
not the only class with this problem). It has a very low true positive
rate, just remove it until we find a better solution for dangling string
references.
llvm-svn: 329292
Summary:
Currently if a fix is attached directly to a diagnostic, we repeat the
diagnostic message as the fix message. From eyeballing the top diagnostics,
it seems describing the textual replacement would be much clearer.
e.g.
error: use of undeclared identifier 'goo'; did you mean 'foo'?
action before: use of undeclared identifier 'goo'; did you mean 'foo'?
action after: change 'goo' to 'foo'
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, MaskRay, cfe-commits
Differential Revision: https://reviews.llvm.org/D45069
llvm-svn: 329090
Summary:
A common mistake that I have found in our codebase is calling a function to get an integer or enum that represents the type such as:
```
int numBytes = numElements * sizeof(x.GetType());
```
So this extends the `sizeof` check to check for these cases. There is also a `WarnOnSizeOfCall` option so it can be disabled.
Patch by Paul Fultz II!
Reviewers: hokein, alexfh, aaron.ballman, ilya-biryukov
Reviewed By: alexfh
Subscribers: lebedev.ri, xazax.hun, jkorous-apple, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D44231
llvm-svn: 329073
This addresses a persistent failure on clang-cmake-mips buildbot.
Reviewers: ioeric
Differential Revision: https://reviews.llvm.org/D44248
llvm-svn: 329053
This macro is widely used in many well-known projects, ex. Chromium.
But it's not set for clang-tidy, so for ex. DCHECK in Chromium is not considered as [[no-return]], and a lot of false-positive warnings about nullptr dereferenced are emitted.
This patch fixes the issue by explicitly added macro definition.
Differential Revision: https://reviews.llvm.org/D44906
llvm-svn: 328932
Summary:
This patch adds support for incremental document syncing, as described
in the LSP spec. The protocol specifies ranges in terms of Position (a
line and a character), and our drafts are stored as plain strings. So I
see two things that may not be super efficient for very large files:
- Converting a Position to an offset (the positionToOffset function)
requires searching for end of lines until we reach the desired line.
- When we update a range, we construct a new string, which implies
copying the whole document.
However, for the typical size of a C++ document and the frequency of
update (at which a user types), it may not be an issue. This patch aims
at getting the basic feature in, and we can always improve it later if
we find it's too slow.
Signed-off-by: Simon Marchi <simon.marchi@ericsson.com>
Reviewers: malaperle, ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: MaskRay, klimek, mgorny, ilya-biryukov, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D44272
llvm-svn: 328500
When no inputs given, the tools should not only produce the help message, but
also return a non-zero exit code. Fixed tests accordingly.
llvm-svn: 328199
Adding the config initialization to clang-tools-extra so that tests that
use REQUIRES, UNSUPPORTED, and XFAIL based on platform or target triple
work properly.
llvm-svn: 328131
After changes to lit.site.cfg.in, the test is now running (and failing)
on windows, so temporarily marking it unsupported. See PR36855 for more
details.
llvm-svn: 328127
The original check did break the green buildbot in the sanitizer build.
It took a while to redroduce and understand the issue.
There occured a stackoverflow while parsing the AST. The testcase with
256 case labels was the problem because each case label added another
stackframe. It seemed that the issue occured only in 'RelWithDebInfo' builds
and not in normal sanitizer builds.
To simplify the matchers the recognition for the different kinds of switch
statements has been moved into a seperate function and will not be done with
ASTMatchers. This is an attempt to reduce recursion and stacksize as well.
The new check removed this big testcase. Covering all possible values is still
implemented for bitfields and works there. The same logic on integer types
will lead to the issue.
Running it over LLVM gives the following results:
Differential: https://reviews.llvm.org/D40737
llvm-svn: 328107
Summary:
To implement incremental document syncing, we want to verify that the
ranges provided by the front-end are valid. Currently, positionToOffset
deals with invalid Positions by returning 0 or Code.size(), which are
two valid offsets. Instead, return an llvm:Expected<size_t> with an
error if the position is invalid.
According to the LSP, if the character value exceeds the number of
characters of the given line, it should default back to the end of the
line. It makes sense in some contexts to have this behavior, and does
not in other contexts. The AllowColumnsBeyondLineLength parameter
allows to decide what to do in that case, default back to the end of the
line, or return an error.
Reviewers: ilya-biryukov
Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D44673
llvm-svn: 328100
This reverts commit r328060 because a test that was inteded to run on
Windows but never ran before due to the missing config initialization
is now being executed and is failing.
llvm-svn: 328069
Adding the config initialization to clang-tools-extra so that tests that
use REQUIRES, UNSUPPORTED, and XFAIL based on platform or target triple
work properly.
Differential Revision: https://reviews.llvm.org/D44708
llvm-svn: 328060
The current code was casting pointer to a misaligned type which is undefined behavior.
Found by compiling with Undefined Behavior Sanitizer and running tests (check-clang-tools).
llvm-svn: 327902
Exit with a non-zero value in case any of the underlying clang-tidy
invocations exit with a non-zero value.
This is useful in case WarningsAsErrors is enabled for some of the
checks: if any of those checks find something, the exit status now
reflects that.
Also add the ability to use run-clang-tidy.py via lit, and assert that
the exit code is not 0 when modernize-use-auto is triggered
intentionally.
Reviewers: alexfh, aaron.ballman
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D44366
llvm-svn: 327854
Summary:
Detects function calls where the return value is unused.
Checked functions can be configured.
Reviewers: alexfh, aaron.ballman, ilya-biryukov, hokein
Reviewed By: alexfh, aaron.ballman
Subscribers: hintonda, JonasToth, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits
Tags: #clang-tools-extra
Patch by Kalle Huttunen!
Differential Revision: https://reviews.llvm.org/D41655
llvm-svn: 327833