41 Commits

Author SHA1 Message Date
Kazu Hirata
732bccb8c1 Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-14 07:53:20 -08:00
Jan Svoboda
cb92511c4d
[clang] NFC: Remove OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr (#74900) 2023-12-08 18:22:53 -08:00
Jan Svoboda
98e6deb62c [clang][tools] Use FileEntryRef in include_cleaner::Header 2023-09-09 09:54:13 -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
Kadir Cetinkaya
90ecadde62
[include-cleaner] Filter references to identity macros
Despite being true positives, these results just confuse users. So
filter them out.

Differential Revision: https://reviews.llvm.org/D157905
2023-08-18 14:40:03 +02:00
Kadir Cetinkaya
43974333dd
[include-cleaner] Unify always_keep with rest of the keep logic
Depends on D156122

Differential Revision: https://reviews.llvm.org/D156123
2023-08-02 12:47:53 +02:00
Kadir Cetinkaya
778a5e9bc6
[include-cleaner] Introduce support for always_keep pragma
Differential Revision: https://reviews.llvm.org/D156122
2023-08-02 12:47:53 +02:00
Sam McCall
f6307b260b [include-cleaner] Switch Include from FileEntry* -> FileEntryRef
Unlike Header, we really do have a preferred spelling for an include: the one
that we used to open the file.

The fact that Header is still FileEntry* makes it difficult to accidentally
use path equality when we want inode equality.

Differential Revision: https://reviews.llvm.org/D155885
2023-07-26 13:41:55 +02:00
Haojian Wu
7f3d2cd7ec [include-cleaner] Fix the fixIncludes API not respect main-file header.
The fixIncludes was using the `input` as the main file path, this will
results in inserting header at wrong places.

We need the main file path to so that we can get the real main-file
header.

Differential Revision: https://reviews.llvm.org/D154950
2023-07-11 15:02:26 +02:00
Haojian Wu
507d766d76 [include-cleaner] Add an IgnoreHeaders flag to the command-line tool.
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D153340
2023-07-06 11:18:44 +02:00
Haojian Wu
3b59842a72 [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC
This will bring down the size from 40 bytes to 32 bytes.

Differential Revision: https://reviews.llvm.org/D153018
2023-06-16 10:21:44 +02:00
Viktoriia Bakalova
90c5fe9822 [include-cleaner] Allow multiple strategies for spelling includes.
Summary:

Reviewers:

Subscribers:

Differential Revision: https://reviews.llvm.org/D150185
2023-06-05 09:47:12 +00:00
Haojian Wu
7de541235f [include-cleaner] NFC, use const HeaderSearch when possible. 2023-06-01 15:26:19 +02:00
Viktoriia Bakalova
481f888536 [clangd] Use expansion location for missing include diagnostics.
Differential Revision: https://reviews.llvm.org/D146727
2023-03-27 14:26:12 +00:00
Kadir Cetinkaya
f5b6e9b6d3
[include-cleaner] Fix crash on unresolved headers
Make sure unresolved headers are not analyzed as part of unused
includes.

Also introduces a testing fixture for analyze tests

Differential Revision: https://reviews.llvm.org/D146916
2023-03-26 16:37:56 +02:00
Kadir Cetinkaya
43fcfdb1d6
[IncludeCleaner][clangd] Mark umbrella headers as users of private
Private headers inside umbrella files shouldn't be marked as unused.

Differential Revision: https://reviews.llvm.org/D146406
2023-03-23 13:08:07 +01:00
Viktoriia Bakalova
2e82eb1f74 Re-land [clangd] Add support for missing includes analysis.
This reverts commit fd8c9ef20a9519dccd5b8178b29ed4574285d36f.

Differential Revision: https://reviews.llvm.org/D145577
2023-03-08 13:29:52 +00:00
Viktoriia Bakalova
fd8c9ef20a Revert "Re-land [clangd] Add support for missing includes analysis."
This reverts commit 85a5c17b66768353b7fff717904e42805bb6a547.
2023-03-08 12:34:15 +00:00
Viktoriia Bakalova
46447e0ba2 Revert "Revert "Re-land [clangd] Add support for missing includes analysis.""
This reverts commit 9814b4d07f614e83e7a244f74fc562f2b5cc9b15.
2023-03-08 12:27:17 +00:00
Viktoriia Bakalova
9814b4d07f Revert "Re-land [clangd] Add support for missing includes analysis."
This reverts commit 85a5c17b66768353b7fff717904e42805bb6a547.
2023-03-08 12:24:51 +00:00
Viktoriia Bakalova
85a5c17b66 Re-land [clangd] Add support for missing includes analysis.
This reverts commit 2eb5ac99a76dbbf8ac68c538211fabeaa5ac0bfd.
2023-03-08 11:02:12 +00:00
Nico Weber
2eb5ac99a7 Revert "[clangd] Add support for missing includes analysis."
This reverts commit 38b9fb5a129db3e086610d53b534833273c5b4d0.
Breaks tests on Windows, see comments on https://reviews.llvm.org/D143496
2023-03-07 22:14:11 -05:00
Viktoriia Bakalova
38b9fb5a12 [clangd] Add support for missing includes analysis.
Differential Revision: https://reviews.llvm.org/D143496
2023-03-07 16:07:19 +00:00
Kadir Cetinkaya
749c6a7083
[include-cleaner] Ranking of providers based on hints
Introduce signals to rank providers of a symbol.

Differential Revision: https://reviews.llvm.org/D139921
2023-01-23 15:22:47 +01:00
Kadir Cetinkaya
b76cc30e15
[include-cleaner] Respect IWYU pragmas during analyze
Fixes https://github.com/llvm/llvm-project/issues/59541.

Differential Revision: https://reviews.llvm.org/D140380
2022-12-20 10:47:22 +01:00
Haojian Wu
bf6e655162 [include-cleaner] Filter out references that not spelled in the main file.
A HTML report of gtest after this patch:
cf05a50351/RecordTest.html

Differential Revision: https://reviews.llvm.org/D138779
2022-12-09 12:59:34 +01:00
Haojian Wu
526fb5fae7 [include-cleaner] Fix walkUsed only report a single macro ref.
The fix 962343a979d51cea9363167e9121c446abbdfdbc was reverted during a
rebase of a later patch. Added a test.
2022-12-09 12:12:16 +01:00
Kadir Cetinkaya
29a8eec1f9
[include-cleaner] Make use of locateSymbol in WalkUsed and HTMLReport
Depens on D135953

Differential Revision: https://reviews.llvm.org/D138200
2022-12-06 15:03:11 +01:00
Sam McCall
1a8dd74258 [include-cleaner] clang-include-cleaner can print/apply edits
This adds command-line flags to the tool:
+ -print: prints changed source code
+ -print=changes: prints headers added/removed
+ -edit: rewrites code in place
+ -insert=0/-remove=0: disables additions/deletions for the above

These are supported by a couple of new functions dumped into Analysis:
analyze() sits on top of walkUsed and makes used/unused decisions for
Includes. fixIncludes() applies those results to source code.

Differential Revision: https://reviews.llvm.org/D139013
2022-12-02 13:16:58 +01:00
Haojian Wu
962343a979 [include-cleaner] Fix walkUsed only report a single macro ref. 2022-11-28 10:12:10 +01: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
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
Haojian Wu
e000c2bce7 [include-cleaner] NFC, move the macro location fixme to findHeaders. 2022-11-11 14:55:29 +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
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
Sam McCall
c333b92b72 [include-cleaner] Missing changes from 38cccb906603 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
Kadir Cetinkaya
d19ba74dee
[Includecleaner] Introduce RefType to ast walking
RefTypes are distinct categories for each reference to a symbol. They
are signals indicating strength of a reference, that'll enable different
decision making based on the finding being provided.

There are 3 kinds of ref types:
- Explicit, the reference is spelled in the code.
- Implicit, the reference is not directly visible in the code.
- Ambigious, the reference exists but can't be proven as used (e.g.
  overloads brought in by a using decl but not used by the code).

Differential Revision: https://reviews.llvm.org/D135859
2022-11-08 16:29:31 +01:00
Sam McCall
3e067d4e59 [include-cleaner] Move vocabulary types into separate header for layering. NFC 2022-10-25 19:01:59 +02:00
Kadir Cetinkaya
ce286eccac
[IncludeCleaner] Add public API
Introduces walkUsed, a very simple version of the public API to enable
incremental development on rest of the pieces.

Differential Revision: https://reviews.llvm.org/D136293
2022-10-24 17:06:15 +02:00