Summary:
If clang-tidy's modernize-use-using feature finds any commas that are not within parentheses, it won't create a fix. That means it won't change lines like:
typedef std::pair<int, int> Point;
to
using Point = std::pair<int, int>;
or even:
typedef std::map<std::string, Foo> MyMap;
typedef std::vector<int,MyCustomAllocator<int>> MyVector;
This patch allows the fix to apply to lines with commas if they are within parentheses or angle brackets that were not themselves within parentheses.
Reviewers: alexfh, hokein, aaron.ballman
Patch by: poelmanc
Subscribers: jonathanmeier, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D67460
Summary:
This is shorter and usually the extra info is noise.
There are cases where the params become type-parameter-0-0 that are hard to fix.
This affects a few features:
- 'name' field in structured hover API (not exposed yet)
- 'name' field in locateSymbolAt (not exposed in LSP)
- 'document/symbol' - the symbol is hierarchically nested in the class
template, or written as foo<t>::foo when defined out-of-line.
Added a test case for hover from https://github.com/clangd/clangd/issues/76.
This patch fixes one field, but no fewer than four others are wrong!
I'll fix them...
Reviewers: hokein
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70308
Summary:
For the constructor Foo() : classmember(arg) {}
The AST looks like:
- CXXCtorInitializer classmember(arg)
- CXXConstructExpr classmember(arg)
- DeclRefExpr: arg
We want the 'classmember' to be associated with the CXXCtorInitializer, not the
CXXConstructExpr. (CXXConstructExpr is known to have bad ranges).
So just early-claim it.
Thanks @hokein for tracking down/reducing the bug.
Reviewers: hokein
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits, hokein
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70312
Summary:
we have a few places using `ASTCtx.getLangOpts().IsHeaderFile` to
determine a header file, but it relies on "-x c-header" compiler flag,
if the compilation command doesn't have this flag, we will get a false
positive. We are encountering this issue in bazel build system.
To solve this problem, we infer the file from file name, actual changes will
come in follow-ups.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70235
Summary:
This doesn't cover decls in diagnostics, which use NamedDecl::getNameForDiagnostic().
(That should also be fixed later I think).
This covers some cases of https://github.com/clangd/clangd/issues/76
(hover, but not outline or sighelp)
Reviewers: hokein
Subscribers: ilya-biryukov, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70236
Summary:
For some reason CMake includes entries for .rc files, but
find-all-symbols handles them improperly.
See PR43993
Reviewers: sammccall, bkramer
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70196
Summary:
The DeclRefExpr for the callee of overloaded `operator()` and `operator[]` are
assigned the range of the paren/bracket lists in the AST.
These are better thought of as implicit (at least `()` - `[] is murkier).
But there's no bit on Expr for implicit, so just ignore them on our side.
While here, deal with the case where an implicit stmt (e.g. implicit-this)
is wrapped in an implicit cast. Previously we ignored the statement but not
the cast, and so the cast ended up being selected.
Fixes https://github.com/clangd/clangd/issues/195
Reviewers: kadircet, lh123
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D70194
Summary:
This revision introduces a new interface `MatchComputation` which generalizes
the `Stencil` interface and replaces the `std::function` interface of
`MatchConsumer`. With this revision, `Stencil` (as an abstraction) becomes just
one collection of implementations of
`MatchComputation<std::string>`. Correspondingly, we remove the `Stencil` class
entirely in favor of a simple type alias, deprecate `MatchConsumer` and change
all functions that accepted `MatchConsumer<std::string>` to use
`MatchComputation<std::string>` instead.
Reviewers: gribozavr
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69802
Summary:
We use the name from the IdentifierInfo of the Macro to compute its
SymbolID. It is better to just take the Name as a parameter to avoid
storing the IdentifierInfo whenever we need the SymbolID for the Macro.
Patch by UTKARSH SAXENA!
Reviewers: hokein
Reviewed By: hokein
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69937
Summary:
There is a regression from https://reviews.llvm.org/D68467. Unlike class
forward declarations, function ducomentation is written in the declaration in
headers, the function definition doesn't contain any documentation, cases like:
```
foo.h
// this is foo.
void foo();
foo.cc
void foo() {}
```
we should still show documentation from the foo declaration.
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69961
This patch reapplies commit 76945821b9. The first version broke
buildbots due to clang-tidy test fails. The fails are because some
errors in templates are now diagnosed earlier (does not wait till
instantiation). I have modified the tests to add checks for these
diagnostics/prevent these diagnostics. There are no additional code
changes.
Summary of code changes:
Clang currently crashes for switch statements inside a template when the
condition is a non-integer field member because contextual implicit
conversion is skipped when parsing the condition. This conversion is
however later checked in an assert when the case statement is handled.
The conversion is skipped when parsing the condition because
the field member is set as type-dependent based on its containing class.
This patch sets the type dependency based on the field's type instead.
This patch fixes Bug 40982.
Reviewers: rnk, gribozavr2
Patch by: Elizabeth Andrews (eandrews)
Differential revision: https://reviews.llvm.org/D69950
Summary:
Updates the relevant source files to use bindings in `clang::transformer` rather
than `clang::tooling`.
Reviewers: gribozavr
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69804
Summary:
Previously, we match ranges, which is hard to spot the difference.
Now, we diff the code after rename against the expected result, it
produces much nicer output.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69890
Summary:
This will be used for incoming cross-file rename (to detect index
staleness issue).
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69615
Summary:
Finds non-static member functions that can be made ``const``
because the functions don't use ``this`` in a non-const way.
The check conservatively tries to preserve logical costness in favor of
physical costness. See readability-make-member-function-const.rst for more
details.
Reviewers: aaron.ballman, gribozavr, hokein, alexfh
Subscribers: mgorny, xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68074
Summary:
To keep the logic of finding locations of interesting AST nodes in one
place.
The advantage is better coverage of various AST nodes, both now and in
the future: as new nodes get added to `findExplicitReferences`, semantic
highlighting will automatically pick them up.
The drawback of this change is that we have to traverse declarations
inside our file twice in order to highlight dependent names, 'auto'
and 'decltype'. Hopefully, this should not affect the actual latency
too much, most time should be spent in building the AST and not
traversing it.
Reviewers: hokein
Reviewed By: hokein
Subscribers: nridge, merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69673
Checks for types which can be made trivially-destructible by removing
out-of-line defaulted destructor declarations.
The check is motivated by the work on C++ garbage collector in Blink
(rendering engine for Chrome), which strives to minimize destructors and
improve runtime of sweeping phase.
In the entire chromium codebase the check hits over 2000 times.
Differential Revision: https://reviews.llvm.org/D69435
Summary:
When moving a function definition to declaration location we also need
to handle renaming of the both function and template parameters.
This patch achives that by making sure every parameter name and dependent type
in destination is renamed to their respective name in the source.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68937
Summary:
These changes were generated by invoking
clang-tools-extra/clang-tidy/add_new_check.py and then reverting the
check that was added.
Reviewers: aaron.ballman
Reviewed By: aaron.ballman
Subscribers: xazax.hun, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69414
Do not warn for redundant conditional expressions when the true and false
branches are expanded from different macros even when they are defined by
one another.
Patch by Daniel Krupp.
Summary:
This provides a convenient way to see the SymbolID/USR of the symbol, mainly
for debugging purpose.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69517
Summary:
Otherwise every client dealing with name location should handle
anonymous names in a special manner.
This seems too error-prone, clients can probably handle anonymous
entities they care about differently.
Reviewers: hokein
Reviewed By: hokein
Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69511
Summary:
Editors are good at highlightings the keywords themselves.
Note that this only affects highlightings of builtin types spelled out
as keywords in the source code. Highlightings of typedefs to builtin
types are unchanged.
Reviewers: hokein
Reviewed By: hokein
Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69431
Summary:
Would be nice to also fix this in clang, but that looks like more work
if we want to preserve signatures in informative chunks.
Fixes https://github.com/clangd/clangd/issues/118
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: merge_guards_bot, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69382
Summary:
Incoming define out-of-line tweak requires access to index.
This patch simply propogates the index in ClangdServer to Tweak::Selection while
passing the AST. Also updates TweakTest to accommodate this change.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69165
Summary:
Initial version of DefineInline action that will fully qualify every
name inside function body.
Reviewers: sammccall, ilya-biryukov, hokein
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66647
Summary:
During the compilation of the `clangd/refactor/tweaks/ExpandAutoType.cpp`, MSVC returns the following error:
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(85): error C2146: syntax error: missing ')' before identifier 'and'
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(85): error C2065: 'and': undeclared identifier
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(86): error C2143: syntax error: missing ';' before '<template-id>'
llvm-monorepo\llvm\tools\clang\tools\extra\clangd\refactor\tweaks\ExpandAutoType.cpp(73): fatal error C1075: '{': no matching token found
So, && must be used instead of `and`.
Patch By Pavel Samolysov (@psamolysov) !
Reviewers: kadircet
Reviewed By: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D69427
Summary:
Incoming define out-of-line tweak requires access to index.
This patch simply propogates the index in ClangdServer to Tweak::Selection while
passing the AST. Also updates TweakTest to accommodate this change.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69165
Summary:
This is an helper for incoming move definition out-of-line action to
figure out possible insertion locations for definition of a qualified name.
Reviewers: hokein, ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68024
Summary:
Initial version of DefineInline action that will fully qualify every
name inside function body.
Reviewers: sammccall, ilya-biryukov, hokein
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66647
Summary:
This is used for cross-file rename. When renaming a class, we expect to
rename all related constructors/destructors.
Reviewers: kadircet, ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69338
Summary:
A certain class of bug (e.g. infloop on an AST worker thread) currently means
clangd never terminates, even if the editor shuts down the protocol and closes
our stdin, and the main thread recognizes that.
Instead, let's wait 60 seconds for threads to finish cleanly, and then crash
if they haven't.
(Obviously, we should still fix these bugs).
Reviewers: kadircet
Subscribers: MaskRay, jkorous, arphaman, jfb, usaxena95, cfe-commits, ilya-biryukov
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69329
Works on this dependency chain:
ArrayRef.h ->
Hashing.h -> --CUT--
Host.h ->
StringMap.h / StringRef.h
ArrayRef is very popular, but Host.h is rarely needed. Move the
IsBigEndianHost constant to SwapByteOrder.h. Clients of that header are
more likely to need it.
llvm-svn: 375316
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us.
llvm-svn: 375102
Summary:
Removes the 'using namespace' under the cursor and qualifies all accesses in the current file.
E.g.:
using namespace std;
vector<int> foo(std::map<int, int>);
Would become:
std::vector<int> foo(std::map<int, int>);
Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68562
llvm-svn: 374982
Summary:
Currently clangd initializes the ClangdServer lazily during
onInitialize request, and it results in propagation of caller's context rather
than the main context created ClangdLSPServer.
This patch changes the logic to store main context that created ClangdLSPServer
and pass it onto to ClangdServer and other objects like CDBs.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68978
llvm-svn: 374892
Fix accidentally making clangTidy library link to dylib. This causes
libclang.so to also link to dylib which results in duplicate symbols
from shared and static libraries, and effectively to registering
command-line options twice.
Thanks to Sylvestre Ledru for noticing this and tracking it down
to r373786. Fixes PR#43589.
Differential Revision: https://reviews.llvm.org/D68927
llvm-svn: 374885
The goal is to have 100% fidelity in clang-scan-deps behavior when
--analyze is present in compilation command.
At the same time I don't want to break clang-tidy which expects
__static_analyzer__ macro defined as built-in.
I introduce new cc1 options (-setup-static-analyzer) that controls
the macro definition and is conditionally set in driver.
Differential Revision: https://reviews.llvm.org/D68093
llvm-svn: 374815
The escaped parens seem to confuse the combination of lit, cygwin
quoting, and cygwin's sed. unxutils sed in cmd.exe is fine with both
forms, so use the extended regex form that doesn't need an escaped
paren.
llvm-svn: 374753
That way, lit's builtin 'env' command can be used for the 'env' bit.
Also it's clearer that way that the 'not' shouldn't cover 'env'
failures.
llvm-svn: 374749
clangd's test:// scheme expands to /clangd-test on non-Win and to
C:/clang-test on Win, so it can't be mixed freely with
file:///clangd-test since that's wrong on Windows. This makes both
tests consistenly use the test:// scheme. (Alternatively, we could use
the //INPUT_DIR pattern used in a few other tests.)
Part of PR43592.
llvm-svn: 374746
The test had a "UNSUPPORTED: win32" line, but the spelling of that
changed in r339307 a year ago. Finally update this test too.
Part of PR43592.
llvm-svn: 374745
The Windows triple currently turns on delayed template parsing, which
confuses several unit tests that use templates.
For now, just explicitly disable delayed template parsing. This isn't
ideal, but:
- the Windows triple will soon no longer use delayed template parsing
by default
- there's precedent for this in the clangd unit tests already
- let's get the clangd tests pass on Windows first before making
behavioral changes
Part of PR43592.
llvm-svn: 374718
On Windows the signed/unsigned int conversions of APInt seems broken, so that
two of the test files marked as unsupported on Windows, as a hotfix.
llvm-svn: 374713