Commit Graph

8501 Commits

Author SHA1 Message Date
Haojian Wu 962343a979 [include-cleaner] Fix walkUsed only report a single macro ref. 2022-11-28 10:12:10 +01:00
Viktoriia Bakalova 10d183b889 [include-cleaner] Capture private headers in PragmaIncludes.
Save file IDs of IWYU private headers and report them as private.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D138678
2022-11-28 10:02:02 +01:00
Kazu Hirata 9c8a6a1627 [include-cleaner] Fix a warning
This patch fixes:

  clang-tools-extra/include-cleaner/lib/HTMLReport.cpp:240:51: error:
  missing field 'Locations' initializer
  [-Werror,-Wmissing-field-initializers]
2022-11-25 09:51:25 -08:00
Jens Massberg db335d02a5 [clang-tidy] Ignore cxxRewrittenBinaryOperator in defaulted function decls in modernize-use-nullptr
The check has produced false positives when checking the default implementation of the spaceship operator.
The default implementation should be skipped by the check.

Modified the existing test so that the check runs into the bug without this fix and add another test case.

Fixes #53961.

Patch by Jens Massberg.

Reviewed By: ilya-biryukov

Differential Revision: https://reviews.llvm.org/D138701
2022-11-25 15:45:37 +01:00
Florian Hahn 07ca9cc04b
Revert "[Support] Move getHostNumPhysicalCores to Threading.h"
This reverts commit 5577207d6d.

This breaks building LLVM on recent macOS. Error messages below:

llvm/lib/Support/Threading.cpp:190:3: error: use of undeclared
identifier 'sysctlbyname'
  sysctlbyname("hw.physicalcpu", &count, &len, NULL, 0);
    ^

llvm/lib/Support/Threading.cpp:193:13: error: use of undeclared
identifier 'CTL_HW'
    nm[0] = CTL_HW;
            ^

llvm/lib/Support/Threading.cpp:194:13: error: use of undeclared identifier 'HW_AVAILCPU'
    nm[1] = HW_AVAILCPU;
            ^

llvm/lib/Support/Threading.cpp:195:5: error: use of undeclared identifier 'sysctl'
    sysctl(nm, 2, &count, &len, NULL, 0);
    ^
2022-11-25 14:11:56 +00:00
Archibald Elliott 5577207d6d [Support] Move getHostNumPhysicalCores to Threading.h
This change is focussed on simplifying `Support/Host.h` to only do
target detection. In this case, this function is close in usage to
existing functions in `Support/Threading.h`, so I moved it into there.
The function is also renamed to `llvm::get_physical_cores()` to match
the style of threading's functions.

Differential Revision: https://reviews.llvm.org/D137836
2022-11-25 12:51:36 +00:00
Sam McCall 9d5e82e75c [include-cleaner] Make HTMLReport impl simpler/safer. NFC
Targets and Refs are 1:1, so merge them.

Don't sort Refs array we keep indices into. (Currently we're done using
those indices by the time we sort, but this is fragile)
2022-11-25 13:12:20 +01:00
Sam McCall 6a95e67323 [include-cleaner] HTMLReport shows headers that would be inserted
Demo: 7911d8251c/PathMapping.cpp.html

Header insertion doesn't actually work that well (not this patch's fault):
- we don't have ranking of locations/headers yet, so inserted header is pretty
  random
- on my system, we get a lot of absolute "/usr/bin/../include/..." paths.
  This is a HeaderSearch bug introduced in D60873 that I'll send a fix for

Differential Revision: https://reviews.llvm.org/D138676
2022-11-25 11:57:35 +01:00
Sam McCall 3e658abd41 [include-cleaner] Show details for #include directives (used/unused)
Differential Revision: https://reviews.llvm.org/D138649
2022-11-24 15:36:44 +01:00
Sam McCall 0cb2dd5322 [include-cleaner] Make Symbol (and Macro) hashable.
For now, we decided not to add operator< or handle other variants.
(If we do so in future we may want to extract a base class).

