aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra
AgeCommit message (Collapse)AuthorFilesLines
2022-02-07[clang-tidy] Fix LLVM include order check policyKadir Cetinkaya3-17/+56
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 (cherry picked from commit 0447ec2fb050eb37ed1f5991a1562dea6e228f9e)
2022-02-01[docs] Remove hard-coded version numbers from sphinx configsTom Stellard2-17/+14
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-01Reland "enable plugins for clang-tidy"Jameson Nash9-2/+142
This reverts commit ab3b89855c5318f0009e1f016ffe5b1483507fd0 but disables the new test if the user has disabled support for building it.
2022-02-01[clangd] Fix handling of co_await in go-to-typeSam McCall1-3/+1
2022-02-01[clangd] Group and extend release notesSam McCall1-51/+104
2022-02-01[clangd] Cleanup of readability-identifier-namingChristian Kühnel39-1586/+1591
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-01-31Tweak formatting & wording in clangd release notesSam McCall1-25/+27
2022-01-31[clang-tidy] getLambdaProperties - use cast<> instead of dyn_cast<> to avoid ↵Simon Pilgrim1-4/+3
dereference of nullptr The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-31[cte] Add release notes for clangd-14Kadir Cetinkaya1-1/+77
Differential Revision: https://reviews.llvm.org/D118592
2022-01-31[clang-tidy] Make header compile standalone. NFC.Benjamin Kramer1-0/+1
2022-01-31[clang-tidy] bugprone-signal-handler improvements: display call chainBalázs Kéri3-51/+163
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-31Revert "enable plugins for clang-tidy"Petr Hosek9-139/+2
This reverts commit 36892727e4f19a60778e371d78f8fb09d8122c85 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-30[clang-tools-extra] Remove unused forward declarations (NFC)Kazu Hirata7-17/+0
2022-01-29[clang-tidy] Organize the release notes a little betterRichard1-43/+59
- 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-29enable plugins for clang-tidyJameson Nash9-2/+139
Fixes #32739 Differential Revision: https://reviews.llvm.org/D111100
2022-01-29Add 'clangd' prefix to remote index proto targetsSam McCall5-22/+21
Some pieces of build infrastructure (shlib, debian package) classify targets based on whether they begin with "clang".
2022-01-28[clang-tidy] Recognize labelled statements when simplifying boolean exprsRichard7-145/+1205
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-27[clangd] Fix a typo , => ; in hovertest.Haojian Wu1-1/+2
I somehow missed it.
2022-01-27[clangd] Enable hover on character literal.Haojian Wu2-2/+6
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[clangd] Fix a selection tree crash for unmatched-bracket code.Haojian Wu2-0/+12
Fixes https://github.com/clangd/clangd/issues/999 Differential Revision: https://reviews.llvm.org/D118322
2022-01-27[clang-tidy] Add more documentation about check development (NFC)Richard1-3/+222
- 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-27Don't trigger unused-parameter warnings on naked functionsMuAlphaOmegaEpsilon4-4/+15
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[clangd][Hover] Suppress initializers with many tokensKadir Cetinkaya2-4/+29
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-26[clang-tidy] Fix nested namespaces in ↵Evgeny Shulgin3-2/+24
`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[CodeCompletion][clangd] Clean __uglified parameter names in completion & hoverSam McCall1-3/+4
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-27Rewrite Doxygen comment to resolve -Wdocumentation warning (NFC)Salman Javed1-2/+2
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-27Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build botSalman Javed25-334/+752
2022-01-27Revert "[clang-tidy] Cache the locations of NOLINTBEGIN/END blocks"Salman Javed25-752/+334
Build warning here: https://lab.llvm.org/buildbot/#/builders/57/builds/14322
2022-01-27[clang-tidy] Cache the locations of NOLINTBEGIN/END blocksSalman Javed25-334/+752
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-25Refactor: Extract Class MessagePrefix (NFC)Richard1-29/+35
The work is the same, the only difference is the prefix of the strings we look for in the reference files.
2022-01-26[clangd] Add designator inlay hints for initializer lists.Sam McCall8-14/+312
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-25[clang-tidy] [bugprone-assert-side-effect] Ignore list for functions/methodsZinovy Nis5-9/+54
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[clang-tidy] Change code of SignalHandlerCheck (NFC).Balázs Kéri3-65/+98
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[clang-tidy] Pop Files only if FileChangeReason is ExitFileJim Lin1-1/+1
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[NFC][clangd] cleaning up llvm-qualified-autoChristian Kühnel19-60/+60
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-24[clang-tools-extra] Fix documentation build (NFC)Richard1-1/+1
2022-01-24[NFC][clangd] Use table to collect option aliasesYuanfang Chen1-2/+15
* 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-24Add missing include llvm/ADT/STLExtrasserge-sans-paille1-0/+1
2022-01-24[clang-tidy] Add `readability-container-contains` checkAdrian Vogelsgesang8-0/+450
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-23[clang] Forward-declare DynTypedNode (NFC)Kazu Hirata1-0/+1
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[clang-tidy] Add readability-duplicate-include checkRichard14-0/+288
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[clang-tidy] Remove gsl::at suggestion from ↵Carlos Galvez5-8/+15
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[clangd] Use castAs<> instead of getAs<> to avoid dereference of nullptrSimon Pilgrim2-4/+3
The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-23[clang-tidy] Use cast<>/castAs<> instead of dyn_cast<>/getAs<> to avoid ↵Simon Pilgrim2-3/+3
dereference of nullptr The pointer is dereferenced immediately, so assert the cast is correct instead of returning nullptr
2022-01-22[clang-tools-extra][cmake] Use `GNUInstallDirs` to support custom ↵John Ericson7-9/+10
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-21[clang-tidy] Avoid binding nullptr to a referenceBenjamin Kramer1-3/+3
That's undefined behavior. Found by -fsanitize=null.
2022-01-21[llvm][ADT] Implement `BitVector::{pop_,}back`Jan Svoboda2-2/+4
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[clangd] Fail inlayHints requests on content changesKadir Cetinkaya1-1/+1
This should improve the overall UX by making the labels less jumpy. Differential Revision: https://reviews.llvm.org/D117776
2022-01-21[clangd][Background] Make index validation logs verboseKadir Cetinkaya1-1/+1
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[clang-tidy] Fix wrong FixIt in performance-move-const-argSockke4-13/+205
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