This patch adjusts `PragmaOpenMPHandler` to set the location of
`tok::annot_pragma_openmp` to the `#pragma` location instead of the
`omp` location so that the former becomes the start location of the
OpenMP AST node. This can be useful when, for example, rewriting a
directive using Clang's Rewrite facility. Most of this patch updates
tests for changes to locations in diagnostics and `-ast-dump` output.
Reviewed By: ABataev, lebedev.ri, Meinersbur, aaron.ballman
Differential Revision: https://reviews.llvm.org/D61509
llvm-svn: 361867
Summary:
By producing the $0 marker in the snippets at the last placeholder.
This produces nicer results in most cases, e.g. for
namespace <#name#> {
<#decls#>
}
we now produce ${0:decls} instead of ${2:decls} and the final cursor
placement is more convenient.
Reviewers: hokein
Reviewed By: hokein
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62389
llvm-svn: 361841
Summary:
readability-identifier-naming causes a null pointer dereference when checking an identifier introduced by a structured binding whose right hand side is an undeclared identifier.
Running the check on a file that is just the following results in a crash:
```
auto [left] = right;
```
Patch by Mark Stegeman!
Reviewers: alexfh, hokein, aaron.ballman, JonasToth
Reviewed By: hokein, aaron.ballman
Subscribers: madsravn, xazax.hun, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D62404
llvm-svn: 361809
Summary:
Change ClangdServer layer to output a structured response for Hover,
which can be rendered by client according to their needs.
Reviewers: sammccall, ilya-biryukov
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61497
llvm-svn: 361803
Summary:
A range-for was added in r361647 where the range variable was only used in an
assertion. As a result, it warned for Release builds. This revision
restructures the assertion to avoid the problem.
Patch by Yitzhak Mandelbaum.
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: xazax.hun, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D62412
llvm-svn: 361749
Summary:
In general, the `Explanation` field is optional in `RewriteRule` cases. But,
because the primary purpose of clang-tidy checks is to provide users with
diagnostics, we assume that a missing explanation is a bug. This change adds an
assertion that checks all cases for an explanation, and updates the code to rely
on that assertion correspondingly.
Reviewers: ilya-biryukov
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62340
llvm-svn: 361647
The other options are to completely specify the triple (reduces test
coverage), or to specify a regex that allows either '0' or '0U' for char
initializers, however, that relaxes the test.
llvm-svn: 361629
Summary: A temporary workaround until we figure out a better way to present fixes.
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62372
llvm-svn: 361625
Summary:
We put only part of the signature starting with a function name into "typed text"
chunks now, previously the whole signature was "typed text".
This leads to meaningful fuzzy match scores, giving better signals to
compare with other completion items.
Ideally, we would not display the result type to the user, but that requires adding
a new kind of completion chunk.
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62298
llvm-svn: 361623
Summary:
Added WarnOnlyIfThisHasSuspiciousField option to allow
to catch any copy assignment operator independently from
the container class's fields.
Added the cert alias using this option.
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: mgorny, Eugene.Zelenko, xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62192
llvm-svn: 361550
Summary: See the added test for an example.
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62303
llvm-svn: 361511
Summary:
Clangd is already resolving symlinks on the server side, therefore
there is no more need to handle it in client side. This was also resulting in
breakages whenever index contained a symbol coming from a non-existent file(like
a generated file), e.g. during workspace symbols whole response was dropped
since stat had failed.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62288
llvm-svn: 361475
It's uncommon to rely on temporary lifetime extension when having a
regular, non-`const&` value behaves identically. Since `Twine::str`
and `buildFixMsgForStringFlag` both return regular `std::string`s,
there's seemingly no point in having `const&` here.
llvm-svn: 361457
This revision introduces an adaptor from Transformer's rewrite rules
(`clang::tooling::RewriteRule`) to `ClangTidyCheck`. For example, given a
RewriteRule `MyCheckAsRewriteRule`, it lets one define a tidy check as follows:
```
class MyTidyCheck : public TransformerClangTidyCheck {
public:
MyTidyCheck(StringRef Name, ClangTidyContext *Context)
: TransformerClangTidyCheck(MyCheckAsRewriteRule, Name, Context) {}
};
```
Reviewers: aaron.ballman
Subscribers: mgorny, xazax.hun, cfe-commits, ilya-biryukov
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61386
llvm-svn: 361418
Summary:
run-clang-tidy.py was enforcing '-header-filter' parameter with an
unfortunate default value when none was given. Thus, leading to
overwritten clang-tidy configuration (e.g. from .clang-tidy).
This change removes the default value for '-header-filter' resulting in
the default behaviour of clang-tidy itself.
Fixes PR#41426
Reviewed By: hintonda
Patch by Torbjörn Klatt!
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D61747
llvm-svn: 361344
Catching trivial objects by value is not dangerous but may be
inefficient if they are too large. This patch adds an option
`WarnOnLargeObject` to the checker to also warn if such an object
is caught by value. An object is considered as "large" if its
size is greater than `MaxSize` which is another option. Default
value is the machine word of the architecture (size of the type
`size_t`).
Differential Revision: https://reviews.llvm.org/D61851
llvm-svn: 361225
Summary:
To give an option for clangd embedders with snapshotted filesystem to
read config files from exact snapshots, possibly loosing some
performance from caching capabilities of the current implementations.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62143
llvm-svn: 361178
Summary:
I inspected every test and did one of the following:
- changed the test to run in all language modes,
- added a comment explaining why the test is only applicable in a
certain mode,
- limited the test to language modes where it passes and added a FIXME
to fix the checker or the test.
Reviewers: alexfh, lebedev.ri
Subscribers: nemanjai, kbarton, arphaman, jdoerfert, lebedev.ri, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62125
llvm-svn: 361131
Summary:
By adding a hook to consume all tokens produced by the preprocessor.
The intention of this change is to make it possible to consume the
expanded tokens without re-runnig the preprocessor with minimal changes
to the preprocessor and minimal performance penalty when preprocessing
without recording the tokens.
The added hook is very low-level and reconstructing the expanded token
stream requires more work in the client code, the actual algorithm to
collect the tokens using this hook can be found in the follow-up change.
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: eraman, nemanjai, kbarton, jsji, riccibruno, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59885
llvm-svn: 361007
Summary: The output of clang-tidy itself already has enough newlines, so the resulting output is more in line with the usual compiler output.
Patch by svenpanne.
Reviewers: alexfh, JonasToth
Reviewed By: JonasToth
Subscribers: JonasToth, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61850
llvm-svn: 360883
Summary: When run-clang-tidy is given the -quiet flag, do not output the potentially hundreds of enabled check names at the beginning.
Patch by svenpanne.
Reviewers: alexfh, JonasToth
Reviewed By: JonasToth
Subscribers: JonasToth, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61849
llvm-svn: 360869
Summary:
modernize-loop-convert was not detecting implicit casts to
const_iterator as convertible to range-based loops:
std::vector<int> vec{1,2,3,4}
for(std::vector<int>::const_iterator i = vec.begin();
i != vec.end();
++i) { }
Thanks to Don Hinton for advice.
As well, this change adds a note for this check's applicability to code
targeting OpenMP prior version 5 as this check will continue breaking
compilation with `-fopenmp`. Thanks to Roman Lebedev for pointing this
out.
Fixes PR#35082
Patch by Torbjörn Klatt!
Reviewed By: hintonda
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D61827
llvm-svn: 360788
Summary:
modernize-loop-convert was not detecting implicit casts to
const_iterator as convertible to range-based loops:
std::vector<int> vec{1,2,3,4}
for(std::vector<int>::const_iterator i = vec.begin();
i != vec.end();
++i) { }
Thanks to Don Hinton for advice.
As well, this change adds a note for this check's applicability to code
targeting OpenMP prior to version 5 as this check will continue breaking
compilation with `-fopenmp`. Thanks to Roman Lebedev for pointing this
out.
Fixes PR#35082
Reviewed By: hintonda
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D61827
llvm-svn: 360785
Implement a check for detecting if/else if/else chains where two or more
branches are Type I clones of each other (that is, they contain identical code)
and for detecting switch statements where two or more consecutive branches are
Type I clones of each other.
Patch by Donát Nagy!
Differential Revision: https://reviews.llvm.org/D54757
llvm-svn: 360779
Summary:
Fixed https://bugs.llvm.org/show_bug.cgi?id=40544
Before, we would generate a fixit like `(anonymous namespace)::Foo::fun();` for
the added test case.
Reviewers: aaron.ballman, alexfh, xazax.hun
Subscribers: rnkovacs, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D61874
llvm-svn: 360698
Summary:
readability-redundant-declaration was diagnosing a redundant declaration
on "extern inline void f();", which is needed in C code to force an external definition
of the inline function f. (This is different to how inline behaves in C++).
Reviewers: alexfh, danielmarjamaki
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61700
llvm-svn: 360613
Summary:
This check searches for copy assignment operators which might not handle self-assignment properly. There are three patterns of
handling a self assignment situation: self check, copy-and-swap or the less common copy-and-move. The new check warns if none of
these patterns is found in a user defined implementation.
See also:
OOP54-CPP. Gracefully handle self-copy assignment
https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP54-CPP.+Gracefully+handle+self-copy+assignment
Reviewers: JonasToth, alexfh, hokein, aaron.ballman
Subscribers: riccibruno, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D60507
llvm-svn: 360540
Summary:
Change the namespace for llvm checkers from 'llvm' to
'llvm_check', and modify add_new_check.py and rename_check.py to
support the new namespace. Checker, file, and directory names remain
unchanged.
Used new version of rename_check.py to make the change in existing
llvm checkers, but had to fix LLVMTidyModule.cpp and
LLVMModuleTest.cpp by hand.
The changes made by rename_check.py are idempotent, so if accidentally
run multiple times, it won't do anything.
Reviewed By: aaron.ballman
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D60629
llvm-svn: 360450
Add the modernize-use-trailing-return check to rewrite function signatures to use trailing return types.
Patch by Bernhard Manfred Gruber.
llvm-svn: 360438
Summary:
If the test does not specify a formatting style, force "none"; otherwise
autodetection logic can discover a ".clang-tidy" file that is not
related to the test.
Reviewers: alexfh
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61739
llvm-svn: 360358
Summary:
After rL360344, BackgroundIndex expects symbols with zero refcounts.
Therefore existing index files are no longer valid.
Assertion regarding finding target of a reference was wrong, since
background-index might still be going on or we might've loaded only some part of
the shards and might be missing the declaring shards for the symbol.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61734
llvm-svn: 360349
Summary:
For counting number of references clangd was relying on merging every
duplication of a symbol. Unfortunately this does not apply to FileIndex(and one
of its users' BackgroundIndex), since we get rid of duplication by simply
dropping symbols coming from non-canonical locations. So only one or two(coming
from canonical declaration header and defined source file, if exists)
replications of the same symbol reaches merging step.
This patch changes reference counting logic to rather count number of different
RefSlabs a given SymbolID exists.
Reviewers: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, mgrang, arphaman, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59481
llvm-svn: 360344
Without this, gcc (7.4) complains with
../tools/clang/tools/extra/clangd/unittests/PrintASTTests.cpp:99:28: error: ISO C++11 requires at least one argument for the "..." in a variadic macro [-Werror]
})));
^
llvm-svn: 360334
Summary:
To unify the way we create threads in clangd.
This should simplify landing D50993.
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: MaskRay, jkorous, arphaman, jfb, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61724
llvm-svn: 360332
Summary:
The case when initialize_list hides behind an implicit case was not
handled before.
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61642
llvm-svn: 360231
Accidentally taking the size of a struct-pointer type or a value of this type
is more common than explicitly using the & operator for the value. This patch
extends the check to include these cases.
Differential Revision: https://reviews.llvm.org/D61260
llvm-svn: 360114
Summary: Embedding clients want to experiment with showing such results in e.g. a different color.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61588
llvm-svn: 360039
Some programmers tend to forget that subtracting two pointers results in the
difference between them in number of elements of the pointee type instead of
bytes. This leads to codes such as `size_t size = (p - q) / sizeof(int)` where
`p` and `q` are of type `int*`. Or similarily, `if (p - q < buffer_size *
sizeof(int)) { ... }`. This patch extends `bugprone-sizeof-expression` to
detect such cases.
Differential Revision: https://reviews.llvm.org/D61422
llvm-svn: 360032
Summary:
The hope is this will catch a few patterns with repetition:
SomeClass* S = ^SomeClass::Create()
int getFrobnicator() { return ^frobnicator_; }
// discard the factory, it's no longer valid.
^MyFactory.reset();
Without triggering antipatterns too often:
return Point(x.first, x.^second);
I'm going to gather some data on whether this turns out to be a win overall.
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61537
llvm-svn: 360030
Add an initial '::' qualifier to all usages of 'testing' namespace that
did not have one.
The goal is to make our code style in tests more consistent.
llvm-svn: 360026
This means "format" will no longer return an error if the -fallback-style flag
is invalid, it will log and use LLVM style. This doesn't really matter.
Also document the dependence on global variables. (This patch is a
compromise - it's probably not worth actually avoiding the globals).
llvm-svn: 360020
I'm not sure what i was thinking when i wrote it to point at the directive.
It's at the very least confusing, and in the `for` is very misleading.
We should point at the actual Stmt out of which the exception escapes,
to highlight where it should be fixed e.g. via adding try-catch block.
Yes, this breaks existing NOLINT, which is why this change needs to
happen now, not any later.
llvm-svn: 360002
Summary:
Both of these attempt to check whether a header guard exists while parsing the
file. However the file is only marked as guarded once clang finishes processing
it. We defer the checks and work until SymbolCollector::finish().
This is ugly and ad-hoc, deferring *all* work might be cleaner.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61442
llvm-svn: 359880
Summary:
clangd currently prefers declarations from codegen files. This patch
implements that behavior for definition locations. If we have definiton
locations both coming from AST and index, clangd will perform a merging to show
the codegen file if that's the case.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61126
llvm-svn: 359874
- Remove a parameter name that was misspelled (OS used for non-stream
parameter)
- Declare operator == (TextEdit, TextEdit) outside the struct, for
consistency with other user-declared ops in our code.
- Fix naming style of a parameter.
llvm-svn: 359866
Summary:
This is a tricky case (we baked the assumption that symbols come from
the preamble xor mainfile pretty deeply) and the fix is a bit of a hack:
We look at the code to guess the macro names, and deserialize them from
the preamble "by hand".
Reviewers: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60937
........
Fix buildbots http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/47684/
llvm-svn: 359796
Summary:
This is a tricky case (we baked the assumption that symbols come from
the preamble xor mainfile pretty deeply) and the fix is a bit of a hack:
We look at the code to guess the macro names, and deserialize them from
the preamble "by hand".
Reviewers: ilya-biryukov
Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D60937
llvm-svn: 359778
Summary:
Previously we were just jumping from the symbol index to the symbol page, and
grabbing all the headers mentioned there. But the page often lists multiple
symbols, and so we got false positives and thus ambiguities (which were dropped).
Now we look at which declarations are for the symbol we want, and prefer headers
listed above that symbol. If there are none, we fall back to the old behavior.
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D61316
llvm-svn: 359771