Differential Revision: https://reviews.llvm.org/D138648
2022-11-24 15:15:50 +01:00
Viktoriia Bakalova 6ebd0aa420 [include-cleaner] Record macro references in #ifdef clause.
Records macro references in #ifdef clauses as ambiguous.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D138559
2022-11-24 14:48:25 +01:00
Haojian Wu 078081171c [include-cleaner] Remove an unused local variable, NFC. 2022-11-24 11:05:34 +01:00
Kazu Hirata 34bcadc38c Use std::nullopt_t instead of NoneType (NFC)
This patch replaces those occurrences of NoneType that would trigger
an error if the definition of NoneType were missing in None.h.

To keep this patch focused, I am deliberately not replacing None with
std::nullopt in this patch or updating comments.  They will be
addressed in subsequent patches.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Differential Revision: https://reviews.llvm.org/D138539
2022-11-23 14:16:04 -08:00
Sam McCall 19ab2a671e [include-cleaner] Show includes matched by refs in HTML report.
Demo: 8736e64c45/ASTTests.html%25202

Differential Revision: https://reviews.llvm.org/D138219
2022-11-23 13:41:24 +01:00
Paul Kirth 48bb147112 Revert "[clang-doc] Move file layout to the generators."
This reverts commit f8a469fc57.

The test in single-file-public.cpp breaks on Mac, due to an unknown
regextype in the find command.
2022-11-22 19:14:54 +00:00
Brett Wilson f8a469fc57 [clang-doc] Move file layout to the generators.
Previously file naming and directory layout was handled on a per Info
object basis by ClangDocMain and the generators blindly wrote to the
files given. This means all generators must use the same file layout and
caused problems where multiple objects mapped to the same file. The
object collision problem happens most easily with template
specializations because the template parameters are not part of the
"name".

This patch moves the responsibility for output file organization to the
generators. Currently HTML and MD use the same structure as before. But
they now collect all objects that map to a given file and combine them,
avoiding the corruption problems.

Converts the YAML generator to naming files based on USR in one
directory. This is easier for downstream tools to manage and avoids
the naming problems with template specializations. Since this change
requires backward-incompatible output changes to referenced files anyway
(since each one is now an array), this is a good time to introduce this
change.

Differential Revision: https://reviews.llvm.org/D138073
2022-11-22 10:27:29 -08:00
Kazu Hirata 1f914944b6 Don't use Optional::getPointer (NFC)
Since std::optional does not offer getPointer(), this patch replaces
X.getPointer() with &*X to make the migration from llvm::Optional to
std::optional easier.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Differential Revision: https://reviews.llvm.org/D138466
2022-11-21 19:03:40 -08:00
Christian Kandeler 699a59aa58 [clangd] Mark "override" and "final" as modifiers
... in semantic highlighting.
These specifiers cannot be identified by simple lexing (since e.g.
variables with these names can legally be declared), which means they
should be semantic tokens.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D137943
2022-11-21 22:01:12 +01:00
Sam McCall c67b710379 [clangd] Add option to skip per-location checks.
This avoids a slow step after timing tidy checks for https://github.com/clangd/clangd/issues/1337
2022-11-21 16:41:53 +01:00
Sam McCall 5696f2dfce [clangd] Move --check options into Check.cpp. Add --check-completion.
This is less plumbing and clutter in ClangdMain.cpp.
Having --check-lines imply completion was just about minimizing plumbing
I think, so make that explicit.
2022-11-21 16:39:27 +01:00
Sam McCall fd733a65de [clangd] Extend --check to time clang-tidy checks, so we can block slow ones
misc-const-correctness is so catastrophically slow that we need to block it
from running. But we need a way to detect this without breaking users first.

This is part of a plan to run only fast checks by default.
More details in  https://github.com/clangd/clangd/issues/1337

