Commit Graph

7887 Commits

Author SHA1 Message Date
Richard 602ea53cb7 [clang-tidy] Refactor: Prefer single quoted strings over double quoted strings [NFC] 2022-03-11 15:08:24 -07:00
Sam McCall 7f0df31ee3 [clang-tools-extra] Don't consider python below LLVM_MINIMUM_PYTHON_VERSION. NFC 2022-03-10 23:57:27 +01:00
Sam McCall 2d58ba200a [clang-tools-extra] Remove unused lit features/substitutions. NFCI 2022-03-10 23:28:43 +01:00
Sam McCall 6ed2f8902b Fix reference to execute_external leftover in 69924ccf7a 2022-03-10 23:20:03 +01:00
Sam McCall 69924ccf7a Remove redundant lit config already handled in llvm_config. NFCI
This logic duplicates lit.llvm.initialize, which we're already calling
(in lit.site.cfg.py.in).
The equivalent logic was removed from clang in d4401d354a but
never cleaned up here.
2022-03-10 23:11:01 +01:00
Yevgeny Rouban c8a35727fe [clangd] Make dexp command line options sticky
Preparing for the cl::opt reset fix proposed on D115433 this
patch fixes the dexp tool to preserve its three command line
options (IndexLocation, ExecCommand, ProjectRoot) from reset
that is done before parsing query options.

Tags: #clang
2022-03-09 13:00:25 +07:00
Yevgeny Rouban 81f8df0c83 [clangd] Make dexp command line options sticky
Preparing for the cl::opt reset fix proposed on D115433 this
patch fixes the dexp tool to preserve its three command line
options (IndexLocation, ExecCommand, ProjectRoot) from reset
that is done before parsing query options.

Tags: #clang
2022-03-09 12:59:49 +07:00
Kirill Bobyrev d5106c8f97
[clangd] NFC: Cleanup IncludeCleaner API
Make a further improvement to decrease verbosity of the API: ASTContext
provides SourceManager access.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D119842
2022-03-08 13:43:25 +01:00
Richard de29719af2 [clang-tools-extra] Document clang tidy unit tests target
Differential Revision: https://reviews.llvm.org/D121019
2022-03-07 08:24:08 -07:00
Balazs Benics e86324f800 [clang-tidy][NFC] Document bugprone-narrowing-conversions check alias 2022-03-04 16:47:11 +01:00
Jun Zhang ac616fbb05
[Clang-tidy] Check the existence of ElaboratedType's qualifiers
The ElaboratedType can have no qualifiers, so we should check it before
use.

Fix #issue53874(https://github.com/llvm/llvm-project/issues/53874)

Differential Revision: https://reviews.llvm.org/D119949
2022-03-01 23:52:44 +08:00
Sockke ba54ebeb5e [clang-tidy] Fix `readability-const-return-type` for pure virtual function.
It cannot match a `pure virtual function`. This patch fixes this behavior.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D116439
2022-03-01 20:55:28 +08:00
Whisperity 9485091827 [NFC][clang-tidy][docs] Remove mention of backported fix of `readability-suspicious-call-argument` from `ReleaseNotes`
Commit 416e689ecd introduced a fix to
`readability-suspicious-call-argument` which added an entry to the
Release Notes, but the same change was backported to **14.0** in commit
e89602b7b2ec12f20f2618cefb864c2b22d0048a.

Hence, this change is not a new thing of the to-be 15.0 release.
2022-03-01 12:06:59 +01:00
Jorge Gorbe Moya de9611befe [NFC] Don't pass temporary LangOptions to Lexer
Since https://reviews.llvm.org/D120334, passing a temporary LangOptions
object to Lexer results in stack-use-after-scope.
2022-02-28 12:53:59 -08:00
Sam McCall 42cb812da7 [clangd] Test fixes missing from 257559ed9 2022-02-26 21:38:25 +01:00
Sam McCall 257559ed9a [clangd] Function return type hints: support lambdas, don't duplicate "->"
While here, fix an ugliness:
  auto foo()->auto { return 42; }
This (silly) code gains a "-> int" hint. While correct and useful, it renders as
  auto foo()->int->auto { return 42; }
which is confusing enough to do more harm than good I think.

Differential Revision: https://reviews.llvm.org/D120416
2022-02-26 21:28:09 +01:00
Sam McCall 671eab254a [clangd] Support IncludeFixer or base specifiers 2022-02-26 15:45:59 +01:00
Sam McCall b09c12c4b9 [clangd] Fix wrong included header. NFC 2022-02-26 14:21:52 +01:00
Sam McCall e63d7bdc28 [clangd] Fix include-cleaner false-positive bug
For TemplateSpecializationType, we were checking the node's newness
twice, so it always failed the second test.

Fixes https://github.com/clangd/clangd/issues/1036
2022-02-26 14:11:48 +01:00
Benjamin Kramer 6c72a97c0e [clangd] Qualify calls to std::move to silence -Wunqualified-std-cast-call. NFC. 2022-02-26 13:36:14 +01:00
Benjamin Kramer dfed8f556d [clangd] Add a missing include. NFC. 2022-02-26 13:23:06 +01:00
Sam McCall 4d006520b8 [clangd] Clean up unused includes. NFCI
Add includes where needed to fix build.
Haven't systematically added used headers, so there is still accidental
dependency on transitive includes.
2022-02-26 12:00:16 +01:00
Whisperity 416e689ecd [clang-tidy] Fix `readability-suspicious-call-argument` crash for arguments without name-like identifier
As originally reported by @steakhal in
http://github.com/llvm/llvm-project/issues/54074, the name extraction logic of
`readability-suspicious-call-argument` crashes if the argument passed to a
function was a function call to a non-trivially named entity (e.g. an operator).

Fixed this crash case by ignoring such constructs and considering them as having
no name.

Reviewed By: aaron.ballman, steakhal

Differential Revision: http://reviews.llvm.org/D120555
2022-02-25 16:24:27 +01:00
Aaron Ballman 27d39e4da0 Use function prototypes when appropriate; NFC
This prepares the clang-tools-extra project for -Wstrict-prototypes
being enabled by default.
2022-02-25 09:08:27 -05:00
Sockke 6cbf15e9b5 [clang-tidy] Fix `readability-non-const-parameter` for parameter referenced by an lvalue
The checker missed a check for a case when the parameter is referenced by an lvalue and this could cause build breakages.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D117090
2022-02-25 14:53:11 +08:00
Sven van Haastregt ba18c360b2 [clang-tidy] Remove opencl-c.h inclusion from tests
After D120254 some clang-tidy tests started failing on release builds.

clang-tidy has been using the `-fdeclare-opencl-builtins` functionality
since this became the default in clang, so there is no need to include
`opencl-c.h`.

Differential Revision: https://reviews.llvm.org/D120470
2022-02-24 16:28:52 +00:00
Nathan James 79353f940c
[clang-tidy][NFC] Remove Tristate from CachedGlobList
The tristate is a little redundant as we can determine if the item was already in the cache based on the return from try_emplace.

Reviewed By: salman-javed-nz

