83 Commits

Author SHA1 Message Date
kadir çetinkaya
756c20561e
[clang][Tooling] Add special symbol mappings for C, starting with size_t (#85784) 2024-03-20 08:48:06 +01:00
j-jorge
984dd15d4d
[clang-format] Add MainIncludeChar option. (#78752)
Resolves #27008, #39735, #53013, #63619.

Hello, this PR adds the MainIncludeChar option to clang-format, allowing
to select which include syntax must be considered when searching for the
main header: quotes (`#include "foo.hpp"`, the default), brackets
(`#include <foo.hpp>`), or both.

The lack of support for brackets has been reported many times, see the
linked issues, so I am pretty sure there is a need for it :)

A short note about why I did not implement a regex approach as discussed
in #53013: while a regex would have allowed many extra ways to describe
the main header, the bug descriptions listed above suggest a very simple
need: support brackets for the main header. This PR answers this needs
in a quite simple way, with a very simple style option. IMHO the feature
space covered by the regex (again, for which there is no demand :)) can
be implemented latter, in addition to the proposed option.

The PR also includes tests for the option with and without grouped
includes.
2024-02-06 01:06:33 -08:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
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-13 08:54:13 -08:00
Krzysztof Parzyszek
764c3afd43
[Tooling/Inclusion] Avoid narrowing conversions in macro expansion (#72664)
```
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp:144:65: warning:
 narrowing conversion of ‘llvm::StringRef(((const char*)"std::experiment
al::filesystem::")).llvm::StringRef::size()’ from ‘size_t’ {aka ‘long un
signed int’} to ‘unsigned int’ [-Wnarrowing]
  144 | #define SYMBOL(Name, NS, Header) {#NS #Name, StringRef(#NS).size
(), #Header},
      |                                              ~~~~~~~~~~~~~~~~~~~
^~
clang/lib/Tooling/Inclusions/Stdlib/StdTsSymbolMap.inc:51:1: note: in ex
pansion of macro ‘SYMBOL’
   51 | SYMBOL(temp_directory_path, std::experimental::filesystem::, <ex
perimental/filesystem>)
      | ^~~~~~
```
2023-11-17 10:53:43 -06:00
Haojian Wu
80db833c75
[tooling/include-mapping] Add missing localtime_r symbols (#66091)
Fixes https://github.com/llvm/llvm-project/issues/64587.
2023-10-25 15:37:04 +02:00
Benjamin Kramer
24f068b0f7 [Tooling/Inclusion] Fix MSVC build 2023-10-24 13:32:21 +02:00
Benjamin Kramer
4674e303d2 [Tooling/Inclusion] Refactor to use tables for compile time
The macro expansion takes 13s and generates an 1.5M obj file, table uses
2s and 680k .o file.

Sanitizers take multiple minutes to compile the old version, while
having negligible overhead on the new version.

No change in functionality.
2023-10-24 13:15:02 +02:00
Alexander Smarus
c6f0f8810d
Workaround for MSVC ARM64 build performance regression (#65215)
MSVC has a major performance regression observed when targeting ARM64
since v19.32 (VS 17.2.0). `cl.exe` spends a lot of time on compiling
`StandardLibrary.cpp` and `CGBuiltin.cpp`, and total build duration
rises extremely. This makes builds stagnate even on a real hardware, but
VM-based builds (like building on cloud agents from GitHub Actions and
Azure Pipelines) are experiencing most damage as they also performance-
and time-limited.

The issue appears to be related to some optimizations applied in `/O2`
mode. It is reported on [Developer
Community](https://developercommunity.visualstudio.com/t/Compiling-a-specific-code-for-ARM64-with/10444970).
While the investigation is in progress, we could apply a workaround to
improve build time. `/O2` actually enables a set of optimizations, and
only one of them does all slowdown. The idea is to disable
optimizations, and then apply all but one back, effectively excluding
the problematic option from the set.

This patch alters the CMake configuration for aforementioned files.
Changes are limited to:
- non-debug builds
- MSVC of the specific version
- target arch (ARM64).
2023-10-20 22:47:12 +05:30
Jan Svoboda
3661a48a84 [clang] NFCI: Use FileEntryRef in SourceManager::getMemoryBufferForFileOr{None,Fake}() 2023-09-29 10:31:42 -07:00
Jan Svoboda
b0abc9dd44 [clang] NFCI: Use FileEntryRef in ASTReader::GetHeaderFileInfo()
This is the `ASTReader` counterpart to PR #67383.
2023-09-29 09:07:13 -07:00
Viktoriia Bakalova
6258912880 [clangd][clang-tidy] Add missing symbols to the symbol map.
Differential Revision: https://reviews.llvm.org/D159462
2023-09-06 13:42:12 +00:00
Viktoriia Bakalova
8a5c0ccee2 [clangd][clang-tidy][std_symbol_map] Add missing symbol.
Differential Revision: https://reviews.llvm.org/D157256
2023-08-07 08:41:58 +00:00
Viktoriia Bakalova
5d492766a8 [clangd][clang-tidy][stdlib] Add a missing symbol to the mapping.
Differential Revision: https://reviews.llvm.org/D157093
2023-08-04 14:15:01 +00:00
Haojian Wu
171868dc2c [Tooling/Inclusion] Add std::range symbols in the mapping.
Fixes https://github.com/llvm/llvm-project/issues/64191

Differential Revision: https://reviews.llvm.org/D156648
2023-07-31 13:05:47 +02:00
Haojian Wu
e93cbd18c1 [Tooling/Inclusion] Make the Recognizer work for C99 code.
C99 is the the earliest C version provided by the language opt.

Differential Revision: https://reviews.llvm.org/D155816
2023-07-25 15:48:21 +02:00
Haojian Wu
85c6d57eb3 [Format][Tooling] Fix HeaderIncludes::insert not respect the main-file header.
Differential Revision: https://reviews.llvm.org/D154963
2023-07-13 10:41:46 +02:00
Kadir Cetinkaya
80c6792200
[clang][Tooling] Add mapping for make_error_code
Differential Revision: https://reviews.llvm.org/D154473
2023-07-05 09:35:28 +02:00
Haojian Wu
c91ee293f9 [Tooling/Inclusion] Add missing PRI family macros.
Differential Revision: https://reviews.llvm.org/D152792
2023-06-13 13:33:53 +02:00
Haojian Wu
3ddd18640a [Tooling] NFC, use const HeaderSearch for isSelfContainedHeader. 2023-06-01 15:17:21 +02:00
Kazu Hirata
ed1539c6ad Migrate {starts,ends}with_insensitive to {starts,ends}_with_insensitive (NFC)
This patch migrates uses of StringRef::{starts,ends}with_insensitive
to StringRef::{starts,ends}_with_insensitive so that we can use names
similar to those used in std::string_view.

Note that the llvm/ directory has migrated in commit
6c3ea866e93003e16fc55d3b5cedd3bc371d1fde.

I'll post a separate patch to deprecate
StringRef::{starts,ends}with_insensitive.

Differential Revision: https://reviews.llvm.org/D150506
2023-05-16 10:12:42 -07:00
NAKAMURA Takumi
077a2a4bcd [CMake] Cleanup deps 2023-04-17 00:38:49 +09:00
Haojian Wu
586e497f79 [Tooling/Inclusion] Index more sub std namespace symbols.
Fixes https://github.com/llvm/llvm-project/issues/61373

Differential Revision: https://reviews.llvm.org/D146021
2023-03-14 13:08:44 +01:00
Haojian Wu
22c0ce9691 [Tooling/Inclusion] Add atomic family symbols
Differential Revision: https://reviews.llvm.org/D145557
2023-03-09 09:21:18 +01:00
Haojian Wu
404b1b2ed4 [Tooling/Inclusion] Add missing placerholder _1 symbols.
Differential Revision: https://reviews.llvm.org/D145553
2023-03-09 09:20:42 +01:00
Haojian Wu
7eb36f5d87 [Tooling/Inclusion] Add missing index_sequence symbols.
Fixes https://github.com/llvm/llvm-project/issues/61026

Differential Revision: https://reviews.llvm.org/D145365
2023-03-06 14:09:49 +01:00
Haojian Wu
4416e4a9ed [Tooling/Inclusion] Add the generic abs symbol to the table.
Fixes https://github.com/llvm/llvm-project/issues/60964

Differential Revision: https://reviews.llvm.org/D144721
2023-02-24 13:56:00 +01:00
Haojian Wu
c86f05dd48 [Tooling/Inclusion] Add the missing NULL symbol to the table.
Differential Revision: https://reviews.llvm.org/D144713
2023-02-24 12:59:52 +01:00
Kadir Cetinkaya
385c8cd3cd
[Tooling][Inclusions] Add c-header and global namespace alternatives for size_t
Differential Revision: https://reviews.llvm.org/D144646
2023-02-24 10:44:33 +01:00
Kadir Cetinkaya
5a623c2a08
Revert "Revert "[Tooling/Inclusion] Handle std::get symbol.""
This reverts commit 7c9b15fbaeb2846ad25e797d55ffe1ccef9e1379. Breakage
was in downstream code.
2023-02-24 01:24:53 +01:00
Caroline Tice
7c9b15fbae Revert "[Tooling/Inclusion] Handle std::get symbol."
This reverts commit cbcb3eef70def3509bdffd4fe1ebfb6422afeaa2.

Causing many clangd test breakages, similar to:

error: no matching constructor for initialization of 'llvm::SmallVector<clang::tooling::stdlib::Header>'
                : llvm::SmallVector<clang::tooling::stdlib::Header>(
                  ^
2023-02-23 15:18:17 -08:00
Haojian Wu
cbcb3eef70 [Tooling/Inclusion] Handle std::get symbol.
Currently, we handle it as a symbol without a header. In general, for
the include-cleaner case, the std::get comes with the type header, it is
safe to ignore it.

Differential Revision: https://reviews.llvm.org/D144484
2023-02-23 10:26:26 +01:00
Kadir Cetinkaya
46cdf7f099
[Tooling][Stdlib][NFC] Reflow comments and strip clang-format pragmas 2023-02-14 09:46:41 +01:00
Younan Zhang
d4021ed3d7 [Tooling/Inclusion] Add symbol mappings for std::experimental::filesystem
Clangd maintains a symbol map from standard library, in order to prevent
unexpected header/symbol leaks from internal files. (e.g. files under
`bits/` for libstdc++) This symbol map was generated by a python script
that parses pages of offline cppreference archive. The script didn't
handle the case for `std::experimental::`, where most symbols are from
TS. It works well as symbols are directly laid out in the corresponding
header under `experimental` directory for most of time.

However, libstdc++'s implementation split symbols of TS FS into a few
header files located in `experimental/bits`. This would make the code
completion provide internal headers when we simply select the symbols.

There are slightly differences between TS FS and C++17 FS. Some
functions like `system_complete` was replaced by `absolute` and
relative-related operations were introduced later by another proposal.
Even so, all mainstream implementation are based on N4100, the final
filesystem TS draft that was published in 2014 and from which symbols
we've added are exported.

This fixes https://github.com/clangd/clangd/issues/1481

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D142836
2023-02-14 01:07:39 +08:00
Haojian Wu
11dcd88577 [Tooling/Inclusion] Use the StdSpecialSymbolMap.inc in the stdlib
Remove a special-case in clangd.

Differential Revision: https://reviews.llvm.org/D143559
2023-02-10 00:04:23 +01:00
Haojian Wu
c812ab7312 [include-mapping] Add C-compatibility symbol entries.
Extending the python generator:
- to generate C-compatibility symbols
- to generate macros

Differential Revision: https://reviews.llvm.org/D143214
2023-02-09 15:34:41 +01:00
Haojian Wu
98e7670b64 [Tooling/Inclusion] Add more multi-header symbols to StdSpecialSymbolMap.inc
Differential Revision: https://reviews.llvm.org/D143569
2023-02-08 20:15:47 +01:00
Viktoriia Bakalova
4da283872a [include-mapping] Regenerate the StdSymbolMap.inc from the 20220730 html book.
Merge the zoombie names into the StdSymbols as well.

Differential Revision: https://reviews.llvm.org/D143054
2023-02-07 14:52:18 +01:00
Haojian Wu
3599cbd3f6 [include-mapping] Better #includes support for std input/output symbols
Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D143280
2023-02-07 14:19:32 +01:00
Haojian Wu
1ab62d9d8e [Tooling/Inclusion] Support multiple headers in the stdlib APIs.
Unittest will be added in https://reviews.llvm.org/D143280

Patch by Viktoriia Bakalova.

Differential Revision: https://reviews.llvm.org/D142092
2023-02-07 14:18:13 +01:00
Haojian Wu
8a09d60b71 [Tooling/Inclusion] Move the StdSpecialSymbolMap.inc to the private lib place.
I missed it in c751264aa19865beab12d94db3ea966c6accd428.
2023-02-07 10:31:41 +01:00
Haojian Wu
c751264aa1 [Tooling/Inclusion] Move the generated mapping .inc file to private places.
The .inc files are private now, clients should tooling::stdlib APIs instead.

Differential Revision: https://reviews.llvm.org/D143399
2023-02-07 10:07:05 +01:00
Haojian Wu
d46d44e3c4 [Tooling/Inclusion] qualifed_name() => qualifiedName(), NFC 2023-02-04 00:08:45 +01:00
Viktoriia Bakalova
1285172c21 [include-mapping] Implement language separation in stdlib recognizer library
Differential Revision: https://reviews.llvm.org/D142992
2023-02-03 17:05:25 +01:00
Haojian Wu
0bf58458d3 [Tooling/Inclusions] ensure the Mapping is inititalized in
Symbol/Header::all() calls
2023-02-03 16:10:05 +01:00
Sam McCall
e1aaa314a4 [Tooling] Add stdlib::Symbol::all() and stdlib::Symbol::qualified_name()
These address some remaining reasons to #include StdSymbolMap.inc directly.

Differential Revision: https://reviews.llvm.org/D142467
2023-02-03 13:22:26 +01:00
Kazu Hirata
2d861436a9 [clang] Remove remaining uses of llvm::Optional (NFC)
This patch removes several "using" declarations and #include
"llvm/ADT/Optional.h".

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
2023-01-14 13:37:25 -08:00
Kazu Hirata
6ad0788c33 [clang] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to remove #include "llvm/ADT/Optional.h".

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
2023-01-14 12:31:01 -08:00
Kazu Hirata
a1580d7b59 [clang] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

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
2023-01-14 11:07:21 -08:00
Haojian Wu
58c9467f58 Use std::optional in Tooling/Inclusions. 2022-12-12 16:01:56 +01:00
Haojian Wu
67b72a2890 [tooling] use std::optional in tooling StandardLibrary.h/.cpp, NFC 2022-12-08 13:49:09 +01:00