Differential Revision: https://reviews.llvm.org/D136082
2022-11-21 16:24:47 +01:00
Haojian Wu 6527201414 [clang-tidy] Remove a duplicated if-branch in the unused-using-decl
check, NFC
2022-11-18 15:07:46 +01:00
Tom Praschan 3cf14a7bdc [Support] Add support for attaching payloads to points and ranges
This is useful where tests previously encoded information in the name
names of ranges and points. Currently, this is pretty limited because
names consist of only alphanumeric characters and '_'.

With this patch, we can keep the names simple and attach optional
payloads to ranges and points instead.

The new syntax should be fully backwards compatible (if I haven't missed
anything). I tested this against clangd unit tests and everything still passes.

Differential Revision: https://reviews.llvm.org/D137909
2022-11-18 15:00:23 +01:00
Haojian Wu 0cf8885144 [include-cleaner] Add self-contained file support for PragmaIncludes.
And use it findHeaders. findHeaders now finds all header candidates
given a symbol location (these headers will be attached with proper
signals, in a followup patch).

Differential Revision: https://reviews.llvm.org/D137698
2022-11-18 13:52:30 +01:00
Martin Storsjö 68294afa08 [include-cleaner] Fix building with LLVM_LINK_LLVM_DYLIB=ON on mingw
Make sure to use clang_target_link_libraries, which skips linking
against libraries and links against libclang-cpp instead, if
LLVM_LINK_LLVM_DYLIB is enabled.

This fixes errors like these:

ld.lld: error: duplicate symbol: clang::PPCallbacks::~PPCallbacks()
>>> defined at libclangLex.a(PPCallbacks.cpp.obj)
>>> defined at libclang-cpp.dll
2022-11-18 10:30:26 +02:00
Fangrui Song 46202543c9 [CMake] Remove a duplicate clangLex entry 2022-11-18 00:58:04 +00:00
Fangrui Song f962dafbbd [include-cleaner] Fix -DBUILD_SHARED_LIBS=on build
and apply an include-cleaner fix for the tool itself:)

addPPCallbacks requires the vtable of PPChainedCallbacks and needs a clangLex
dependency.
2022-11-18 00:56:04 +00:00
Alexander Shaposhnikov 2483a7fffb [include-cleaner] Fix the build of include-cleaner with LLVM_BUILD_LLVM_DYLIB=ON 2022-11-18 00:54:45 +00:00
v1nh1shungry 8003c1d61e [clang-tidy] Fix misc-unused-using-decls for user-defined literals
Current version complains unused using-declaration even if the target
user-defined literal is used.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D138204
2022-11-17 22:47:15 +00:00
Simon Pilgrim 6faf5d7245 Fix MSVC "not all control paths return a value" warning. NFC. 2022-11-17 17:19:41 +00:00
Sam McCall 2675773258 [include-cleaner] add macro symbols and implicit refs to HTML report
Demo: 8c5c5ad927/ASTTests.html

Differential Revision: https://reviews.llvm.org/D137677
2022-11-17 17:29:41 +01:00
Tom Praschan 0e00611cbc [clangd] Add heuristic for dropping snippet when completing member function pointer
This implements the 1st heuristic mentioned in https://github.com/clangd/clangd/issues/968#issuecomment-1002242704:

When completing a function that names a non-static member of a class, and we are not inside that class's scope, assume the reference will not be a call (and thus don't add the snippetSuffix)

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D137040
2022-11-17 00:37:16 +01:00
David Goldman 2d5c4b8f6e Fix use of dangling stack allocated string in IncludeFixer
IncludeFixer uses this BuildDir string later on if given relative paths.

Differential Revision: https://reviews.llvm.org/D138047
2022-11-16 11:09:06 -08:00
Kadir Cetinkaya e5739eb4f8
[include-cleaner] Defer decl->stdlib conversion into decl->location conversion
We preserve decls for stdlib symbols after this patch in symbol. That
way we have a more unified view of stdlib and regular decls and can provide
reacher information in applications.

Differential Revision: https://reviews.llvm.org/D138134
2022-11-16 16:52:39 +01:00
Thomas Etter a49fcca9e3 [clang-tidy] Optionally ignore findings in macros in `readability-const-return-type`.
Adds support for options-controlled configuration of the check to ignore results in macros.