Differential Revision: https://reviews.llvm.org/D120196
2022-02-23 08:35:31 +00:00
Sam McCall b9b6938183 [clangd] Treat 'auto' params as deduced if there's a single instantiation.
This makes hover/go-to-definition/expand-auto etc work for auto params in many
common cases.
This includes when a generic lambda is passed to a function accepting
std::function. (The tests don't use this case, it requires a lot of setup).

Note that this doesn't affect the AST of the function body itself, cause its
nodes not to be dependent, improve code completion etc.
(These sort of improvements seem possible, in a similar "if there's a single
instantiation, traverse it instead of the primary template" way).

Fixes https://github.com/clangd/clangd/issues/493
Fixes https://github.com/clangd/clangd/issues/1015

Differential Revision: https://reviews.llvm.org/D119537
2022-02-21 13:24:11 +01:00
Kesavan Yogeswaran c57b8ca721
[clang-tidy] Provide fine control of color in run-clang-tidy
D90110 modified the behavior of `run-clang-tidy` to always pass the
`--use-color` option to clang-tidy, which enabled colored diagnostics
output regardless of TTY status or .clang-tidy settings. This left the
user with no option to disable the colored output.

This presents an issue when trying to parse the output of run-clang-tidy
programmaticall, as the output is polluted with ANSI escape characters.

This PR fixes this issue in two ways:
1. It restores the default behavior of `run-clang-tidy` to let
   `clang-tidy` decide whether to color output. This allows the user to
   configure color via the `UseColor` option in a .clang-tidy file.
2. It adds mutually exclusive, optional `-use-color` and `-no-use-color`
   argument flags that let the user explicitly set the color option via
   the invocation.

After this change the default behavior of `run-clang-tidy` when no
.clang-tidy file is available is now to show no color, presumably
because `clang-tidy` detects that the output is being piped and defaults
to not showing colored output. This seems like an acceptable tradeoff
to respect .clang-tidy configurations, as users can still use the
`-use-color` option to explicitly enable color.

Fixes #49441 (50097 in Bugzilla)

Reviewed By: njames93

Differential Revision: https://reviews.llvm.org/D119562
2022-02-20 22:00:28 +00:00
Benjamin Kramer 3a1d6a361c [clangd] Remove uuidof warning. Clang never emits this one. 2022-02-20 14:44:47 +01:00
David Goldman 54a962bbfe [clangd] Use `ObjCProtocolLoc` for generalized ObjC protocol support
This removes clangd's existing workaround in favor of proper support
via the newly added `ObjCProtocolLoc`. This improves support by
allowing clangd to properly identify which protocol is selected
now that `ObjCProtocolLoc` gets its own ASTNode.

Differential Revision: https://reviews.llvm.org/D119366
2022-02-18 15:24:00 -05:00
Simon Pilgrim 9415fbbbcf [clangd] getHover - pass FormatStyle argument by const reference
Reported by coverity
2022-02-18 17:27:45 +00:00
Sam McCall 47b749e5be [clangd] Tweak --query-driver to ignore slash direction on windows
See https://github.com/clangd/clangd/issues/1022

Differential Revision: https://reviews.llvm.org/D120115
2022-02-18 18:06:36 +01:00
Simon Pilgrim 707157f248 Revert rGc24e197aaad5333717a27f6e4346f97da84821ed "[clangd] getHover - pass FormatStyle argument by const reference"
There are a number of buildbot build failures on non MSVC compilers
2022-02-18 14:59:57 +00:00
Simon Pilgrim c24e197aaa [clangd] getHover - pass FormatStyle argument by const reference
Reported by coverity
2022-02-18 14:45:51 +00:00
Simon Pilgrim 535e7b09c1 [clangd] lookupSiblingsWithinContext - remove unnecessary nullptr check
The DC pointer is always dereferenced after the loop
2022-02-18 11:12:53 +00:00
Brad Smith f374c8ddf2 [clangd] Fix building SerializationTests unit test on OpenBSD
This fixes building the unit tests on OpenBSD. OpenBSD does not support RLIMIT_AS.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D119989
2022-02-17 12:17:12 -05:00
Simon Pilgrim 1c502c63cb [clang-doc] SerializeIndex - pass Index param by constant reference
Silence coverity warnings about unnecessary copies
2022-02-17 13:28:02 +00:00
Christopher Di Bella d7b1c840ba [clangd][NFC] includes missing headers
`Shutdown.h` was transitively depending on two headers, but this isn't
allowed under a modules build, so they're now explicitly included.

Differential Revision: https://reviews.llvm.org/D119806
2022-02-15 17:44:47 +00:00
Jan Svoboda 7a124f4859 [clang][lex] Remove `PPCallbacks::FileNotFound()`
The purpose of the `FileNotFound` preprocessor callback was to add the ability to recover from failed header lookups. This was to support downstream project.

However, injecting additional search path while performing header search can invalidate currently used iterators/references to `DirectoryLookup` in `Preprocessor` and `HeaderSearch`.

The downstream project ended up maintaining a separate patch to further tweak the functionality. Since we don't have any upstream users nor open source downstream users, I'd like to remove this callback for good to prevent future misuse. I doubt there are any actual downstream users, since the functionality is definitely broken at the moment.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D119708
2022-02-15 09:48:25 +01:00
Evgeny Shulgin fc84ebfff3 [clang-tidy] Ignore variable template partial specializations in `misc-definitions-in-headers`
Variable template partial specializations are inline and can't lead
to ODR-violations. The checker now ignores them.

Fixes https://github.com/llvm/llvm-project/issues/53519

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D119098
2022-02-14 11:38:27 +01:00
Simon Pilgrim 5d1e3ed3e2 [clang-tidy] SimplifyBooleanExprCheck - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The IfStmt pointer is always referenced inside the replaceCompoundReturnWithCondition call, so assert the cast is correct instead of returning nullptr
2022-02-12 19:59:30 +00:00
Simon Pilgrim 7ad94bd74b [clang-tidy] ContainerSizeEmptyCheck::check - simplify isa<> and dyn_cast<> repeated calls
Just use dyn_cast<> to determine literal + container values from the binop
2022-02-12 11:31:27 +00:00
Simon Pilgrim 2188e61691 [clang-doc] populateParentNamespaces - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr

It's only later iterations of the loop where the getParent() call might return nullptr
2022-02-12 11:28:50 +00:00
Simon Pilgrim 869c066ca8 [clang-tidy] RedundantControlFlowCheck::issueDiagnostic - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-12 11:05:59 +00:00
Simon Pilgrim 9acba5206a [clang-tidy] FunctionASTVisitor::TraverseStmt - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-12 11:04:20 +00:00
Simon Pilgrim ed5d659038 [clang-tidy] NoexceptMoveConstructorCheck::check - use castAs<> instead of getAs<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-12 10:57:09 +00:00
Simon Pilgrim 99acc0dc64 [clang-tidy] UseNoexceptCheck::check - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-12 10:51:48 +00:00
Simon Pilgrim 003e038264 [clang-tidy] getOutermostNamespace - remove redundant nullptr check
The pointer is always dereferenced
2022-02-12 10:49:54 +00:00
Simon Pilgrim 5bc13f9d94 [clang-tidy] ProBoundsConstantArrayIndexCheck::check - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-12 10:43:21 +00:00
Simon Pilgrim 389bee71ea [clang-tidy] checkOverridingFunctionReturnType - use castAs<> instead of getAs<> to avoid dereference of nullptr
The pointers are referenced immediately, so assert the cast is correct instead of returning nullptr
2022-02-12 10:41:43 +00:00
Kirill Bobyrev 100ec80ab5 [clang-tidy] Add early exit for defaulted FunctionDecls
This prevents matching of defaulted comparison operators.

Resolves: https://github.com/llvm/llvm-project/issues/53355

Author: Febbe (Fabian Keßler)
2022-02-10 20:29:26 +01:00
Christian Kandeler bd6c6974f5
clangd: Set a diagnostic on a code action resulting from a tweak
... if there is a match.
This is needed to that clients can can make a connection between a
diagnostic and an associated quickfix-tweak.
Ideally, quickfix-kind tweak code actions would be provided inline along
with the non-tweak fixes, but this doesn't seem easily achievable.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D118976
2022-02-10 15:58:12 +01:00
Greg Miller d038faea46 [clang-tidy] add option performance-move-const-arg.CheckMoveToConstRef
This option allows callers to disable the warning from
https://clang.llvm.org/extra/clang-tidy/checks/performance-move-const-arg.html
that would warn on the following

```
void f(const string &s);
string s;
f(std::move(s));  // ALLOWED if performance-move-const-arg.CheckMoveToConstRef=false
```

The reason people might want to disable this check, is because it allows
callers to use `std::move()` or not based on local reasoning about the
argument, and without having to care about how the function `f` accepts
the argument. Indeed, `f` might accept the argument by const-ref today,
but change to by-value tomorrow, and if the caller had moved the
argument that they were finished with, the code would work as
efficiently as possible regardless of how `f` accepted the parameter.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D119370
2022-02-10 13:31:07 +00:00
Yuanfang Chen 4f30a52696 NFC: fix GCC warning -Wcast-qual 2022-02-09 18:03:25 -08:00
Jameson Nash 76cad51ba7 replace clang LLVM_ENABLE_PLUGINS -> CLANG_PLUGIN_SUPPORT in tests
Ensure CLANG_PLUGIN_SUPPORT is compatible with llvm_add_library.
Fixes an issue noted in D111100.

Differential Revision: https://reviews.llvm.org/D119199
2022-02-09 17:31:34 -05:00
Kirill Bobyrev 46a6f5ae14 [clangd] NFC: Move stdlib headers handling to Clang
This will allow moving the IncludeCleaner library essentials to Clang
and decoupling them from the majority of clangd.

The patch itself just moves the code, it doesn't change existing
functionality.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D119130
2022-02-09 11:05:39 +01:00
Corentin Jabot c151225096 [C++2b] Implement multidimentional subscript operator
Implement P2128R6 in C++23 mode.

Unlike GCC's implementation, this doesn't try to recover when a user
meant to use a comma expression.

Because the syntax changes meaning in C++23, the patch is *NOT*
implemented as an extension. Instead, declaring an array with not
exactly 1 parameter is an error in older languages modes. There is an
off-by-default extension warning in C++23 mode.

Unlike the standard, we supports default arguments;

Ie, we assume, based on conversations in WG21, that the proposed
resolution to CWG2507 will be accepted.

We allow arrays OpenMP sections and C++23 multidimensional array to
coexist:

[a , b] multi dimensional array
[a : b] open mp section
[a, b: c] // error

The rest of the patch is relatively straight forward: we take care to
support an arbitrary number of arguments everywhere.
2022-02-08 12:10:47 -05:00
Jesko Appelfeller 0851970af5 Make run-clang-tidy.py print the configured checks correctly
The test invocation at the start of run-clang-tidy.py (line 257) prints
all enabled checks - meaning either the default set or anything
configured via the -checks option. If any checks were (un-)configured
via the -config option, these are not printed. This is confusing to the
user, since the list of checks that are printed may be different from
the list of checks that are used by the non-testing calls to clang-tidy,
where the -config option is passed correctly.

This patch adds the -config option to the test invocation of clang-tidy
at the start of the script. This means that checks (un-)configured via
the -config option (rather than the -checks option) are applied
correctly, when printing the list of enabled checks.
2022-02-08 08:32:04 -05:00
David Goldman f98bf92b62 Reland "[clangd] Properly compute framework-style include spelling"
Roll forward of https://reviews.llvm.org/D117056 with a fix. Proper
initialization of `IsPrivateHeader` was missing, causing failures
on Linux.
2022-02-07 11:21:23 -05:00
Balázs Kéri 29fc5e0245 [clang-tidy] Fixed a compile warning (NFC).
Fixed a "override" related warning in SharedPtrArrayMismatchCheck.h.
Related to differential revision: https://reviews.llvm.org/D117306
2022-02-07 14:56:27 +01:00
Balázs Kéri c63522e6ba [clang-tidy] Add new check 'shared-ptr-array-mismatch'.
Reviewed By: LegalizeAdulthood

Differential Revision: https://reviews.llvm.org/D117306
2022-02-07 12:57:58 +01:00
David Goldman fb7ddd0628 Revert "[clangd] Properly compute framework-style include spelling"
This reverts commit 4dfd11324e
due to the failures on Linux CI:
https://lab.llvm.org/buildbot/#/builders/188/builds/9296
2022-02-04 18:02:32 -05:00
David Goldman 6abb70c2d0 Attempt forward fix after 4dfd113
If this doesn't work will just revert the change,
can't seem to repro on macOS.
2022-02-04 17:47:38 -05:00
David Goldman 4dfd11324e [clangd] Properly compute framework-style include spelling
With this change, clangd now computes framework-style includes
for framework headers at indexing time.

Differential Revision: https://reviews.llvm.org/D117056
2022-02-04 16:40:56 -05:00
Kadir Cetinkaya 0447ec2fb0
[clang-tidy] Fix LLVM include order check policy
Clang-format LLVM style has a custom include category for gtest/ and
gmock/ headers between regular includes and angled includes. Do the same here.

Fixes https://github.com/llvm/llvm-project/issues/53525.

Differential Revision: https://reviews.llvm.org/D118913
2022-02-03 17:32:43 +01:00
Kirill Bobyrev 089d9c50b2
[clangd] IncludeCleaner: Decrease API dependency on clangd
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D118882
2022-02-03 14:40:53 +01:00
Christian Kühnel 2f8da95e07 [clangd][nfc] cleanup of remaining clang-tidy findings
There were some left-overs (or new things) from the previous patches.

This will get us down to 0 open findings except:
clang-tidy is complaining in some files about
`warning: #includes are not sorted properly [llvm-include-order]`
however, clang-format does revert these changes.
It looks like clang-tidy and clang-format disagree there.

Not sure how we can fix that...

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D118698
2022-02-03 12:05:25 +00:00
Haojian Wu c39969ef25 [clangd] NFC, remove an unused local varaiable. 2022-02-03 12:52:24 +01:00
Tom Stellard a2601c9887 Bump the trunk major version to 15 2022-02-01 23:54:52 -08:00
Tom Stellard e80c52986e [docs] Remove hard-coded version numbers from sphinx configs
This updates all the non-runtime project release notes to use the
version number from CMake instead of the hard-coded version numbers
in conf.py.

It also hides warnings about pre-releases when the git suffix
is dropped from the LLVM version in CMake.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D112181
2022-02-01 23:14:12 -08:00
Jameson Nash 84f137a590 Reland "enable plugins for clang-tidy"
This reverts commit ab3b89855c but
disables the new test if the user has disabled support for building it.
2022-02-01 17:37:24 -05:00
Sam McCall 7af1a2ed81 [clangd] Fix handling of co_await in go-to-type 2022-02-01 16:01:53 +01:00
Sam McCall e9cba78653 [clangd] Group and extend release notes 2022-02-01 15:51:57 +01:00
Christian Kühnel 8edfc2f814 [clangd] Cleanup of readability-identifier-naming
Auto-generated patch based on clang-tidy readability-identifier-naming.
Only some manual cleanup for `extern "C"` declarations and a GTest change was required.

I'm not sure if this cleanup is actually very useful. It cleans up clang-tidy findings to the number of warnings from clang-tidy should be lower.  Since it was easy to do and required only little cleanup I thought I'd upload it for discussion.

One pattern that keeps recurring: Test **matchers** are also supposed to start with a lowercase letter as per LLVM convention. However GTest naming convention for matchers start with upper case. I would propose to keep stay consistent with the GTest convention there. However that would imply a lot of `//NOLINT` throughout these files.

To re-product this patch run:
```
run-clang-tidy -checks="-*,readability-identifier-naming" -fix -format ./clang-tools-extra/clangd
```

To convert the macro names, I was using this script with some manual cleanup afterwards:
https://gist.github.com/ChristianKuehnel/a01cc4362b07c58281554ab46235a077

Differential Revision: https://reviews.llvm.org/D115634
2022-02-01 13:31:52 +00:00
Sam McCall 1ed0b0e657 Tweak formatting & wording in clangd release notes 2022-01-31 19:02:54 +01:00
Simon Pilgrim 1307f66d17 [clang-tidy] getLambdaProperties - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-31 17:25:16 +00:00
Kadir Cetinkaya 236458ef02
[cte] Add release notes for clangd-14
Differential Revision: https://reviews.llvm.org/D118592
2022-01-31 16:32:25 +01:00
Benjamin Kramer e07823ad72 [clang-tidy] Make header compile standalone. NFC. 2022-01-31 11:18:00 +01:00
Balázs Kéri b088237f08 [clang-tidy] bugprone-signal-handler improvements: display call chain
Display notes for a possible call chain if an unsafe function is found to be
called (maybe indirectly) from a signal handler.
The call chain displayed this way includes probably not the first calls of
the functions, but it is a valid possible (in non path-sensitive way) one.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D118224
2022-01-31 10:35:23 +01:00
Petr Hosek ab3b89855c Revert "enable plugins for clang-tidy"
This reverts commit 36892727e4 which
breaks the build when LLVM_INSTALL_TOOLCHAIN_ONLY is enabled with:

  CMake Error at cmake/modules/AddLLVM.cmake:683 (add_dependencies):
  The dependency target "clang-tidy-headers" of target "CTTestTidyModule"
  does not exist.
2022-01-31 00:55:43 -08:00
Kazu Hirata 2f18b02de7 [clang-tools-extra] Remove unused forward declarations (NFC) 2022-01-30 16:05:00 -08:00
Richard 9948020682 [clang-tidy] Organize the release notes a little better
- Sort new checks by check name
- Sort changes to existing checks by check name
- Add docs for changes to readability-simplify-boolean-expr
- Move check changes from "Improvements to clang-tidy" to
  "Changes in existing checks" section

Differential Revision: https://reviews.llvm.org/D118519
2022-01-29 20:32:25 -07:00
Jameson Nash 36892727e4 enable plugins for clang-tidy
Fixes #32739

Differential Revision: https://reviews.llvm.org/D111100
2022-01-29 14:21:19 -05:00
Sam McCall 93cf9640fa Add 'clangd' prefix to remote index proto targets
Some pieces of build infrastructure (shlib, debian package) classify
targets based on whether they begin with "clang".
2022-01-29 02:20:52 +01:00
Richard 99217fa8a0 [clang-tidy] Recognize labelled statements when simplifying boolean exprs
Inside a switch the caseStmt() and defaultStmt() have a nested statement
associated with them.  Similarly, labelStmt() has a nested statement.
These statements were being missed when looking for a compound-if of the
form "if (x) return true; return false;" when the if is nested under one
of these labelling constructs.

Enhance the matchers to look for these nested statements using some
private matcher hasSubstatement() traversal matcher on case, default
and label statements.  Add the private matcher hasSubstatementSequence()
to match the compound "if (x) return true; return false;" pattern.

- Add unit tests for private matchers and corresponding test
  infrastructure
- Add corresponding test file readability-simplify-bool-expr-case.cpp.
- Fix variable name copy/paste error in readability-simplify-bool-expr.cpp.
- Drop the asserts, which were used only for debugging matchers.
- Run clang-format on the whole check.
- Move local functions out of anonymous namespace and declare state, per
  LLVM style guide
- Declare labels constexpr
- Declare visitor arguments as pointer to const
- Drop braces around simple control statements per LLVM style guide
- Prefer explicit arguments over default arguments to methods

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

Fixes #27078
2022-01-28 16:09:46 -07:00
Haojian Wu 15dfe7a3f1 [clangd] Fix a typo , => ; in hovertest.
I somehow missed it.
2022-01-27 22:19:09 +01:00
Haojian Wu 0cf75aac42 [clangd] Enable hover on character literal.
In the initial hover expression patch (https://reviews.llvm.org/D72500), we
disabled all literals.

There is some value on running hover on character literals (e.g. see the
int value of the char).

Differential Revision: https://reviews.llvm.org/D117864
2022-01-27 21:22:03 +01:00
Haojian Wu 4cb1686bfe [clangd] Fix a selection tree crash for unmatched-bracket code.
Fixes https://github.com/clangd/clangd/issues/999

Differential Revision: https://reviews.llvm.org/D118322
2022-01-27 21:21:40 +01:00
Richard 8ce99dadb0 [clang-tidy] Add more documentation about check development (NFC)
- Mention pp-trace
- CMake configuration
- Overriding registerPPCallbacks
- Overriding isLanguageVersionSupported
- Check development tips
  - Guide to useful documentation
  - Using the Transformer library
  - Developing your check incrementally
  - Creating private matchers
  - Unit testing helper code
  - Making your check robust
  - Documenting your check
- Describe the Inputs test folder

Differential Revision: https://reviews.llvm.org/D117939
2022-01-27 09:44:09 -07:00
MuAlphaOmegaEpsilon ccce1a03c9 Don't trigger unused-parameter warnings on naked functions
This commit checks if a function is marked with the naked attribute
and, if it is, will silence the emission of any unused-parameter
warning.

Inside a naked function only the usage of basic ASM instructions is
expected. In this context the parameters can actually be used by
fetching them according to the underlying ABI. Since parameters might
be used through ASM instructions, the linter and the compiler will have
a hard time understanding if one of those is unused or not, therefore
no unused-parameter warning should ever be triggered whenever a
function is marked naked.
2022-01-27 11:40:08 -05:00
Kadir Cetinkaya c4e68953f6
[clangd][Hover] Suppress initializers with many tokens
This results in excessive memory usage and eats a lot of screen estate.
Especially in the cases with lots of nested macro calls.

This patch tries to remedy it before the release cut by suppressing the
initializers. For better UX we should probably update the expression printer to
truncate those (behind some policy).

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

Differential Revision: https://reviews.llvm.org/D118260
2022-01-27 13:01:55 +01:00
Evgeny Shulgin 836950c4e6 [clang-tidy] Fix nested namespaces in `readability-static-definition-in-anonymous-namespace` check
The check previously inspected only the immediate parent namespace.
`static` in a named namespace within an unnamed namespace is still
redundant.
We will use `Decl::isInAnonymousNamespace()` method that traverses the
namespaces hierarchy recursively.

Differential Revision: https://reviews.llvm.org/D118010
2022-01-26 21:54:17 -07:00
Sam McCall 33c3ef2fbe [CodeCompletion][clangd] Clean __uglified parameter names in completion & hover
Underscore-uglified identifiers are used in standard library implementations to
guard against collisions with macros, and they hurt readability considerably.
(Consider `push_back(Tp_ &&__value)` vs `push_back(Tp value)`.
When we're describing an interface, the exact names of parameters are not
critical so we can drop these prefixes.

This patch adds a new PrintingPolicy flag that can applies this stripping
when recursively printing pieces of AST.
We set it in code completion/signature help, and in clangd's hover display.
All three features also do a bit of manual poking at names, so fix up those too.

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

Differential Revision: https://reviews.llvm.org/D116387
2022-01-26 15:51:17 +01:00
Salman Javed c283c8dfb5 Rewrite Doxygen comment to resolve -Wdocumentation warning (NFC)
Comment change only, no functional change intended.
Example of warning:
https://lab.llvm.org/buildbot/#/builders/188/builds/8696/steps/4/logs/warnings__2_
2022-01-27 02:21:05 +13:00
Salman Javed 5da7c04003 Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build bot 2022-01-27 01:03:27 +13:00
Salman Javed 8e29d19b8d Revert "[clang-tidy] Cache the locations of NOLINTBEGIN/END blocks"
Build warning here:
https://lab.llvm.org/buildbot/#/builders/57/builds/14322
2022-01-27 00:52:44 +13:00
Salman Javed 19eaad94c4 [clang-tidy] Cache the locations of NOLINTBEGIN/END blocks
Support for NOLINT(BEGIN/END) blocks (implemented in D108560) is
currently costly. This patch aims to improve the performance with the
following changes:

- The use of tokenized NOLINTs instead of a series of repetitive ad-hoc
string operations (`find()`, `split()`, `slice()`, regex matching etc).
- The caching of NOLINT(BEGIN/END) block locations. Determining these
locations each time a new diagnostic is raised is wasteful as it
requires reading and parsing the entire source file.

Move NOLINT-specific code from `ClangTidyDiagnosticConsumer` to new
purpose-built class `NoLintDirectiveHandler`.

Differential Revision: https://reviews.llvm.org/D116085
2022-01-27 00:12:16 +13:00
Richard f0726ae0f9 Refactor: Extract Class MessagePrefix (NFC)
The work is the same, the only difference is the prefix
of the strings we look for in the reference files.
2022-01-25 23:19:33 -07:00
Sam McCall ce94432702 [clangd] Add designator inlay hints for initializer lists.
These make the init lists appear as if designated initialization was used.

Example:
  ExpectedHint{"param: ", "arg"}
becomes
  ExpectedHint{.Label="param: ", .RangeName="arg"}

Differential Revision: https://reviews.llvm.org/D116786
2022-01-26 00:35:29 +01:00
Zinovy Nis 19d7a0b47b [clang-tidy] [bugprone-assert-side-effect] Ignore list for functions/methods
A semicolon-separated list of the names of functions or methods to be considered as not having side-effects was added for bugprone-assert-side-effect. It can be used to exclude methods like iterator::begin/end from being considered as having side-effects.

Differential Revision: https://reviews.llvm.org/D116478
2022-01-25 21:04:07 +03:00
Balázs Kéri 9d8c3ad94f [clang-tidy] Change code of SignalHandlerCheck (NFC).
Using clang::CallGraph to get the called functions.
This makes a better foundation to improve support for
C++ and print the call chain.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D118016
2022-01-25 15:52:38 +01:00
Jim Lin f3314e3747 [clang-tidy] Pop Files only if FileChangeReason is ExitFile
enum FileChangeReason has four possible type EnterFile, ExitFile,
SystemHeaderPragma and RenameFile,
It should pop the back element of Files only if FileChangeReason is ExitFile.
2022-01-25 22:46:12 +08:00
Christian Kühnel c0e3c893aa [NFC][clangd] cleaning up llvm-qualified-auto
This is a cleanup of all llvm-qualified-auto findings.
This patch was created by automatically applying the fixes from
clang-tidy.

Differential Revision: https://reviews.llvm.org/D113898
2022-01-25 13:26:33 +00:00
Richard 810f13f0eb [clang-tools-extra] Fix documentation build (NFC) 2022-01-24 20:19:03 -07:00
Yuanfang Chen 3b64ab574d [NFC][clangd] Use table to collect option aliases
* Suppress a lot of `-Wtautological-compare` warning
* Speed up file build a little bit

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D98110
2022-01-24 14:27:14 -08:00
serge-sans-paille a0d5e938fe Add missing include llvm/ADT/STLExtras 2022-01-24 14:41:24 +01:00
Adrian Vogelsgesang 3696c70e67 [clang-tidy] Add `readability-container-contains` check
This commit introduces a new check `readability-container-contains` which finds
usages of `container.count()` and `container.find() != container.end()` and
instead recommends the `container.contains()` method introduced in C++20.

For containers which permit multiple entries per key (`multimap`, `multiset`,
...), `contains` is more efficient than `count` because `count` has to do
unnecessary additional work.

While this this performance difference does not exist for containers with only
a single entry per key (`map`, `unordered_map`, ...), `contains` still conveys
the intent better.

Reviewed By: xazax.hun, whisperity

Differential Revision: http://reviews.llvm.org/D112646
2022-01-24 12:57:18 +01:00
Kazu Hirata ee591a64a7 [clang] Forward-declare DynTypedNode (NFC)
This patch adds a forward declaraiton of DynTypedNode.

DumpAST.h is relying on the forward declaration of DynTypedNode in
ASTContext.h, which is undesirable.
2022-01-23 13:28:04 -08:00
Richard d2e8fb3318 [clang-tidy] Add readability-duplicate-include check
Looks for duplicate includes and removes them.

Every time an include directive is processed, check a vector of filenames
to see if the included file has already been included.  If so, it issues
a warning and a replacement to remove the entire line containing the
duplicated include directive.

When a macro is defined or undefined, the vector of filenames is cleared.
This enables including the same file multiple times, but getting
different expansions based on the set of active macros at the time of
inclusion.  For example:

  #undef NDEBUG
  #include "assertion.h"
  // ...code with assertions enabled

  #define NDEBUG
  #include "assertion.h"
  // ...code with assertions disabled

Since macros are redefined between the inclusion of assertion.h,
they are not flagged as redundant.

Differential Revision: https://reviews.llvm.org/D7982
2022-01-23 09:23:04 -07:00
Carlos Galvez eb3f20e8fa [clang-tidy] Remove gsl::at suggestion from cppcoreguidelines-pro-bounds-constant-array-index
Currently the fix hint is hardcoded to gsl::at(). This poses
a problem for people who, for a number of reasons, don't want
or cannot use the GSL library (introducing a new third-party
dependency into a project is not a minor task).

In these situations, the fix hint does more harm than good
as it creates confusion as to what the fix should be. People
can even misinterpret the fix "gsl::at" as e.g. "std::array::at",
which can lead to even more trouble (e.g. when having guidelines
that disallow exceptions).

Furthermore, this is not a requirement from the C++ Core Guidelines.
simply that array indexing needs to be safe. Each project should
be able to decide upon a strategy for safe indexing.

The fix-it is kept for people who want to use the GSL library.

Differential Revision: https://reviews.llvm.org/D117857
2022-01-23 15:52:42 +00:00
Simon Pilgrim df0fd1c301 [clangd] Use castAs<> instead of getAs<> to avoid dereference of nullptr
The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-23 13:24:36 +00:00
Simon Pilgrim 86497026a2 [clang-tidy] Use cast<>/castAs<> instead of dyn_cast<>/getAs<> to avoid dereference of nullptr
The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-23 12:57:12 +00:00
John Ericson 7c16647c36 [clang-tools-extra][cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-22 20:57:21 +00:00
Benjamin Kramer b8102449a7 [clang-tidy] Avoid binding nullptr to a reference
That's undefined behavior. Found by -fsanitize=null.
2022-01-21 15:55:17 +01:00
Jan Svoboda 622354a522 [llvm][ADT] Implement `BitVector::{pop_,}back`
LLVM Programmer’s Manual strongly discourages the use of `std::vector<bool>` and suggests `llvm::BitVector` as a possible replacement.

Currently, some users of `std::vector<bool>` cannot switch to `llvm::BitVector` because it doesn't implement the `pop_back()` and `back()` functions.

To enable easy transition of `std::vector<bool>` users, this patch implements `llvm::BitVector::pop_back()` and `llvm::BitVector::back()`.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D117115
2022-01-21 14:50:53 +01:00
Kadir Cetinkaya 825a3cd6b6
[clangd] Fail inlayHints requests on content changes
This should improve the overall UX by making the labels less jumpy.

Differential Revision: https://reviews.llvm.org/D117776
2022-01-21 12:40:49 +01:00
Kadir Cetinkaya 597eae998a
[clangd][Background] Make index validation logs verbose
These errors are non-harmful and should be transient. They either
imply:
- compilation database returned stale results for TUs and it'll be fixed once
  it's updated to match project state.
- a TUs dependencies has changed and some headers no longer exist. this should
  be fixed with the next indexing cycle.

In either case the user will have some stale symbols in their index until clangd
restarts and the underlying issue is resolved. On the downside these logs are
confusing users when there's another issue.

Differential Revision: https://reviews.llvm.org/D117792
2022-01-21 12:37:20 +01:00
Sockke a7f8aea714 [clang-tidy] Fix wrong FixIt in performance-move-const-arg
There are incorrect Fixit and missing warnings:
case :
A trivially-copyable object wrapped by std::move is passed to the function with rvalue reference parameters. Removing std::move will cause compilation errors.
```
void showInt(int&&) {}
void testInt() {
    int a = 10;
    // expect: warning + nofix
    showInt(std::move(a));  // showInt(a) <--- wrong fix
}

struct Tmp {};
void showTmp(Tmp&&) {}
void testTmp() {
    Tmp t;
    // expect: warning + nofix
    showTmp(std::move(t));  // showTmp(t) <--- wrong fix
}
```

Reviewed By: aaron.ballman, Quuxplusone

Differential Revision: https://reviews.llvm.org/D107450
2022-01-21 14:23:52 +08:00
Fabian Wolff d3b188a2d7 [clang-tidy] Include constructor initializers in `bugprone-exception-escape` check
Fixes PR#52435.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D113507
2022-01-21 00:53:57 +01:00
CJ Johnson a568411444 [clang-tidy] Update bugprone-stringview-nullptr to consistently prefer the empty string when passing arguments to constructors/functions
Previously, function(nullptr) would have been fixed with function({}). This unfortunately can change overload resolution and even become ambiguous. T(nullptr) was already being fixed with T(""), so this change just brings function calls in line with that.

Differential Revision: https://reviews.llvm.org/D117840
2022-01-20 18:08:40 -05:00
Nathan James 39f779afb3
[clang-tidy][NFC] Remove redundant string creation for comparison 2022-01-20 22:20:10 +00:00
Richard baa08d1ec3 [clang-tidy] Revert documentation change (NFC)
Restore a fix to the list of checks that was undone by a recent commit.
2022-01-20 01:27:23 -07:00
Richard 058d212379 [clang-tidy] Use literal block instead of code block (NFC)
I used a C++ code block in check documentation to show example
output from clang-tidy, but since the example output isn't
kosher C++, sphinx didn't like that when it went to syntax
highlight the block.  So switch to a literal block instead
and forego any highlighting.

Fixes build error
<https://lab.llvm.org/buildbot/#/builders/115/builds/21145>
2022-01-19 15:23:48 -07:00
Richard d83ecd77cc [clang-tidy] Narrow cppguidelines-macro-usage to actual constants
Previously, any macro that didn't look like a varargs macro
or a function style macro was reported with a warning that
it should be replaced with a constexpr const declaration.
This is only reasonable when the macro body contains constants
and not expansions like ",", "[[noreturn]]", "__declspec(xxx)",
etc.

So instead of always issuing a warning about every macro that
doesn't look like a varargs or function style macro, examine the
tokens in the macro and only warn about the macro if it contains
only comment and constant tokens.

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

Fixes #39945
2022-01-19 12:28:22 -07:00
Nathan James a4bdeb9a56
[clang-tidy][NFC] replace some redundant std::string creations 2022-01-19 18:36:35 +00:00
Haojian Wu 55b702c37b [clangd] NFC, emit source ranges in selection debug messages.
It will make the output more versbose, but I found that these are useful
information when debugging selection tree.

Differential Revision: https://reviews.llvm.org/D117475
2022-01-19 16:06:58 +01:00
Haojian Wu 6c78703e3a [AST] Fix the incorrect auto-keyword loc for constrained auto type loc.
E.g.  `Concept auto Func();`

The nameLoc for the constained auto type loc pointed to the concept name
loc, it should be the auto token loc. This patch fixes it, and remove
a relevant hack in clang-tidy check.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D117009
2022-01-19 14:18:38 +01:00
Kadir Cetinkaya cae932b6c6
[clangd] Sort targets before printing for tests
Targets are not necessarily inserted in the order they appear in source
code. For example we could traverse overload sets, or selectively insert
template patterns after all other decls.
So order the targets before printing to make sure tests are not dependent on
such implementation details. We can also do it in production, but that might be
wasteful as we haven't seen any complaints in the wild around these orderings
yet.

Differential Revision: https://reviews.llvm.org/D117549
2022-01-19 14:06:53 +01:00
Fabian Wolff f7b7138a62 [clang-tidy] Make `readability-container-data-pointer` more robust
Fixes PR#52245. I've also added a few test cases beyond PR#52245 that would also fail with the current implementation, which is quite brittle in many respects (e.g. it uses the `hasDescendant()` matcher to find the container that is being accessed, which is very easy to trick, as in the example in PR#52245).

I have not been able to reproduce the second issue mentioned in PR#52245 (namely that using the `data()` member function is suggested even for containers that don't have it), but I've added a test case for it to be sure.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D113863
2022-01-18 21:08:59 +01:00
Jan Svoboda c6fb636667 [clangd][clang-tidy] Remove uses of `std::vector<bool>`
LLVM Programmer’s Manual strongly discourages the use of `std::vector<bool>` and suggests `llvm::BitVector` as a possible replacement.

This patch does just that for clangd and clang-tidy.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D117119
2022-01-18 17:59:40 +01:00
Richard e598913a47 [clang-tidy] Force LF newlines when writing files
The recommendation on Windows is to checkout from git with
core.autolf=false in order to preserve LF line endings on
test files.  However, when creating a new check this results
in modified files as having switched all the line endings on
Windows.  Write all files with explicit LF line endings to
prevent this.

Fixes #52968

Differential Revision: https://reviews.llvm.org/D117535
2022-01-18 09:39:42 -07:00
Jan Svoboda 105c913156 [clang][lex] NFC: Simplify calls to `LookupFile`
The `{HeaderSearch,Preprocessor}::LookupFile()` functions take an out-parameter `const DirectoryLookup *&`. Most callers end up creating a `const DirectoryLookup *` variable that's otherwise unused.

This patch changes the out-parameter from reference to a pointer, making it possible to simply pass `nullptr` to the function without the ceremony.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D117312
2022-01-18 16:02:18 +01:00
Haojian Wu fd598e1859 [clangd] Bring back early-claim approach to fix a selection-tree regression.
The early-claim hack was removed in 96f5cc1ee4,
we see a regression about captured var-decl in lambda.

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

Differential Revision: https://reviews.llvm.org/D117472
2022-01-18 10:22:26 +01:00
Kirill Bobyrev 2d9198cec9
[clangd] Remove redundant check for renamed symbol origin
This is a follow-up on D116643. `isInSystemHeader` check already detects
symbols coming from the Standard Library, so searching for the qualified name
in StdSymbolMap.inc is no longer necessary.

The tests filtering out purely based on the symbol qualified names are removed.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D117491
2022-01-18 09:43:53 +01:00
Fabian Wolff 2cd2accc61 [clang-tidy] Fix false positives involving type aliases in `misc-unconventional-assign-operator` check
clang-tidy currently reports false positives even for simple cases such as:
```
struct S {
    using X = S;
    X &operator=(const X&) { return *this; }
};
```
This is due to the fact that the `misc-unconventional-assign-operator` check fails to look at the //canonical// types. This patch fixes this behavior.

Reviewed By: aaron.ballman, mizvekov

Differential Revision: https://reviews.llvm.org/D114197
2022-01-17 21:16:17 +01:00
Fabian Wolff 42bc3275d3 [clang-tidy] Fix `readability-redundant-declaration` false positive for template friend declaration
Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=48086 | PR#48086 ]]. The problem is that the current matcher uses `hasParent()` to detect friend declarations, but for a template friend declaration, the immediate parent of the `FunctionDecl` is a `FunctionTemplateDecl`, not the `FriendDecl`. Therefore, I have replaced the matcher with `hasAncestor()`.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D114299
2022-01-17 20:50:32 +01:00
Sam McCall 4dedd82cc9 Re-land [clangd] Elide even more checks in SelectionTree.
This reverts commit 1093b9f2e9.

Fix added for implicit-include case.
2022-01-17 15:26:28 +01:00
Haojian Wu 192f8d9700 [clangd] Don't rename on symbols from system headers.
Fixes https://github.com/clangd/clangd/issues/963.

Differential Revision: https://reviews.llvm.org/D116643
2022-01-17 15:08:53 +01:00
Nathan James 8b88ff0803
[clangd] Add option to use dirty file contents when building preambles.
Adds a option `use-dirty-preambles` to enable using unsaved in editor contents when building pre-ambles.
This enables a more seamless user experience when switching between header and implementation files and forgetting to save inbetween.
It's also in line with the LSP spec that states open files in the editor should be used instead of on the contents on disk - https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/
For now the option is defaulted to off and hidden, Though I have a feeling it should be moved into the `.clangd` config and possibly defaulted to true.

Addresses https://github.com/clangd/clangd/issues/488

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95046
2022-01-17 10:55:35 +00:00
Haojian Wu ab3f100bec Reland (2) "[AST] Add RParen loc for decltype AutoTypeloc.""
The patch was reverted because it caused a crash during PCH build -- we
missed to update the RParenLoc in TreeTransform<Derived>::TransformAutoType.

This relands 55d96ac and 37ec65e with a test and fix.
2022-01-17 11:33:11 +01:00
Haojian Wu 884832407e [clangd] Avoid a code completion crash
This is a workaround (adding a newline to the eof) in clangd to avoid the code
completion crash, see https://github.com/clangd/clangd/issues/332.

In principle, this is a clang bug, we should fix it in clang, but it is not
trivial.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D117456
2022-01-17 10:35:55 +01:00
Haojian Wu 64c108c9e4 [clangd] Better handling `\n` in the synthesized diagnostic message.
The newline-eof fix was rendered as "insert '...'", this patch
special-case it.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D117294
2022-01-17 09:27:58 +01:00
John Ericson da77db58d7 Revert "[cmake] Use `GNUInstallDirs` to support custom installation dirs."
https://lab.llvm.org/buildbot/#/builders/46/builds/21146 Still have
this odd error, not sure how to reproduce, so I will just try breaking
up my patch.

This reverts commit 4a678f8072.
2022-01-16 05:48:30 +00:00
John Ericson 4a678f8072 [cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-16 05:33:07 +00:00
John Ericson 6e52bfe09d Revert "[cmake] Use `GNUInstallDirs` to support custom installation dirs."
Sorry for the disruption, I will try again later.

This reverts commit efeb501970.
2022-01-15 07:35:02 +00:00
John Ericson efeb501970 [cmake] Use `GNUInstallDirs` to support custom installation dirs.
This is the original patch in my GNUInstallDirs series, now last to merge as the final piece!

It arose as a new draft of D28234. I initially did the unorthodox thing of pushing to that when I wasn't the original author, but since I ended up

 - Using `GNUInstallDirs`, rather than mimicking it, as the original author was hesitant to do but others requested.

 - Converting all the packages, not just LLVM, effecting many more projects than LLVM itself.

I figured it was time to make a new revision.

I have used this patch series (and many back-ports) as the basis of https://github.com/NixOS/nixpkgs/pull/111487 for my distro (NixOS), which was merged last spring (2021). It looked like people were generally on board in D28234, but I make note of this here in case extra motivation is useful.

---

As pointed out in the original issue, a central tension is that LLVM already has some partial support for these sorts of things. Variables like `COMPILER_RT_INSTALL_PATH` have already been dealt with. Variables like `LLVM_LIBDIR_SUFFIX` however, will require further work, so that we may use `CMAKE_INSTALL_LIBDIR`.

These remaining items will be addressed in further patches. What is here is now rote and so we should get it out of the way before dealing more intricately with the remainder.

Reviewed By: #libunwind, #libc, #libc_abi, compnerd

Differential Revision: https://reviews.llvm.org/D99484
2022-01-15 01:08:35 +00:00
Kadir Cetinkaya 1093b9f2e9
Revert "[clangd] Elide even more checks in SelectionTree."
This reverts commit 07f9fb8b51.
2022-01-14 14:32:43 +01:00
Sam McCall 07f9fb8b51 [clangd] Elide even more checks in SelectionTree.
During pop() we convert nodes into spans of expanded syntax::Tokens.
If we precompute a range of plausible (expanded) tokens, then we can do an
extremely cheap approximate hit-test against it, because syntax::Tokens are
ordered by pointer.

This would seem not to buy anything (we don't enter nodes unless they overlap
the selection), but in fact the spans we have are for *newly* claimed ranges
(i.e. those unclaimed by any child node).

So if you have:
   { { [[2+2]]; } }
then all of the CompoundStmts pass the hit test and are pushed, but we skip
full hit-testing of the brackets during pop() as they lie outside the range.

This is ~10x average speedup for selectiontree on a bad case I've seen
(large gtest file).

Differential Revision: https://reviews.llvm.org/D117107
2022-01-13 22:27:51 +01:00
Sam McCall 004acbb47d [clangd] Suppress warning about system_header pragma when editing headers
Not sure it's OK to suppress this in clang itself - if we're building a PCH
or module, maybe it matters?

Differential Revision: https://reviews.llvm.org/D116925
2022-01-13 22:24:05 +01:00
Sam McCall 71a082f726 [clangd] Implement textDocument/typeDefinition
This reuses the type=>decl mapping from go-to-definition on auto.
(Which could stand some improvement, but that can happen later).

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

Differential Revision: https://reviews.llvm.org/D116443
2022-01-13 22:15:10 +01:00
Sam McCall fc7a9f36a9 [clangd] Ignore cvr-qualifiers in selection.
The AST doesn't track their locations, and the default behavior of attributing
them to the lexically-enclosing node is sloppy and often inaccurate.

Also add a couple of passing test cases for declarators that weren't obvious.

Differential Revision: https://reviews.llvm.org/D117185
2022-01-13 15:08:50 +01:00
Sam McCall 2b2dbe6126 [clangd] Selection: Prune gtest TEST()s earlier
When searching for AST nodes that may overlap the selection, mayHit() was only
attempting to prune nodes whose begin/end are both in the main file.

While failing to prune never gives wrong results, it hurts performance.
In GTest unit-tests, `TEST()` macros at the top level declare classes.
These were never pruned and we traversed *every* such class for any selection.

We fix this by reasoning about what tokens such a node might claim.
They must lie within its ultimate macro expansion range, so if this doesn't
overlap with the selection, we can prune the node.

Differential Revision: https://reviews.llvm.org/D116978
2022-01-13 13:58:42 +01:00
Kirill Bobyrev a9bf32763d [clangd] Fix build after D115243
The api for loadIndex changed but was not updated everywhere due to
differences in the build configuration.
2022-01-13 13:44:19 +01:00
Sam McCall 54eb70886c [clangd] Remove --inlay-hints flag
Differential Revision: https://reviews.llvm.org/D117036
2022-01-13 10:02:28 +01:00
Sam McCall 9c9119ab36 [clangd] Extend SymbolOrigin, stop serializing it
New values:
- Split Dynamic into Open/Preamble
- Add Background (previously was just Unknown)
- Soon: stdlib index

This requires extending to 16 bits, which fits within the padding of Symbol.
Unfortunately we're also *serializing* SymbolOrigin as a fixed 8 bits.

Stop serializing SymbolOrigin:
- conceptually, the source is whoever indexes or *deserializes* a symbol
- deserialization takes SymbolOrigin as a parameter and stamps it on each sym
- this is a breaking format change

Differential Revision: https://reviews.llvm.org/D115243
2022-01-13 08:26:12 +01:00
Sam McCall d8716cd7d3 [CodeCompletion] (mostly) fix completion in incomplete C++ ctor initializers.
C++ member function bodies (including ctor initializers) are first captured
into a buffer and then parsed after the class is complete. (This allows
members to be referenced even if declared later).

When the boundary of the function body cannot be established, its buffer is
discarded and late-parsing never happens (it would surely fail).
For code completion this is the wrong tradeoff: the point of the parse is to
generate completions as a side-effect.
Today, when the ctor body wasn't typed yet there are no init list completions.
With this patch we parse such an init-list if it contains the completion point.

There's one caveat: the parser has to decide where to resume parsing members
after a broken init list. Often the first clear recovery point is *after* the
next member, so that member is missing from completion/signature help etc. e.g.
  struct S {
    S() m  //<- completion here
    int maaa;
    int mbbb;
  }
Here "int maaa;" is treated as part of the init list, so "maaa" is not available
as a completion. Maybe in future indentation can be used to recognize that
this is a separate member, not part of the init list.

Differential Revision: https://reviews.llvm.org/D116294
2022-01-13 08:06:35 +01:00
CJ Johnson 81c330e23d Filter string_view from the nullptr diagnosis of bugprone-string-constructor to prevent duplicate warnings with bugprone-stringview-nullptr
Updates the check and tests to not diagnose the null case for string_view (but retains it for string). This prevents the check from giving duplicate warnings that are caught by bugprone-stringview-nullptr ([[ https://reviews.llvm.org/D113148 | D113148 ]]).

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D114823
2022-01-12 17:04:44 -05:00
CJ Johnson 7e29da875c Add support for return values in bugprone-stringview-nullptr
bugprone-stringview-nullptr was not initially written with tests for return statements. After landing the check, the thought crossed my mind to add such tests. After writing them, I realized they needed additional handling in the matchers.

Differential Revision: https://reviews.llvm.org/D115121
2022-01-12 16:53:13 -05:00
Richard fff59f4817 [clang-tidy] Improve modernize-redundant-void-arg to recognize macro uses
Sometimes a macro invocation will look like an argument list
declaration.  Improve the check to detect this situation and not
try to modify the macro invocation.

Thanks to Nathan James for the fix.

- Ignore implicit typedefs (e.g. compiler builtins)
- Improve lexing state machine to locate void argument tokens
- Add additional return_t() macro tests
- clang-format control in the test case file
- remove braces around single statements per LLVM style guide

Fixes #43791

Differential Revision: https://reviews.llvm.org/D116425
2022-01-12 13:51:50 -07:00
Simon Pilgrim dcc20143e1 [clang-tidy] UseDefaultMemberInitCheck::checkDefaultInit - Use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is always dereferenced immediately below, so assert the cast is correct instead of returning nullptr
2022-01-12 15:35:37 +00:00
Kadir Cetinkaya c490f8feb7
[clangd][StdSymbolMap] Prefer std::remove from algorithm
std::remove from algorithm is a lot more common than the overload from
the cstdio (which deletes files). This patch introduces a set of symbols
for which we should prefer the overloaded versions.

Differential Revision: https://reviews.llvm.org/D114724
2022-01-12 15:25:42 +01:00
serge-sans-paille 35cca45b09 Misleading bidirectional detection
This patch implements detection of incomplete bidirectional sequence withing
comments and string literals within clang-tidy.

It detects the bidi part of https://www.trojansource.codes/trojan-source.pdf

Differential Revision: https://reviews.llvm.org/D112913
2022-01-12 11:38:36 +01:00
Florian Hahn eadb4cfeef
Revert (2) "[AST] Add RParen loc for decltype AutoTypeloc."
This reverts commit 41fbdfa4d5.

The commit breaks stage 2 builds with debug info, e.g.
https://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/5088/console

Clang crashes with the following assertion when building
llvm-project/llvm/lib/Support/Timer.cpp

/usr/local/bin/sccache /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/host-compiler/bin/clang++  -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support -Iinclude -I/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/include -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -fmodules -fmodules-cache-path=/Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/clang-build/Build/module.cache -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -flto=thin  -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk   -std=c++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o -c /Users/buildslave/jenkins/workspace/clang-stage2-Rthinlto/llvm-project/llvm/lib/Support/Timer.cpp
Assertion failed: (((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow"), function getLocWithOffset, file /Users/buildslave/jenkins/workspace/clang-stage1-RA/llvm-project/clang/include/clang/Basic/SourceLocation.h, line 135.
2022-01-12 10:09:37 +00:00
Carlos Galvez c4db521cea [clang] Introduce support for disabling warnings in system macros
Often we run into situations where we want to ignore
warnings from system headers, but Clang will still
give warnings about the contents of a macro defined
in a system header used in user-code.

Introduce a ShowInSystemMacro option to be able to
specify which warnings we do want to keep raising
warnings for. The current behavior is kept in this patch
(i.e. warnings from system macros are enabled by default).
The decision as to whether this should be an opt-in or opt-out
feature can be made in a separate patch.

To put the feature to test, replace duplicated code for
Wshadow and Wold-style-cast with the SuppressInSystemMacro tag.
Also disable the warning for C++20 designators, fixing #52944.

Differential Revision: https://reviews.llvm.org/D116833
2022-01-12 08:18:19 +00:00
Elvis Stansvik 36af073342 Accept string literal decay in conditional operator
The cppcoreguidelines-pro-bounds-array-to-pointer-decay check currently
accepts:

const char *b = i ? "foo" : "foobar";

but not

const char *a = i ? "foo" : "bar";

This is because the AST is slightly different in the latter case (see
https://godbolt.org/z/MkHVvs).

This eliminates the inconsistency by making it accept the latter form
as well.

Fixes https://github.com/llvm/llvm-project/issues/31155.
2022-01-11 15:05:30 -05:00
Haojian Wu 41fbdfa4d5 Reland "[AST] Add RParen loc for decltype AutoTypeloc."
Reland 55d96ac and 37ec65e with a clang-tidy fix.
2022-01-11 12:06:18 +01:00
Sam McCall 1e9b837585 [clangd] Save more getFileID in Selection
This saves about 10% of SelectionVisitor::pop().
2022-01-11 11:01:54 +01:00
Sam McCall 22ac067b2d [clangd] Small optimization in SelectionTree
This seems to be strictly faster in all cases. Before fixing D116978 it
was one of the hot paths, and may become one again.
2022-01-11 10:18:44 +01:00
Sam McCall 4258d68dc7 [Tooling] When transferring compile commands between files, always use '--'
"driver <flags> -- <input>" is a particularly convenient form of the
compile command to manipulate, with fewer special cases to handle.

Guaranteeing that the output command is of that form is cheap and makes
it easier to consume the result in some cases.

Differential Revision: https://reviews.llvm.org/D116721
2022-01-11 01:41:42 +01:00
Richard a2c33b0ec9 [clang-tidy] Refactor: Extract Class CheckRunner on check_clang_tidy.py
Break up the huge function by extracting a class, storing intermediate
state as class members and breaking up the big function into a group
of class methods all at the same level of abstraction.

Differential Revision: https://reviews.llvm.org/D56343
2022-01-10 15:44:12 -07:00
Logan Smith 988c3f5f96 [clang-tidy] Fix RenamerClangTidyChecks suggesting invalid macro identifiers
This behavior was fixed for regular identifiers in
9f3edc323a, but the same fix was not applied to
macro fixits. This addresses https://github.com/llvm/llvm-project/issues/52895.

Differential Revision: https://reviews.llvm.org/D116824
2022-01-10 10:35:04 -08:00
Nico Weber cf90b3cf7e Revert "[clangd] Enable expand-auto for decltype(auto)."
This reverts commit 37ec65e1d7.

Its prerequisite 55d96ac3dc wsa
reverted in c2293bc17d. c2293bc's
patch description claimed that it reverted 37ec65 as well,
but it apparently didn't.

See https://reviews.llvm.org/D116921#3231802
2022-01-10 12:01:42 -05:00
Haojian Wu c2293bc17d Revert "[AST] Add RParen loc for decltype AutoTypeloc."
This breaks a clang-tidy check, needs to investigate and fix. Revert
them to bring the buildbot back.

This reverts commit 55d96ac3dc and
37ec65e1d7
2022-01-10 15:18:41 +01:00
Haojian Wu 37ec65e1d7 [clangd] Enable expand-auto for decltype(auto).
Based on https://reviews.llvm.org/D116919.

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

Differential Revision: https://reviews.llvm.org/D116921
2022-01-10 13:46:56 +01:00
Haojian Wu 55d96ac3dc [AST] Add RParen loc for decltype AutoTypeloc.
Differential Revision: https://reviews.llvm.org/D116919
2022-01-10 12:46:27 +01:00
Sam McCall 1ab13793be [clangd] Include fixer for missing functions in C
A function call `unresolved()` in C will generate an implicit declaration
of the missing function and warn `ext_implicit_function_decl` or so.
(Compared to in C++ where we get `err_undeclared_var_use`).
We want to try to resolve these names.

Unfortunately typo correction is disabled in sema for performance
reasons unless this warning is promoted to error.
(We need typo correction for include-fixer.)
It's not clear to me where a switch to force this correction on should
go, include-fixer is kind of a hack. So hack more by telling sema we're
promoting them to error.

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

Differential Revision: https://reviews.llvm.org/D115490
2022-01-10 12:17:19 +01:00
Sam McCall 16fd5c2784 [clangd] Support configuration of inlay hints.
The idea is that the feature will always be advertised at the LSP level, but
depending on config we'll return partial or no responses.

We try to avoid doing the analysis for hints we're not going to return.

Examples of syntax:
```
InlayHints:
  Enabled: No
---
InlayHints:
  ParameterNames: No
---
InlayHints:
  ParameterNames: Yes
  DeducedTypes: Yes
```

Differential Revision: https://reviews.llvm.org/D116713
2022-01-10 10:49:35 +01:00
Haojian Wu 4a4b8e4f99 [AST] Add more source information for DecltypeTypeLoc.
Adds the paren source location, and removes the hack in clangd.

Differential Revision: https://reviews.llvm.org/D116793
2022-01-10 09:34:18 +01:00
Kazu Hirata 8afcfbfb8f Use true/false instead of 1/0 (NFC)
Identified by modernize-use-bool-literals.
2022-01-09 12:21:06 -08:00
Kazu Hirata b12fd13812 Fix bugprone argument comments.
Identified by bugprone-argument-comment.
2022-01-09 12:21:02 -08:00
Vitaly Buka 244dd2913a Don't pass uninitialized QueryKind
Even if findImplementors does not use
uninitialized parameter it's still UB and
it's going to be detected by msan with:
-Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1

Differential Revision: https://reviews.llvm.org/D116827
2022-01-07 17:14:08 -08:00
Vitaly Buka 669eb60046 Initialize HighlightingsBuilder::Resolver
Detected by msan with:
-Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1

Differential Revision: https://reviews.llvm.org/D116828
2022-01-07 15:21:22 -08:00
Kazu Hirata e56a9c9b5b Remove redundant return statements (NFC)
Identified by readability-redundant-control-flow.
2022-01-07 07:42:35 -08:00
Sam McCall 7c19fdd599 [clangd] Polish clangd/inlayHints and expose them by default.
This means it's a "real feature" in clangd 14, albeit one that requires special
client support.

- remove "preview" from the flag description
- expose the `clangdInlayHints` capability by default
- provide `position` as well as `range`
- support `InlayHintsParams.range` to restrict the range retrieved
- inlay hint list is in document order (sorted by position)

Still to come: control feature via config rather than flag.

Fixes https://github.com/clangd/clangd/issues/313
Protocol doc is in https://github.com/llvm/clangd-www/pull/56/files

Differential Revision: https://reviews.llvm.org/D116699
2022-01-07 15:12:43 +01:00
Qiu Chaofan c2cc70e4f5 [NFC] Fix endif comments to match with include guard 2022-01-07 15:52:59 +08:00
Carlos Galvez 670de10f9d Disable clang-tidy warnings from system macros
Currently, it's inconsistent that warnings are disabled if they
come from system headers, unless they come from macros.
Typically a user cannot act upon these warnings coming from
system macros, so clang-tidy should ignore them unless the
user specifically requests warnings from system headers
via the corresponding configuration.

This change broke the ProTypeVarargCheck check, because it
was checking for the usage of va_arg indirectly, expanding it
(it's a system macro) to detect the usage of __builtin_va_arg.
The check has been fixed by checking directly what the rule
is about: "do not use va_arg", by adding a PP callback that
checks if any macro with name "va_arg" is expanded. The old
AST matcher is still kept for compatibility with Windows.

Add unit test that ensures warnings from macros are disabled
when not using the -system-headers flag. Document the change
in the Release Notes.

Differential Revision: https://reviews.llvm.org/D116378
2022-01-06 20:27:28 +00:00
Chuanqi Xu bbce75e352 Update Bug report URL to Github Issues
Although we moved to Github Issues. The bug report message refers to
Bugzilla still. This patch tries to update these URLs.

Reviewed By: MaskRay, Quuxplusone, jhenderson, libunwind, libc++

Differential Revision: https://reviews.llvm.org/D116351
2022-01-06 17:33:25 +08:00
Richard d7b6574c3b [clang-tidy] Recognize transformer checks as providing fixits
- Recognize older checks that might not end with Check.cpp
- Update list of checks based on improvements to add_new_check
- Fix spelling error in TransformerClangTidyCheck.h

Fixes #52962

Differential Revision: https://reviews.llvm.org/D116550
2022-01-05 16:13:52 -07:00
Nico Weber 085f078307 Revert "Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`.""
This reverts commit 859ebca744.
The change contained many unrelated changes and e.g. restored
unit test failes for the old lld port.
2022-01-05 13:10:25 -05:00
David Salinas 859ebca744 Revert D109159 "[amdgpu] Enable selection of `s_cselect_b64`."
This reverts commit 640beb38e7.

That commit caused performance degradtion in Quicksilver test QS:sGPU and a functional test failure in (rocPRIM rocprim.device_segmented_radix_sort).
Reverting until we have a better solution to s_cselect_b64 codegen cleanup

Change-Id: Ibf8e397df94001f248fba609f072088a46abae08

Reviewed By: kzhuravl

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

Change-Id: Id169459ce4dfffa857d5645a0af50b0063ce1105
2022-01-05 17:57:32 +00:00
Sam McCall 055d8090d1 [clangd] Don't index __reserved_names in headers.
Main use of these is in the standard library, where they generally clutter up
the index.

Certain macros are also common, we don't touch indexing of macros in this patch.

Differential Revision: https://reviews.llvm.org/D115301
2022-01-05 16:34:04 +01:00
Sam McCall bb10e03fba
[clangd] Refine comment on declarator ranges 2022-01-05 16:00:13 +01:00
Haojian Wu 7632d19ada [clangd] Fix typos in the SelectionTree comment. 2022-01-05 15:50:07 +01:00
Sam McCall 96f5cc1ee4 [clangd] Handle declarators more consistently in Selection.
Because declarators nest inside-out, we logically need to claim tokens for
parent declarators logically before child ones.
This is the ultimate reason we had problems with DeclaratorDecl, ArrayType etc.

However actually changing the order of traversal is hard, especially for nodes
that have both declarator and non-declarator children.
Since there's only a few TypeLocs corresponding to declarators, we just
have them claim the exact tokens rather than rely on nesting.

This fixes handling of complex declarators, like
`int (*Fun(OuterT^ype))(InnerType);`.

This avoids the need for the DeclaratorDecl early-claim hack, which is
removed.
Unfortunately the DeclaratorDecl early-claims were covering up an AST
anomaly around CXXConstructExpr, so we need to fix that up too.

Based on D116623 and D116618

Differential Revision: https://reviews.llvm.org/D116630
2022-01-05 15:40:47 +01:00
Clement Courbet ed8ff29aa6 [clang-tidy] Fix false positive in modernize-pass-by-value
The check should not trigger on lvalue/rvalue overload pairs:

```
struct S {
  S(const A& a) : a(a) {}
  S(A&& a) : a(std::move(a)) {}

  A a;
}
```

Differential Revision: https://reviews.llvm.org/D116535
2022-01-05 14:33:40 +01:00
Sam McCall 0683a1e588 [clangd] Adjust compile flags so they work when applied to other file(type)s.
It's reasonable to want to use the command from one file to compile another.
In particular, the command from a translation unit to parse a related header:
  {"file": "foo.h", "command": "clang foo.cpp"}

This is largely what InterpolatingCompilationDatabase tries to do.
To do this correctly can require nontrivial changes to the argv, because the
file extension affects semantics.  e.g. here we must add "-x c++header".

When external tools compile commands for different files, we should apply the
same adjustments. This is better than telling people to "fix their tools":
 - simple e.g. python scripts shouldn't have to interpret clang argv
 - this is a good way to represent the intent "parse header X in the context of
   file Y", which can work even if X is not self-contained. clangd does not
   support this today, but some other tools do, and we may one day.

This issue is discussed in https://github.com/clangd/clangd/issues/519

Differential Revision: https://reviews.llvm.org/D116167
2022-01-04 16:10:27 +01:00
Sam McCall 229c95ab66 [CodeCompletion] Signature help for aggregate initialization.
The "parameter list" is the list of fields which should be initialized.
We introduce a new OverloadCandidate kind for this.
It starts to become harder for CC consumers to handle all the cases for
params, so I added some extra APIs on OverloadCandidate to abstract them.

Includes some basic support for designated initializers.
The same aggregate signature is shown, the current arg jumps after the
one you just initialized. This follows C99 semantics for mixed
designated/positional initializers (which clang supports in C++ as an extension)
and is also a useful prompt for C++ as C++ designated initializers must be
in order.

Related bugs:
 - https://github.com/clangd/clangd/issues/965
 - https://github.com/clangd/clangd/issues/306

Differential Revision: https://reviews.llvm.org/D116326
2022-01-04 16:00:22 +01:00
Oleg Smolsky 051847cfec Improve the 'modernize-use-default-member-init'
We want to deal with non-default constructors that just happen to
contain constant initializers. There was already a negative test case,
it is now a positive one. We find and refactor this case:

struct PositiveNotDefaultInt {
  PositiveNotDefaultInt(int) : i(7) {}
  int i;
};
2022-01-04 07:27:02 -05:00
Haojian Wu cb9ccd38c5 [clangd] Move the selection decltype hack to getSourceRange.
Previously, it was in canSafelySkipNode, which is only used to decide
whether we should descend into it and its children, and we still used
the incomplete Decltypeloc.getSourceRange() to claim tokens, which will
cause some tokens were not claimed correctly.

Separate a change of https://reviews.llvm.org/D116536

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D116586
2022-01-04 12:11:58 +01:00