Commit Graph

9375 Commits

Author SHA1 Message Date
vabridgers
4b5366c951
[clang-tidy] Avoid checking magic numbers if _BitInt (#65888)
Recent changes to add _BitInt support have caused our internal random
testing to fail. This change just avoids a readability magic numbers
check for now if a _BitInt. The crash seen (edited for clarity) is shown
below.

<src-root>/llvm/include/llvm/ADT/APInt.h:1488:
  uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits()
  <= 64 && "Too many bits for uint64_t"' failed.

...
 #9 <address> llvm::APInt::getZExtValue() const
      <src-root>/llvm/include/llvm/ADT/APInt.h:1488:5
      clang::IntegerLiteral const*) const

<src-root>/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:198:47
<clang::IntegerLiteral>(clang::ast_matchers::MatchFinder::MatchResult
      const&, char const*)

<src-root>/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h:67:5
      clang::ast_matchers::MatchFinder::MatchResult const&)

<src-root>/clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp:152:35
...

Reviewed By: donat.nagy
2023-09-17 14:00:57 -05:00
Piotr Zegar
ff8b4c8b2c [clang-tidy][NFC] Minor cleanup in ClangTidyMain.cpp
Extracted some code from a clangTidyMain function into
separate functions.
2023-09-16 06:17:57 +00:00
Aaron Ballman
e8b1af9a55 Fix clang-tidy sphinx docs
This addresses issues found by:
https://lab.llvm.org/buildbot/#/builders/115/builds/53446
2023-09-15 10:11:10 -04:00
Congcong Cai
72d4d4e3b9
[clang-tidy]add new check bugprone-compare-pointer-to-member-virtual-function (#66055) 2023-09-15 20:59:12 +08:00
Yitzhak Mandelbaum
004a7cea70
[clang][dataflow] Change diagnoseFunction to use llvm::SmallVector instead of std::vector. (#66014)
The template is agnostic as to the type used by the list, as long as it
is
compatible with `llvm::move` and `std::back_inserter`. In practice,
we've
encountered analyses which use different types (`llvm::SmallVector` vs
`std::vector`), so it seems preferable to leave this open to the caller.
2023-09-13 13:10:58 -04:00
kadir çetinkaya
a4d14011e5
[include-cleaner] Fix handling of enums in presence of qualifiers (#65952) 2023-09-11 19:21:02 +02:00
Viktoriia Bakalova
13e5fafb55 [clangd] Fix buildbot breakages from stemming from 64366d4935 2023-09-11 08:30:06 +00:00
Matthew Mirvish
4af340a6af
[clangd] Forward --target to system include extraction (#65824)
Some clang multilib configurations (such as the one currently used in
the [beta ARM LLVM
toolchain](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm))
wind up only reporting the C++ include paths properly if they get passed
the correct target. This patch ensures the `--target` (or `-target`)
arguments are correctly sent to the queried driver.
2023-09-11 04:11:37 -04:00
Julian Schmidt
94b14355e2 [clangd] allow extracting to variable for lambda expressions
Support for extracting lambda expressions, e.g. extracting a lambda from a callexpr (e.g. algorithms/ranges) to a named variable.

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D141757
2023-09-11 04:03:38 -04:00
Viktoriia Bakalova
64366d4935 [clangd] Rollforward include-cleaner library usage in symbol collector.
Differential Revision: https://reviews.llvm.org/D156659
2023-09-11 07:57:35 +00:00
Kadir Cetinkaya
26f9e49d9c
[clangd] Delete deprecated enumerateTweaks endpoint 2023-09-11 09:09:12 +02:00
kadir çetinkaya
d3cfc7126c
[include-cleaner] Always keep non-self-contained files (#65499) 2023-09-11 07:22:52 +02:00
Jan Svoboda
797cad9d32 [clang] NFCI: Use FileEntryRef in 'clang-tools-extra' 2023-09-10 19:53:54 -07:00
Piotr Zegar
503e31528a
[clang-tidy] Exclude bitwise operators in bugprone-non-zero-enum-to-bool-conversion (#65498)
Improved bugprone-non-zero-enum-to-bool-conversion check by eliminating
false positives resulting from direct usage of bitwise operators.
2023-09-10 18:08:51 +02:00
Ignat Loskutov
f2e5000937 [clang-tidy] Fix DanglingHandleCheck to work in C++17 and later mode
Due to guaranteed copy elision, not only do some nodes get removed from the AST,
but also some existing nodes change the source locations they correspond to.
Hence, the check works slightly differently in pre-C++17 and C++17-and-later modes
in terms of what gets highlighted.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D158371
2023-09-10 12:52:47 +00:00
Piotr Zegar
01c11569fc [clang-tidy] Add IgnoreTypes option to modernize-use-nullptr
New option added and configured in a way, so types
related to std::strong_ordering would be ignored.

Fixes: #63478

Reviewed By: ccotter

Differential Revision: https://reviews.llvm.org/D158928
2023-09-10 12:22:53 +00:00
Younan Zhang
cbd6ac6165 [clangd] Show parameter hints for operator()
Closes https://github.com/clangd/clangd/issues/1742

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D158926
2023-09-10 15:56:00 +08:00
Jan Svoboda
6966c06bed [clang] NFCI: Use FileEntryRef in suggestPathToFileForDiagnostics() 2023-09-09 20:29:04 -07:00
Jan Svoboda
eea232da82 [clang][tools] Remove path separator assumption
After 98e6deb6 the 'HeadersForSymbolTest.IWYUTransitiveExportWithPrivate' test in 'ClangIncludeCleanerTest' started failing. This is most likely because `FileEntryRef::getName()` now starts with ".\" on Windows, whereas `FileEntry::getName()` did not. This commit fixes assumption of forward slash separators.
2023-09-09 11:38:32 -07:00
Jan Svoboda
98e6deb62c [clang][tools] Use FileEntryRef in include_cleaner::Header 2023-09-09 09:54:13 -07:00
Jan Svoboda
5523fefb01 [clang][lex] Use preferred path separator in includer-relative lookup
There is a long-standing FIXME in `HeaderSearch.cpp` to use the path separator preferred by the platform instead of forward slash. There was an attempt to fix that (1cf6c28a) which got reverted (cf385dc8). I couldn't find an explanation, but my guess is that some tests assuming forward slash started failing.

This commit fixes tests with that assumption.

This is intended to be NFC, but there are two exceptions to that:
* Some diagnostic messages might now contain backslash instead of forward slash.
* Arguments to the "-remap-file" option that use forward slash might stop kicking in. Separators between potential includer path and header name need to be replaced by backslash in that case.
2023-09-08 16:38:08 -07:00
Viktoriia Bakalova
43c20367f4 [include-cleaner][clangd][clang-tidy] Ignore resource dir during include-cleaner analysis.
Differential Revision: https://reviews.llvm.org/D157610
2023-09-07 11:39:18 +00:00
Congcong Cai
31ded49527
[clang-tidy][modernize-use-using]fix function pointer typedef correctly (#65558)
Fixed #65055
For normal type, typedef is from typedef to the end of original type,
but for function pointer it is from typedef to the end.
So it needs to consider alias name length for normal type.
2023-09-07 17:06:28 +08:00
Piotr Zegar
93f9f63b2d [clang-tidy][NFC] Update documentation for fuchsia-statically-constructed-objects
Fix compile errors in example provided in
documentation.

Fixes: #65118
2023-09-06 18:06:59 +00:00
Kadir Cetinkaya
73b2c86d95
[include-cleaner] Weaken signal for boosting preferred headers
Putting preferred header signal above completeness implied we would
uprank forward declarations above complete ones in certain cases.

This can be desired in cases where:
- Complete definition is private. But this case is already governed by
  publicness signal.
- The library indeed intends to provide a forward declaring interface, like
  iosfwd vs ostream.

In all other cases, upranking is undesired as it means we've picked up prefered
headerness signal by mistake from an unrelated declaration to the library.

This change regresses the behavior for libraries that intentionally provide a
forward declaring interface. But that wasn't something we intended to support
explicitly, it was working incidentally when the forward declaring header had a
similar name to the symbol. Moreover, include-cleaner deliberately discourages
forward-declarations, so not working in this case is also more aligned with rest
of the components.

Differential Revision: https://reviews.llvm.org/D159441
2023-09-06 14:46:33 +02:00
Viktoriia Bakalova
d71adebb9f [include-cleaner] Map the 4-argument move overload to the algorithm header.
Differential Revision: https://reviews.llvm.org/D159463
2023-09-06 11:38:56 +00:00
Congcong Cai
b0831c3996
[clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (#65431)
`HeaderIncludes` won't update `ExistingIncludes` during inserting.
We need to manage it in tidy check.

Fixed: #65285
2023-09-06 17:37:14 +08:00
Kadir Cetinkaya
9a26d2c6d3
[clangd][unittests] Limit paralelism for clangd unittests
We started seeing a lot of timeouts that align with the change in lit to
execute gtests in shards. The logic there assumes tests are
single-threaded, which is the case for most of the LLVM, hence they
pick #shards ~ #cores (by slightly overshooting).

There are enough unittests in clangd that rely on multi-threading, they
can create arbitrarily many threads but we limit amount of meaningful
work to ~4 thread per process.

This change ensures that we're accounting for that paralelism when
executing clangd tests and not overloading test executors.

In theory the change overestimates the requirements, not all tests are
multi-threaded, but it doesn't seem to be resulting in any regressions
on my local runs.

Fixes https://github.com/llvm/llvm-project/issues/64964.
Fixes https://github.com/clangd/clangd/issues/1712.
2023-09-06 10:53:18 +02:00
Jan Svoboda
8e0c9bb91f [clang] NFCI: Change returned AnalyzerOptions smart pointer to reference 2023-09-05 13:23:53 -07:00
Jan Svoboda
5746002ebb [clang] NFCI: Change returned LanguageOptions pointer to reference 2023-09-05 13:23:53 -07:00
Ivan Murashko
d03a7f15f0 [clangd] SIGSEGV at clangd: DiagnosticConsumer Is Used After Free
This is a follow-up patch for D148088. The dynamic symbol index (`FileIndex::updatePreamble`) may run in a separate thread, and the `DiagnosticConsumer` that is set up in `buildPreamble` might go out of scope before it is used. This could result in a SIGSEGV when attempting to call any method of the `DiagnosticConsumer` class.

The function `buildPreamble` sets up the `DiagnosticConsumer` as follows:
```
... buildPreamble(...) {
...
  StoreDiags PreambleDiagnostics;
  ...
  llvm::IntrusiveRefCntPtr<DiagnosticsEngine> PreambleDiagsEngine =
    CompilerInstance::createDiagnostics(&CI.getDiagnosticOpts(),
                                        &PreambleDiagnostics,
                                        /*ShouldOwnClient=*/false);
  ...
  // The call might use the diagnostic consumer in a separate thread
  PreambleCallback(...)
  ...
}
```
`PreambleDiagnostics` might be out of scope for `buildPreamble` function when we call it inside `PreambleCallback` in a separate thread.

The Fix
The fix involves replacing the client (DiagnosticConsumer) with an `IgnoringDiagConsumer` instance, which will print messages to the clangd log.

Alternatively, we can replace `PreambleDiagnostics` with an object that is owned by `DiagnosticsEngine`.

Note
There is no corresponding LIT/GTest for this issue, since there is a specific race condition that is difficult to reproduce within a test framework.

Test Plan:
```
ninja check-clangd
```

Reviewed By: kadircet, sammccall

Differential Revision: https://reviews.llvm.org/D159363
2023-09-04 18:53:49 +01:00
Sam McCall
a8c9b9f140 [clangd] Support ConceptReference in generic AST wrangling code
Now we can store it in DynTypedNode, we can target these nodes
(SelectionTree) and resolve them (FindTarget).
This makes Hover, go-to-def etc work in all(?) cases.

Also support it in DumpAST.

Differential Revision: https://reviews.llvm.org/D159299
2023-09-04 14:58:25 +02:00
Carlos Galvez
fdb6e8b792
[clang-tidy][NFC][doc] Improve documentation for modernize-use-equals… (#65231)
…-delete

So the purpose of the check is more clear. Update examples code to show
compliant code.

Fixes #65221

---------

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2023-09-04 11:45:04 +02:00
Piotr Zegar
208fa9acc0 [clang-tidy] Ignore used special-members in modernize-use-equals-delete
Special members marked as used, or with out-of-line
definition should not raise an warning now.

Fixes: #33759

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D158486
2023-09-03 17:05:31 +00:00
Piotr Zegar
fa8e740737
[clang-tidy] readability-identifier-naming - fix StructCase and UnionCase in C (#65202)
In C struct are visible as RecordDecl, not as CXXRecordDecl, this type
of declaration were not supported in this check before. Changing check
to support it. Added tests.

Fixes: #55422
2023-09-03 18:40:18 +02:00
Piotr Zegar
c2bee1ed26 [clang-tidy][NFC] Unwind if-else-if-... in UnusedUsingDeclsCheck
Break a if-else-if-else... chain. Use early return instead.

Fixes: #46375
2023-09-03 06:24:56 +00:00
Kazu Hirata
840a968226 [clang-tools-extra] Use range-based for loops (NFC) 2023-09-02 12:12:16 -07:00
Younan Zhang
e257c0a919 [clang][clangd] Ensure the stack bottom before building AST
`clang::runWithSufficientStackSpace` requires the address of the
initial stack bottom to prevent potential stack overflows.

In addition, add a fallback to ASTFrontendAction in case any client
forgets to call it when not through CompilerInstance::ExecuteAction,
which is rare.

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

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D158967
2023-09-02 18:53:06 +08:00
Fangrui Song
678e3ee123 [lldb] Fix duplicate word typos; NFC
Those fixes were taken from https://reviews.llvm.org/D137338
2023-09-01 21:32:24 -07:00
Kadir Cetinkaya
16b8b3e59f
[clangd][tests] Bump timeouts in TUSchedulerTests to 60 secs
There are some slow/congested bots, that can't go idle in 10 secs, see https://github.com/llvm/llvm-project/issues/64964

Differential Revision: https://reviews.llvm.org/D159338
2023-09-01 12:19:10 +02:00
Kadir Cetinkaya
69feef0e82
[clangd][tests] Assert for idleness of scheduler
We could fail going idle in 5 seconds and get spurious errors
afterwards. See https://github.com/llvm/llvm-project/issues/64964.

Differential Revision: https://reviews.llvm.org/D159337
2023-09-01 12:19:09 +02:00
Piotr Zegar
4294bca5e4 [clang-tidy] Add exit code support to clang-tidy-diff.py
Modify script to fail when some run clang-tidy
command fails. Based on run_clang-tidy.

Fixes: #65000

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D158929
2023-08-31 19:58:15 +00:00
Piotr Zegar
efebb4e0fa [clang-tidy] readability-container-size-empty handle std::string length()
Extends readability-container-size-empty to check std::string length() similar to size().

Fixes: #37603

Co-authored-by: Dmitry Venikov <quolyk@gmail.com>

Reviewed By: carlosgalvezp

Differential Revision: https://reviews.llvm.org/D56644
2023-08-31 19:56:07 +00:00
Piotr Zegar
a199d8fac0 [clang-tidy][NFC] Improve compilation time of IntegralLiteralExpressionMatcher
When using agressive inlining -Xclang -mllvm -Xclang -inline-threshold=500,
this file takes 10-18 min to compile. This is caused by in-direct recursion.
Looks like transforming code to use templates and lambdas instead of
std::function and member function pointer reduces this time to 0.5s.

Fixes: #59658
2023-08-31 19:22:17 +00:00
Utkarsh Saxena
ac2d2652db [include-cleaner] Handle decls/refs to concepts 2023-08-31 13:57:22 +02:00
Jens Massberg
c39dcd2c2b [c++20][clangd] Simplify code using the new ConceptReference nodes.
Directly traverse `ConceptReference`s in FindTarget.cpp.

There is no need for the extra logic for `AutoTypeLoc`s in SemanticHightlighting.cpp as the concept information is stored in a `ConceptReference` which is now traversed.

Differential Revision: https://reviews.llvm.org/D159268
2023-08-31 13:53:56 +02:00
Ian Anderson
680da4b5d7 [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized
stdarg.h and stddef.h have to be textual headers in their upcoming modules to support their `__needs_xxx` macros. That means that they won't get precompiled into their modules' pcm, and instead their declarations will go into every other pcm that uses them. For now that's ok since the type merger can handle the declarations in these headers, but it's suboptimal at best. Make separate headers for all of the pieces so that they can be properly modularized.

Reviewed By: aaron.ballman, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D158709
2023-08-30 11:41:12 -07:00
Piotr Zegar
c6fa07ca96 [clang-tidy][NFC][DOC] Update links to HICPP standard
Old links pointed out to old domain, and then redirected to correct
one, but to wrong pages. Changed links from old to new domain and page.

Fixes: #65064
2023-08-30 18:02:34 +00:00
Piotr Zegar
26f230fe52 [clang-tidy][NFC] Fix llvm-else-after-return findings
Fix issues found by clang-tidy in clang-tidy source directory.
2023-08-30 17:41:41 +00:00
Aaron Ballman
a02f9a7756 Revert "[clang] Enable sized deallocation by default in C++14 onwards"
This reverts commit 2916b125f6.

Reverting due to failures on:
https://lab.llvm.org/buildbot/#/builders/216/builds/26407
https://lab.llvm.org/staging/#/builders/247/builds/5659
http://45.33.8.238/win/83485/step_7.txt
2023-08-29 09:36:59 -04:00