Differential Revision: https://reviews.llvm.org/D137972
2022-11-15 14:28:03 +00:00
Thomas Etter f3afd16b65 [clang-tidy] Ignore overriden methods in `readability-const-return-type`.
Overrides are constrained by the signature of the overridden method, so a
warning on an override is frequently unactionable.

Differential Revision: https://reviews.llvm.org/D137968
2022-11-15 14:24:05 +00:00
Haojian Wu dd46a08008 Move the isSelfContainedHeader function from clangd to libtooling.
We plan to reuse it in the include-cleaner library, this patch moves
this functionality from clangd to libtooling, so that this piece of code can be
shared among all clang tools.

Differential Revision: https://reviews.llvm.org/D137697
2022-11-14 09:40:45 +01:00
Haojian Wu e000c2bce7 [include-cleaner] NFC, move the macro location fixme to findHeaders. 2022-11-11 14:55:29 +01:00
Haojian Wu 15b2702e83 [include-cleaner] NFC, correct a comment in
PragmaIncludes::RecordPragma.
2022-11-11 14:40:08 +01:00
Sam McCall 7943169273 [clang-include-cleaner] make SymbolLocation a real class, move FindHeaders
- replace SymbolLocation std::variant with enum-exposing version similar to
  those in types.cpp. There's no appropriate implementation file, added
  LocateSymbol.cpp in anticipation of locateDecl/locateMacro.
- FindHeaders is not part of the public Analysis interface, so should not
  be implemented/tested there (just code organization)
- rename findIncludeHeaders->findHeaders to avoid confusion with Include concept

Differential Revision: https://reviews.llvm.org/D137825
2022-11-11 13:41:54 +01:00
Sam McCall 8dfaf9940a [include-cleaner] Provide public to_string of RefType (for HTMLReport), clean up includes. NFC 2022-11-11 13:25:22 +01:00
Sam McCall 61c2276cb2 [include-cleaner] verbatimSpelling->verbatim, clean up some silly init-lists. NFC 2022-11-11 12:10:12 +01:00
Haojian Wu 7795548048 [include-cleaner] Initial version for the "Location=>Header" step
This patch implements the initial version of "Location => Header" step:

- define the interface;
- integrate into the existing workflow, and use the PragmaIncludes;

Differential Revision: https://reviews.llvm.org/D137320
2022-11-11 10:34:22 +01:00
Haojian Wu f3e8a117d2 [include-cleaner] Add export IWYU pragma support.
- add support to PragmaIncludes to handle IWYU export/begin_exports/end_exports
  pragma;
- implement an API to retrieve the direct exporter headers;

Differential Revision: https://reviews.llvm.org/D137319
2022-11-10 15:39:30 +01:00
v1nh1shungry 92297bde5c
[clangd] Implement hover for string literals
Show string-literals' type and size in a hover card

Issue related: https://github.com/clangd/clangd/issues/1016

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D137650
2022-11-10 12:16:05 +01:00
v1nh1shungry 82ca918b57 [clangd] Fix the code action `RemoveUsingNamespace`
Avoid adding qualifiers before user-defined literals

Reviewed By: tom-anders

Differential Revision: https://reviews.llvm.org/D137550
2022-11-09 21:04:21 +01:00
Ilya Biryukov 453c2879cb [include-cleaner] Add dependency to fix build with shared libraries 2022-11-09 18:31:14 +01:00
Sam McCall 96d771c470
[clangd] Avoid escaping issues in system-include-extractor.test 2022-11-08 23:48:15 +01:00
Sam McCall c333b92b72 [include-cleaner] Missing changes from 38cccb9066 2022-11-08 20:18:10 +01:00
Sam McCall 38cccb9066 [include-cleaner] pass through recorded macro refs in walkUsed
Differential Revision: https://reviews.llvm.org/D137644
2022-11-08 20:10:39 +01:00