aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra
AgeCommit message (Collapse)AuthorFilesLines
2024-03-16[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 (cherry picked from commit e6e53ca8470d719882539359ebe3ad8b442a8cb0)
2024-03-14[clangd] Add clangd 18 release notes (#84436)Nathan Ridge1-7/+36
2024-02-03Backport '[clang] static operators should evaluate object argument (reland)' ↵Tianlan Zhou1-5/+1
to release/18.x (#80109) Cherry picked from commit ee01a2c3996f9647f3158f5acdb921a6ede94dc1. Closes #80041, backport #80108. Co-authored-by: Shafik Yaghmour <shafik@users.noreply.github.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2024-01-23[misc-coroutine-hostile-raii] Use getOperand instead of getCommonExpr. (#79206)Utkarsh Saxena2-2/+34
We were previously allowlisting awaitable types returned by `await_transform` instead of the type of the operand of the `co_await` expression. This previously used to give false positives and not respect the `AllowedAwaitablesList` flag when `await_transform` is used. See added test cases for such examples.
2024-01-23[clang-tidy][DOC] Update list.rstPiotr Zegar1-1/+1
Update list.rst to put checks in alphabetical order
2024-01-23[clang-tidy] Ignore user-defined literals in google-runtime-int (#78859)Félix-Antoine Constantin3-9/+23
User-defined literals do not accept u?intXX(_t)? variables. So the check should not emit a warning. Fixes #54546 #25214
2024-01-22[clang-tidy] fix misc-const-correctnes false-positive for fold expressions ↵Julian Schmidt2-1/+30
(#78320) The check no longer emits a diagnostic for non-parameter-pack variables in C++17 fold expressions. The operator used is type-dependent because of the parameter pack and can therefore not be guaranteed to not mutate the variable. Fixes: #70323
2024-01-22[PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (#78285)Qiongsi Wu1-1/+1
https://github.com/llvm/llvm-project/pull/76471 caused buildbot failures on Windows. For more details, see https://github.com/llvm/llvm-project/issues/77546. This PR revises the test and relands https://github.com/llvm/llvm-project/pull/76471.
2024-01-22[clang-tidy] Add bugprone-chained-comparison check (#76365)Piotr Zegar9-0/+435
Check that flags chained comparison expressions, such as a < b < c or a == b == c, which may have unintended behavior due to implicit operator associativity. Moved from Phabricator (D144429).
2024-01-22[clang-tidy] Fix macros handling in ↵Piotr Zegar3-5/+36
cppcoreguidelines-prefer-member-initializer (#72037) Produces now valid fixes for a member variables initialized with macros. Correctly uses expansion location instead of location inside macro to get init code. Close #70189
2024-01-22[include-cleaner] Add --only-headers flag, opposite of --ignore-headers (#78714)Sam McCall2-3/+31
2024-01-22[clang-tidy] Use llvm::any_of (NFC)Kazu Hirata1-1/+1
2024-01-22[clang] Remove `CXXNewInitializationStyle::Implicit` (#78793)Vlad Serebrennikov1-4/+3
This is a follow up to https://github.com/llvm/llvm-project/pull/71417 , which aims to resolve concerns brought up there. Namely, this patch replaces `CXXNewInitializationStyle::Implicit` with a dedicated `HasInitializer` flag. This makes `CXXNewInitializationStyle` to model syntax again. This patch also renames `Call` and `List` to less confusing `Parens` and `Braces`.
2024-01-21[c++20] P1907R1: Support for generalized non-type template arguments of ↵Andrey Ali Khan Bolshakov2-0/+2
scalar type. (#78041) Previously committed as 9e08e51a20d0d2b1c5724bb17e969d036fced4cd, and reverted because a dependency commit was reverted, then committed again as 4b574008aef5a7235c1f894ab065fe300d26e786 and reverted again because "dependency commit" 5a391d38ac6c561ba908334d427f26124ed9132e was reverted. But it doesn't seem that 5a391d38ac6c was a real dependency for this. This commit incorporates 4b574008aef5a7235c1f894ab065fe300d26e786 and 18e093faf726d15f210ab4917142beec51848258 by Richard Smith (@zygoloid), with some minor fixes, most notably: - `UncommonValue` renamed to `StructuralValue` - `VK_PRValue` instead of `VK_RValue` as default kind in lvalue and member pointer handling branch in `BuildExpressionFromNonTypeTemplateArgumentValue`; - handling of `StructuralValue` in `IsTypeDeclaredInsideVisitor`; - filling in `SugaredConverted` along with `CanonicalConverted` parameter in `Sema::CheckTemplateArgument`; - minor cleanup in `TemplateInstantiator::transformNonTypeTemplateParmRef`; - `TemplateArgument` constructors refactored; - `ODRHash` calculation for `UncommonValue`; - USR generation for `UncommonValue`; - more correct MS compatibility mangling algorithm (tested on MSVC ver. 19.35; toolset ver. 143); - IR emitting fixed on using a subobject as a template argument when the corresponding template parameter is used in an lvalue context; - `noundef` attribute and opaque pointers in `template-arguments` test; - analysis for C++17 mode is turned off for templates in `warn-bool-conversion` test; in C++17 and C++20 mode, array reference used as a template argument of pointer type produces template argument of UncommonValue type, and `BuildExpressionFromNonTypeTemplateArgumentValue` makes `OpaqueValueExpr` for it, and `DiagnoseAlwaysNonNullPointer` cannot see through it; despite of "These cases should not warn" comment, I'm not sure about correct behavior; I'd expect a suggestion to replace `if` by `if constexpr`; - `temp.arg.nontype/p1.cpp` and `dr18xx.cpp` tests fixed.
2024-01-21[clang-tidy][NFC] Enable exceptions in test for google-readability-castingPiotr Zegar1-1/+1
Add missing -fexceptions in test.
2024-01-21[clang-tidy] Fix handling of functional cast in google-readability-casting ↵Piotr Zegar4-15/+19
(#71650) Fix issue with constructor call being interpreted as functional cast and considered for a replacement with static cast or being removed as redundant. Closes #57959
2024-01-20[clang-tidy] fix modernize-use-auto incorrect fix hints for pointer (#77943)Congcong Cai3-15/+74
2024-01-20[clang-tidy] Added new check to detect redundant inline keyword (#73069)Félix-Antoine Constantin8-0/+353
This checks find usages of the inline keywork where it is already implicitly defined by the compiler and suggests it's removal. Fixes #72397
2024-01-20[clang-tidy] Add readability-redundant-casting check (#70595)Piotr Zegar9-0/+562
Detects explicit type casting operations that involve the same source and destination types, and subsequently recommend their removal. Covers a range of explicit casting operations. Its primary objective is to enhance code readability and maintainability by eliminating unnecessary type casting. Closes #67534
2024-01-20[clang-tidy] Fix crash in modernize-loop-convert when int is used as ↵Piotr Zegar3-6/+24
iterator (#78796) Fix crash when built-in type (like int) is used as iterator, or when call to begin() return integer. Closes #78381
2024-01-19[clang-apply-replacements] Deduplicate Implementation of ↵Daniil Dudkin2-45/+28
`collectReplacementsFromDirectory` (NFC) (#78630) * Convert `collectReplacementsFromDirectory` into a function template. * Employ explicit specialization to maintain implementation in the source file. * Utilize the function template in the source file to eliminate code duplication. * Update the documentation for the function.
2024-01-19[clangd] Don't collect templated decls for builtin templates (#78466)Younan Zhang2-3/+37
Builtin templates e.g. `__make_integer_seq`, `__type_pack_element` are such that they don't have alias *Decls*. [D133262](https://reviews.llvm.org/D133262) marked these as alias templates, resulting in an attempt to collect their null "using" Decls within our `TargetFinder`. This fixes https://github.com/clangd/clangd/issues/1906.
2024-01-18[Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (#78463)cor3ntin4-7/+8
To avoid any possible confusion with the notion of pure function and the gnu::pure attribute.
2024-01-18[clangd] Handle an expanded token range that ends in the `eof` token in ↵Nathan Ridge1-0/+11
TokenBuffer::spelledForExpanded() (#78092) Such ranges can legitimately arise in the case of invalid code, such as a declaration missing an ending brace. Fixes https://github.com/clangd/clangd/issues/1559
2024-01-16[clang-tidy] Fix missing parentheses in readability-implicit-bool-conversion ↵Piotr Zegar7-109/+140
fixes (#74891) Check now more properly add missing parentheses to code like this: 'bool bar = true ? 1 : 0 != 0;'. Closes #71867
2024-01-16[NFC][clang-tidy]improve performance for misc-unused-using-decls check (#78231)Congcong Cai2-4/+11
`UnusedUsingDeclsCheck::removeFromFoundDecls` will be called with high frequency. At current time it will check every `Context`. This patch adds a cache to reduce algorithm complexity.
2024-01-16[clang-tidy] Handle C++ structured bindings in `performance-for-range-copy` ↵Clement Courbet3-8/+40
(#77105) Right now we are not triggering on: ``` for (auto [x, y] : container) { // const-only access } ```
2024-01-15[modularize] Use SmallString::operator std::string (NFC)Kazu Hirata1-2/+2
2024-01-16[NFC]add - at the beginning for alignmentCongcong Cai1-1/+1
2024-01-15[clang-tidy]Add new check readability-avoid-nested-conditional-operator (#78022)Congcong Cai8-0/+140
Finds nested conditional operator. Nested conditional operators lead code hard to understand, so they should be splited as several statement and stored in temporary varibale.
2024-01-15[clang-tidy]fix readability-implicit-bool-conversion false-positives when ↵Congcong Cai3-4/+7
comparison bool bitfield (#77878) Fixes: #76817 For ignoring comparison and xor operator, it needs to use `ImplicitCastFromBool` without ignoring exception cases. This patch splits ignoring exception cases logic from `ImplicitCastFromBool` and only applies it during matching targeted AST.
2024-01-14[clang-doc] Use SmallString::operator std::string (NFC)Kazu Hirata1-1/+1
2024-01-14[clang-tidy] Use StringRef::consume_front (NFC)Kazu Hirata1-5/+1
2024-01-14[clang-tidy] Fix false-positives in readability-container-size-empty (#74140)Piotr Zegar3-11/+83
Added support for size-like method returning signed type, and corrected false positive caused by always-false check for size bellow zero. Closes #72619
2024-01-14[clang-tidy] Add support for in-class initializers in ↵Piotr Zegar4-23/+109
readability-redundant-member-init (#77206) Support detecting redundant in-class initializers. Moved from https://reviews.llvm.org/D157262 Fixes: #62525
2024-01-14[clang-tidy][DOC] Fix some speling mistakes in release notesPiotr Zegar1-16/+16
Reorder checks & fix some formating.
2024-01-14Fix #75686: add iter_swap and iter_move to the matched name (#76117)Da-Viper7-12/+40
Added support for iter_swap, iter_move in bugprone-exception-escape and performance-noexcept-swap checks. Fixes #75686
2024-01-14[clang-tidy] Add option to ignore macros in ↵Danny Mösch5-3/+42
`readability-simplify-boolean-expr` check (#78043)
2024-01-13[clang-tidy] Invalid Fix-It generated for ↵Félix-Antoine Constantin5-16/+31
implicit-widening-multiplication-result (#76315) The check currently emits warnings for the following code: `uint64_t fn() { return 1024 * 1024; }` But the code generated after applying the notes will look like this: `uint64_t fn() { return static_cast<uint64_t>(1024 * )1024; }` This is because when generating the notes the check will use the beginLoc() and EndLoc() of the subexpr of the implicit cast. But in some cases the AST Node might not have a beginLoc and EndLoc. This seems to be true when the Node is composed of only 1 token (for example an integer literal). Calling the getEndLoc() on this type of node will simply return the known location which is, in this case, the beginLoc. Fixes #63070 #56728
2024-01-12[clang-tidy] Use StringRef::ltrim (NFC)Kazu Hirata1-1/+1
2024-01-13[NFC]fix incorrect autosar link in clang-tidy docCongcong Cai1-1/+1
2024-01-13[NFC]update autosar link in clang-tidy docCongcong Cai2-1/+4
2024-01-12[clang-tidy] Fix false-positives in misc-static-assert caused by ↵Piotr Zegar3-2/+56
non-constexpr variables (#77203) Ignore false-positives when referring to non-constexpr variables in non-unevaluated context (like decltype, sizeof, ...). Moved from https://reviews.llvm.org/D158657 Fixes: #24066
2024-01-12[clangd] Use starts_with instead of startswith in CompileCommands.cpp (NFC)Jie Fu1-1/+1
llvm-project/clang-tools-extra/clangd/CompileCommands.cpp:324:52: error: 'startswith' is deprecated: Use starts_with instead [-Werror,-Wdeprecated-declarations] 324 | Cmd, [&](llvm::StringRef Arg) { return Arg.startswith(Flag); }); | ^~~~~~~~~~ | starts_with
2024-01-12[clangd] Fix sysroot flag handling in CommandMangler to prevent duplicates ↵Kon2-13/+91
(#75694) CommandMangler should guess the sysroot path of the host system and add that through `-isysroot` flag only when there is no `--sysroot` or `-isysroot` flag in the original compile command to avoid duplicate sysroot. Previously, CommandMangler appropriately avoided adding a guessed sysroot flag if the original command had an argument in the form of `--sysroot=<sysroot>`, `--sysroot <sysroot>`, or `-isysroot <sysroot>`. However, when presented as `-isysroot<sysroot>` (without spaces after `-isysroot`), CommandMangler mistakenly appended the guessed sysroot flag, resulting in duplicated sysroot in the final command. This commit fixes it, ensuring the final command has no duplicate sysroot flags. Also adds unit tests for this fix.
2024-01-11[clangd] Handle lambda scopes inside Node::getDeclContext() (#76329)Younan Zhang3-0/+39
We used to consider the `DeclContext` for selection nodes inside a lambda as the enclosing scope of the lambda expression, rather than the lambda itself. For example, ```cpp void foo(); auto lambda = [] { return ^foo(); }; ``` where `N` is the selection node for the expression `foo()`, `N.getDeclContext()` returns the `TranslationUnitDecl` previously, which IMO is wrong, since the method `operator()` of the lambda is closer. Incidentally, this fixes a glitch in add-using-declaration tweaks. (Thanks @HighCommander4 for the test case.)
2024-01-10[clang-query] Use StringRef::ltrim (NFC)Kazu Hirata1-6/+3
2024-01-10[emacs] Fix Emacs library formatting (#76110)darkfeline1-0/+1
This makes it easier to ship/install these using the builtin Emacs package format (in particular, a Version is required).
2024-01-09Revert "[PGO] Exposing PGO's Counter Reset and File Dumping APIs (#76471)"Vitaly Buka1-1/+1
Issue #77546 This reverts commit 07c9189fcc063bdf6219d2733843c89cde3991e1.
2024-01-09[clangd] Fix typo in function name in AST.cpp (#77504)Nour12481-6/+6