21 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
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
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
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
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
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
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
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
Haojian Wu
67b72a2890 [tooling] use std::optional in tooling StandardLibrary.h/.cpp, NFC 2022-12-08 13:49:09 +01:00
Kazu Hirata
5891420e68 [clang] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
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
2022-12-03 11:54:46 -08:00
Sam McCall
d03ee70de1 [Tooling] Avoid StandardLibrary.h including Decl. NFC
So you can use the enum in a header without pulling in half the AST.
2022-10-25 19:12:45 +02:00
Kadir Cetinkaya
d1f13c54f1
[clang][Tooling] Move STL recognizer to its own library
As pointed out in https://reviews.llvm.org/D119130#3829816, this
introduces a clang AST dependency to the clangToolingInclusions, which is used
by clang-format.

Since rest of the inclusion tooling doesn't depend on clang ast, moving this
into a separate library.

Differential Revision: https://reviews.llvm.org/D135245
2022-10-06 10:09:13 +02:00