aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra
AgeCommit message (Collapse)AuthorFilesLines
2024-03-11Fixing test from 8467457afc61d70e881c9817ace26356ef757733Aaron Ballman1-1/+1
The clangd test was testing the previous diagnostic logic and now it's testing with the new warning flag.
2024-03-11[clangd] Fix JSON conversion for symbol tags (#84747)Christian Kandeler1-1/+1
The wrong constructor of json::Value got called, making every tag an array instead of a number.
2024-03-11[clangd] Avoid libFormat's objective-c guessing heuristic where possible ↵Nathan Ridge8-12/+68
(#84133) This avoids a known libFormat bug where the heuristic can OOM on certain large files (particularly single-header libraries such as miniaudio.h). The OOM will still happen on affected files if you actually try to format them (this is harder to avoid since the underlyting issue affects the actual formatting logic, not just the language-guessing heuristic), but at least it's avoided during non-modifying operations like hover, and modifying operations that do local formatting like code completion. Fixes https://github.com/clangd/clangd/issues/719 Fixes https://github.com/clangd/clangd/issues/1384 Fixes https://github.com/llvm/llvm-project/issues/70945
2024-03-09[clang-tidy]avoid bugprone-unused-return-value false positive for assignment ↵Congcong Cai4-12/+57
operator overloading (#84489)
2024-03-08[llvm][Support] Add and use errnoAsErrorCode (#84423)Michael Spencer1-2/+1
LLVM is inconsistent about how it converts `errno` to `std::error_code`. This can cause problems because values outside of `std::errc` compare differently if one is system and one is generic on POSIX systems. This is even more of a problem on Windows where use of the system category is just wrong, as that is for Windows errors, which have a completely different mapping than POSIX/generic errors. This patch fixes one instance of this mistake in `JSONTransport.cpp`. This patch adds `errnoAsErrorCode()` which makes it so people do not need to think about this issue in the future. It also cleans up a lot of usage of `errno` in LLVM and Clang.
2024-03-08[clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (#84236)Piotr Zegar5-13/+766
Fix handling of Hungarian Prefix when configured to LowerCase. Warnings no longer will be emited for names that already match this style. Fixes: #80268
2024-03-08[clang-tidy]avoid bugprone-unused-return-value false positive for function ↵Congcong Cai4-109/+126
with the same prefix as the default argument (#84333)
2024-03-07[clang-tidy] `isOnlyUsedAsConst`: Handle static method calls. (#84005)Clement Courbet2-4/+14
... using method syntax: ``` struct S { static void f() }; void DoIt(S& s) { s.f(); // Does not mutate `s` through the `this` parameter. } ```
2024-03-07[clang-tidy] bugprone-assert-side-effect can detect side effect from ↵Congcong Cai3-5/+43
non-const reference parameters (#84095) Fixes: #84092
2024-03-05[clangd] Show argument names for function pointer struct fields (#69011)Qwinci1-0/+17
Show argument names in signature help when calling a function pointer struct field.
2024-03-05[clangd] Remove calls to getFileLoc() in declToSym() (#83532)Nathan Ridge2-3/+10
toHalfOpenFileRange() already handles translating macro locations to file locations, and it can provide a better result by knowing about both ends of the range. Fixes https://github.com/clangd/clangd/issues/1941
2024-03-05[clangd] Make all calls to format::getStyle() go through ↵Nathan Ridge5-27/+19
getFormatStyleForFile() (#82948)
2024-03-05Rename llvm::ThreadPool -> llvm::DefaultThreadPool (NFC) (#83702)Mehdi Amini2-2/+2
The base class llvm::ThreadPoolInterface will be renamed llvm::ThreadPool in a subsequent commit. This is a breaking change: clients who use to create a ThreadPool must now create a DefaultThreadPool instead.
2024-03-06[clang-tidy] fix false negative in cppcoreguidelines-missing-std-forward ↵Qizhi Hu3-5/+18
(#83987) Try to fix https://github.com/llvm/llvm-project/issues/83845 When `std::forward` is invoked in a function, make sure it uses correct parameter by checking if the bounded `var` equals the parameter. Co-authored-by: huqizhi <836744285@qq.com>
2024-03-05[clangd] Add metric for rename decl kind (#83867)David Goldman1-0/+4
This will give us insight into what users are renaming in practice - for instance, try to gauge the impact of the ObjC rename support.
2024-03-05[clang-tidy] CRTP Constructor Accessibility Check (#82403)isuckatcs8-0/+577
Detects error-prone Curiously Recurring Template Pattern usage, when the CRTP can be constructed outside itself and the derived class.
2024-03-04[clang-tidy] Let `bugprone-use-after-move` also handle calls to ↵AMS214-15/+95
`std::forward` (#82673) Add support for std::forward. Fixes #82023
2024-03-04[clang-tidy] bugprone-unused-return-value config now supports regexes (#82952)Félix-Antoine Constantin6-110/+117
The parameter `CheckedFunctions` now supports regexes Fixes #63107
2024-03-04[clangd] [HeuristicResolver] Protect against infinite recursion on ↵Nathan Ridge3-69/+165
DependentNameTypes (#83542) When resolving names inside templates that implement recursive compile-time functions (e.g. waldo<N>::type is defined in terms of waldo<N-1>::type), HeuristicResolver could get into an infinite recursion, specifically one where resolveDependentNameType() can be called recursively with the same DependentNameType*. To guard against this, HeuristicResolver tracks, for each external call into a HeuristicResolver function, the set of DependentNameTypes that it has seen, and bails if it sees the same DependentNameType again. To implement this, a helper class HeuristicResolverImpl is introduced to store state that persists for the duration of an external call into HeuristicResolver (but does not persist between such calls). Fixes https://github.com/clangd/clangd/issues/1951
2024-03-03[clang-tidy] Improve `google-explicit-constructor` checks handling of ↵AMS213-8/+88
`explicit(bool)` (#82689) We now treat `explicit(false)` the same way we treat `noexcept(false)` in the noexcept checks, which is ignoring it. Also introduced a new warning message if a constructor has an `explicit` declaration which evaluates to false and no longer emit a faulty FixIt. Fixes #81121
2024-02-29[clang-tidy][NFC] Fix buffer overflow in modernize-use-designated-initializersPiotr Zegar1-1/+1
Instance of DenseMap were copied into local variable, and as a result reference to string stored in that local variable were returned from function. At the end fix-it were applied with already destroyed string causing some non utf-8 characters to be printed. Related to #80541
2024-02-29[clang-tidy] Add new check `modernize-use-designated-initializers` (#80541)Danny Mösch15-166/+745
2024-02-29[include-cleaner] Generate references from explicit functiontemplate ↵kadir çetinkaya2-6/+9
specializations (#83392)
2024-02-27[clang-tidy] Fix `cppcoreguidelines-missing-std-forward` false positive for ↵AMS213-1/+21
deleted functions (#83055) Improved check by no longer giving false positives for deleted functions.
2024-02-26[clang-tidy] Add support for determining constness of more expressions. (#82617)Clement Courbet6-183/+394
This uses a more systematic approach for determining whcich `DeclRefExpr`s mutate the underlying object: Instead of using a few matchers, we walk up the AST until we find a parent that we can prove cannot change the underlying object. This allows us to handle most address taking and dereference, bindings to value and const& variables, and track constness of pointee (see changes in DeclRefExprUtilsTest.cpp). This allows supporting more patterns in `performance-unnecessary-copy-initialization`. Those two patterns are relatively common: ``` const auto e = (*vector_ptr)[i] ``` and ``` const auto e = vector_ptr->at(i); ``` In our codebase, we have around 25% additional findings from `performance-unnecessary-copy-initialization` with this change. I did not see any additional false positives.
2024-02-25[run-clang-tidy.py] Add option to ignore source files from compilation ↵Alexander Scholz2-0/+24
database (#82416) I added the option -source-filter to the `run-clang-tidy.py` script in the clang-tools-extra. This option allows for handing over a regex, to filter out source files from the compilation database (not run `clang-tidy` on them).
2024-02-23[clangd] Fix renaming single argument ObjC methods (#82396)David Goldman2-5/+152
Use the legacy non-ObjC rename logic when dealing with selectors that have zero or one arguments. In addition, make sure we don't add an extra `:` during the rename. Add a few more tests to verify this works (thanks to @ahoppen for the tests and finding this bug).
2024-02-23[include-cleaner] Use FoundDecl only for using-shadow-decls (#82615)kadir çetinkaya2-15/+24
2024-02-23[clangd] Make tidy-rename tests conditionalKadir Cetinkaya1-1/+7
2024-02-23Reland "[clang] Preserve found-decl when constructing VarTemplateIds" (#82612)kadir çetinkaya1-8/+8
Update include-cleaner tests. Now that we have proper found-decls set up for VarTemplates, in case of instationtations we point to primary templates and not specializations. To be changed in a follow-up patch.
2024-02-20[clangd] forward clang-tidy's readability-identifier-naming fix to ↵Tom Praschan10-9/+182
textDocument/rename (#78454) Co-authored-by: Nathan Ridge <zeratul976@hotmail.com>
2024-02-19[clangd] Do not offer extraction to variable for decl init expression (#69477)Christian Kandeler2-16/+55
That would turn: int x = f() + 1; into: auto placeholder = f() + 1; int x = placeholder; which makes little sense and is clearly not intended, as stated explicitly by a comment in eligibleForExtraction(). It appears that the declaration case was simply forgotten (the assignment case was already implemented).
2024-02-19[clang-tidy][readability-identifier-naming] Resolve symlinks for checking ↵Dmitry Polukhin5-2/+32
style for file (#81985) Summary: Some build systems create symlinks in a temporary build directory for headers in the source tree for isolation purposes. These symlinks prevent `readability-identifier-naming` detecting issues and applying fixes. Without this fix clang-tidy is checking .clang-tidy config file in a temporary directory instead of source source location. Test Plan: check-clang-tools
2024-02-18[clang-tidy] Keep parentheses when replacing index access in `sizeof` calls ↵Danny Mösch3-3/+25
(#82166) Fixes #56021.
2024-02-18[clang-tidy] Fixes to readability-implicit-bool-conversion (#72050)Piotr Zegar3-4/+31
- Fixed issue with invalid code being generated when static_cast is put into fix, and no space were added before it. - Fixed issue with duplicate parentheses being added when double implicit cast is used. Closes #71848
2024-02-17[clang-tidy] Fix handling of parentheses in ↵Piotr Zegar3-1/+8
bugprone-non-zero-enum-to-bool-conversion (#81890) Properly ignore parentheses in bitwise operators. Closes #81515
2024-02-16[clang-tidy] fix incorrect hint for InitListExpr in ↵Congcong Cai3-1/+30
prefer-member-initializer (#81560)
2024-02-15Add support for renaming objc methods, even those with multiple selector ↵David Goldman10-86/+692
pieces (#76466) This adds support for renaming Objective-C methods, which are unique since their method names can be split across multiple tokens.
2024-02-15[clangd][test] Fix -Wmissing-field-initializers in DiagnosticsTests.cpp (NFC)Jie Fu1-2/+4
llvm-project/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:921:45: error: missing field 'Annotations' initializer [-Werror,-Wmissing-field-initializers] TextEdit{Main.range("virtual1"), ""}}}; ^ llvm-project/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp:926:45: error: missing field 'Annotations' initializer [-Werror,-Wmissing-field-initializers] TextEdit{Main.range("virtual2"), ""}}}; ^ 2 errors generated.
2024-02-14[clangd] Clean formatting modernize-use-override (#81435)Kevin Joseph4-3/+58
When applying the recommended fix for the "modernize-use-override" clang-tidy diagnostic there was a stray whitespace. This PR fixes that. Resolves https://github.com/clangd/clangd/issues/1704
2024-02-14[clang-tidy] Removed redundant-inline-specifier warning on static data ↵Félix-Antoine Constantin3-3/+25
members (#81423) Updated the check to ignore point static data members with in class initializer since removing the inline specifier would generate a compilation error Fixes #80684
2024-02-13[clang-tidy] ignore local variable with [maybe_unused] attribute in ↵Congcong Cai4-0/+7
bugprone-unused-local-non-trivial-variable (#81563)
2024-02-11[NFC] Correct C++ standard names (#81421)Danny Mösch5-5/+5
2024-02-09[clang-tidy][NFC] Fixes in release notes and documentationPiotr Zegar2-9/+9
Minor fixes in documentation & release notes.
2024-02-09[Clang-tidy] bugprone-too-small-loop-variable - false-negative when const ↵Shourya Goel4-4/+28
variable is used as loop bound (#81183) Changed LibASTMatcher to give an appropriate warning when a const loop bound is initialized with a function declaration. Fixes: #79580
2024-02-08[clang-tidy] Fix failing test after #80864 (#81171)Krystian Stasiowski1-1/+2
The following test case in `clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp` is failing: ``` #ifdef PR64602 // Should not crash template <class T = void> struct S { auto foo(auto); }; template <> auto S<>::foo(auto) { return 1; } // CHECK8: error: template parameter list matching the non-templated nested type 'S<>' should be empty ('template<>') [clang-diagnostic-error] #endif ``` #80864 fixes a bug where we would (incorrectly) append invented template parameters to empty template parameter lists, which causes this test to fail.
2024-02-08[clang][lex] Always pass suggested module to `InclusionDirective()` callback ↵Jan Svoboda24-53/+75
(#81061) This patch provides more information to the `PPCallbacks::InclusionDirective()` hook. We now always pass the suggested module, regardless of whether it was actually imported or not. The extra `bool ModuleImported` parameter then denotes whether the header `#include` will be automatically translated into import the the module. The main change is in `clang/lib/Lex/PPDirectives.cpp`, where we take care to not modify `SuggestedModule` after it's been populated by `LookupHeaderIncludeOrImport()`. We now exclusively use the `SM` (`ModuleToImport`) variable instead, which has been equivalent to `SuggestedModule` until now. This allows us to use the original non-modified `SuggestedModule` for the callback itself. (This patch turns out to be necessary for https://github.com/apple/llvm-project/pull/8011).
2024-02-06Add clang-tidy check to suggest replacement of conditional statement with ↵Bhuminjay Soni8-0/+524
std::min/std::max (#77816) This pull request fixes #64914 where author suggests adding a readability check to propose the replacement of conditional statements with std::min/std::max for improved code readability. Additionally, reference is made to PyLint's similar checks: [consider-using-min-builtin](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/consider-using-min-builtin.html) and [consider-using-max-builtin](https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/consider-using-max-builtin.html)
2024-02-05Apply format only if --format is specified (#79466)Dmitry Polukhin7-1/+69
clang-apply-replacements used to apply format even without --format is specified. This because, methods like createReplacementsForHeaders only takes the Spec.Style and would re-order the headers even when it was not requested. The fix is to set up Spec.Style only if --format is provided. Also added note to ReleaseNotes.rst Based on https://github.com/llvm/llvm-project/pull/70801 --------- Co-authored-by: Kugan <34810920+kuganv@users.noreply.github.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-02-05[clangd] Handle IndirectFieldDecl in kindForDecl (#80588)Nathan Ridge2-1/+17
Fixes https://github.com/clangd/clangd/issues/1925