aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-15[clang] Remove unused includes (NFC) (#144285)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-12[NFC] Optimize file kind determination (#139492)Serge Pavlov1-2/+1
There are checks in clang codebase that determine the type of source file, associated with a given location - specifically, if it is an ordonary file or comes from sources like command-line options or a built-in definitions. These checks often rely on calls to `getPresumedLoc`, which is relatively expensive. In certain cases, these checks are combined, leading to repeated calculations of the costly function negatively affecting compile time. This change tries to optimize such checks. It must fix compile time regression introduced in https://github.com/llvm/llvm-project/pull/137306/. --------- Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2024-09-25[clang] Make deprecations of some `FileManager` APIs formal (#110014)Jan Svoboda1-2/+2
Some `FileManager` APIs still return `{File,Directory}Entry` instead of the preferred `{File,Directory}EntryRef`. These are documented to be deprecated, but don't have the attribute that warns on their usage. This PR marks them as such with `LLVM_DEPRECATED()` and replaces their usage with the recommended counterparts. NFCI.
2024-09-03[clang][ExtractAPI] Remove erroneous module name check in MacroCallbacks ↵Daniel Grumberg1-1/+1
(#107059) rdar://135044923
2024-08-27[clang][ExtractAPI] Fix quirks in interaction with submodules (#105868)Daniel Grumberg1-54/+36
Extension SGFs require the module system to be enabled in order to discover which module defines the extended external type. This patch ensures the following: - Associate symbols with their top level module name, and that only top level modules are considered as modules for emitting extension SGFs. - Ensure we don't drop macro definitions that came from a submodule. To this end look at all defined macros in `PPCalbacks::EndOfMainFile` instead of relying on `PPCallbacks::MacroDefined` being called to detect a macro definition.
2024-04-03Reenable external categories (#87357)Daniel Grumberg1-59/+53
Reenables b31414bf4f9898f7817a9fcf8a91f62ec26f3eaf. Also adds a new warning for missing `--symbol-graph-dir` arg when `--emit-extension-symbol-graphs` is provided. This also reverts the commit that removed.
2024-04-02Revert "[clang][ExtractAPI] Add ability to create multiple symbol graphs ↵Daniel Grumberg1-53/+59
(#86676)" This failed the test suite due to missing DiagGroup for a new warning. This reverts commit b31414bf4f9898f7817a9fcf8a91f62ec26f3eaf.
2024-04-02[clang][ExtractAPI] Add ability to create multiple symbol graphs (#86676)Daniel Grumberg1-59/+53
This extends ExtractAPI to take into account symbols defined in categories to types defined in an external module. This introduces 2 new command line flags, `--symbol-graph-dir=DIR` and `--emit-extension-symbol-graphs`, when used together this generates additional symbol graph files at `DIR/ExtendedModule@ProductName.symbols.json` for each external module that is extended in this way. Additionally this makes some cleanups to tests to make them more resilient and cleans up the `APISet` data structure.
2024-02-20[clang][InstallAPI] Add input file support to library (#81701)Cyndy Ishida1-4/+3
This patch adds support for expected InstallAPI inputs. InstallAPI accepts a well defined filelist of headers and how those headers represent a single library. InstallAPI captures header files to determine linkable symbols to then compare against what was compiled in a binary dylib and generate TBD files.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-2/+2
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-01[clang][ExtractAPI] Ensure LocationFileChecker doesn't try to traverse VFS ↵Daniel Grumberg1-3/+8
when determining file path (#74071) As part of https://reviews.llvm.org/D154130 the logic of LocationFileChecker changed slightly to try and get the absolute external file path instead of the name as requested when the file was openened which would be before VFS mappings in our usage. Ensure that we only check against the name as requested instead of trying to generate the external canonical file path. rdar://115195433
2023-09-13[clang] NFCI: Use `FileEntryRef` in `FileManager::getCanonicalName()`Jan Svoboda1-6/+6
2023-08-01[lit][clang] Avoid realpath on Windows due to MAX_PATH limitationsSaleem Abdulrasool1-3/+1
Running lit tests on Windows can fail because its use of `os.path.realpath` expands substitute drives, which are used to keep paths short and avoid hitting MAX_PATH limitations. Changes lit logic to: Use `os.path.abspath` on Windows, where `MAX_PATH` is a concern that we can work around using substitute drives, which `os.path.realpath` would resolve. Use `os.path.realpath` on Unix, where the current directory always has symlinks resolved, so it is impossible to preserve symlinks in the presence of relative paths, and so we must make sure that all code paths use real paths. Also updates clang's `FileManager::getCanonicalName` and `ExtractAPI` code to avoid resolving substitute drives (i.e. resolving to a path under a different root). How tested: built with `-DLLVM_ENABLE_PROJECTS=clang` and built `check-all` on both Windows Differential Revision: https://reviews.llvm.org/D154130 Reviewed By: @benlangmuir Patch by Tristan Labelle <tristan@thebrowser.company>!
2023-07-03[clang][ExtractAPI] Add --emit-symbol-graph optionAnkur1-20/+140
Add new --emit-symbol-graph=<DIR> option which generates ExtractAPI symbol graph information of .c/.m files on regular compilation job and put them in the provided "DIR" directory. Reviewed By: dang Differential Revision: https://reviews.llvm.org/D152356
2023-03-30[clang][ExtractAPI] Reland ExtractAPI for libclang improvementsDaniel Grumberg1-2/+28
This relands the changes that were originally introduced by: - https://reviews.llvm.org/D146656 - https://reviews.llvm.org/D147138 This also fixes the leak that led to these changes being reverted Differential Revision: https://reviews.llvm.org/D147234
2023-03-29Revert "Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656""Mitch Phillips1-28/+2
This reverts commit 79116475124112051625b1a0665e35c861bb13fd. Broke the ASan bots. See more information in https://reviews.llvm.org/rG79116475124112051625b1a0665e35c861bb13fd
2023-03-29Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656"Daniel Grumberg1-2/+28
This reverts commit 158a431227a876306fe5838936413dd51588d0c6.
2023-03-27Revert ExtractAPI from https://reviews.llvm.org/D146656Daniel Grumberg1-28/+2
2023-03-27Address code review feedbackDaniel Grumberg1-1/+1
2023-03-27[clang][ExtractAPI] Refactor ExtractAPIVisitor to make it more extensibleDaniel Grumberg1-3/+29
Use CRTP to enable creating statically dispatched subclasses of ExtractAPIVisitor. This enables adding extension points and customising the behavior more easily. This is used in CXExtractAPI.cpp to create a specialized visitor for Libclang as well as streamlining the batch implementation in ExtractAPIConsumer.cpp
2023-03-13[clang][ExtractAPI] Add multiple file support to --extract-api-ignoresAnkur1-2/+2
- Modify -extract-api-ignores command line option to accept multiple arguments - Update APIIgnoresList to operate on a file list instead of a single file - Add new test verifying the functionality - fix #61242 on GitHub issue tracker Reviewed By: dang Differential Revision: https://reviews.llvm.org/D145869
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-3/+3
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
2022-12-13[clang][ExtractAPI] Add support for single symbol SGF and libclang supportDaniel Grumberg1-536/+13
This is mainly adding an entry point to `SymbolGraphSerializer` at `serializeSingleSymbolSGF` and exposing the necessary data to make this possible. Additionaly there are some changes to how symbol kinds and path components are serialized to make the usage more ergonomic in `serializeSingleSymbolSGF`. On the libclang side this introduces APIs to: - create an APISet from a TU - dispose of an APISet - query an APISet for a single symbol SGF for a given USR. - generate a single symbol SGF for a given CXCursor, this only traverses the necessary AST nodes to construct the result as oppposed as going through the entire AST. Differential Revision: https://reviews.llvm.org/D139115
2022-12-09[ExtractAPI] Use std::optional in ExtractAPIConsumer.cpp (NFC)Kazu Hirata1-3/+4
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[clang] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
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-10-25[clang][ExtractAPI] Allow users to specify a list of symbols to ignoreDaniel Grumberg1-1/+16
Adds a `--extract-api-ignores=` command line option that allows users to provide a file containing a new line separated list of symbols to unconditionally ignore when extracting API information. Differential Revision: https://reviews.llvm.org/D136450
2022-10-13[clang][ExtractAPI] Ignore fully anonymous RecordDeclsDaniel Grumberg1-0/+3
ExtractAPI was emitting a separate symbol for anonymous record declaration that define the type of a member of another record declaration. Now ExtractAPI ignores these declarations and just records the existence of the actual member. Differential Revision: https://reviews.llvm.org/D135804
2022-10-05[clang][ExtractAPI] Don't print locations for anonymous tagsZixu Wang1-0/+5
ExtractAPI doesn't care about locations of anonymous TagDecls. Set the printing policy to exclude that from anonymous decl names. Differential Revision: https://reviews.llvm.org/D135295
2022-08-19[clang][ExtractAPI] Record availability information on all platformsDaniel Grumberg1-68/+27
Currently ExtractAPI only emits availability information for the current platform. This makes it easy for clients to get all availability information for a given symbol in one invocation as opposed to having to invoke clang once per-platform and then merge the symbol-graphs. Differential Revision: https://reviews.llvm.org/D130918
2022-07-22[NFC] Start saving InstantiatedFromDecl in non-template functionsErich Keane1-0/+1
In cases where a non-template function is defined inside a function template, we don't have information about the original uninstantiated version. In the case of concepts instantiation, we will need the ability to get back to the original template. This patch splits a piece of the deferred concepts instantaition patch off to accomplish the storage of this, with minor runtime overhead, and zero additional storage.
2022-07-01Revert "Re-apply "Deferred Concept Instantiation Implementation"""Erich Keane1-1/+0
This reverts commit befa8cf087dbb8159a4d9dc8fa4d6748d6d5049a. Apparently this breaks some libc++ builds with an apparent assertion, so I'm looking into that .
2022-07-01Re-apply "Deferred Concept Instantiation Implementation""Erich Keane1-0/+1
This reverts commit d4d47e574ecae562ab32f8ac7fa3f4d424bb6574. This fixes the lldb crash that was observed by ensuring that our friend-'template contains reference to' TreeTransform properly handles a TemplateDecl.
2022-06-30Revert "Deferred Concept Instantiation Implementation"Jonas Devlieghere1-1/+0
This reverts commit 2f207439521d62d9551b2884158368e8b34084e5 because it triggers an assertion when building an LLDB test program: Assertion failed: (InstantiatingSpecializations.empty() && "failed to clean up an InstantiatingTemplate?"), function ~Sema, file /Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/clang/lib/Sema/Sema.cpp, line 458. More details in https://reviews.llvm.org/D126907.
2022-06-30Deferred Concept Instantiation ImplementationErich Keane1-0/+1
This is a continuation of D119544. Based on @rsmith 's feed back showing me https://eel.is/c++draft/temp#friend-9, We should properly handle friend functions now. Differential Revision: https://reviews.llvm.org/D126907
2022-06-12[clang] Use any_of and none_of (NFC)Kazu Hirata1-5/+5
2022-05-09Revert ""Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""""Erich Keane1-1/+0
This reverts commit a425cac31e2e4cee8e14b7b9a99c8ba17c1ebb52. There is another libc++ test, that this time causes us to hit an assertion. Reverting, likely for a while this time.
2022-05-09"Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""""Erich Keane1-0/+1
This includes a fix for the libc++ issue I ran across with friend declarations not properly being identified as overloads. This reverts commit 45c07db31cc76802a1a2e41bed1ce9c1b8198181.
2022-05-05[clang] Add static_cast to fix Bazel build.Adrian Kuegel1-1/+2
Differential Revision: https://reviews.llvm.org/D124995
2022-05-04Revert "Revert "[clang][extract-api] Use relative includes""Zixu Wang1-12/+178
Reapply the change after fixing sanitizer errors. The original problem was that `StringRef`s in `Matches` are pointing to temporary local `std::string`s created by `path::convert_to_slash` in the regex match call. This patch does the conversion up front in container `FilePath`. This reverts commit 2966f0fa505266735dbc8324b8821b7f0aa901ff. Differential Revision: https://reviews.llvm.org/D124964
2022-05-04Revert "[clang][extract-api] Use relative includes"Zixu Wang1-181/+12
This reverts commit 4c262fee08b5383c96857d77eefe80d61c41d2b0. Revert to fix Msan and Asan errors.
2022-05-04[clang][extract-api] Use relative includesZixu Wang1-12/+181
This patch transforms the given input headers to relative include names using header search entries and some heuritics. For example: `/Path/To/Header.h` will be included as `<Header.h>` with a search path of `-I /Path/To/`; and `/Path/To/Framework.framework/Headers/Header.h` will be included as `<Framework/Header.h>`, given a search path of `-F /Path/To`. Headermaps will also be queried in reverse to find a spelled name to include headers. Differential Revision: https://reviews.llvm.org/D123831
2022-05-02Revert "Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""Erich Keane1-1/+0
This reverts commit a97899108e495147985e5e9492e742d51d5cc97a. The patch caused some problems with the libc++ `__range_adaptor_closure` that I haven't been able to figure out the cause of, so I am reverting while I figure out whether this is a solvable problem/issue with the CFE, or libc++ depending on an older 'incorrect' behavior.
2022-05-02Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""Erich Keane1-0/+1
This reverts commit 0c31da48389754822dc3eecc4723160c295b9ab2. I've solved the issue with the PointerUnion by making the `FunctionTemplateDecl` pointer be a NamedDecl, that could be a `FunctionDecl` or `FunctionTemplateDecl` depending. This is enforced with an assert.
2022-05-02Revert "Deferred Concept Instantiation Implementation"Erich Keane1-1/+0
This reverts commit 4b6c2cd647e9e5a147954886338f97ffb6a1bcfb. The patch caused numerous ARM 32 bit build failures, since we added a 5th item to the PointerUnion, and went over the 2-bits available in the 32 bit pointers.
2022-05-02Deferred Concept Instantiation ImplementationErich Keane1-0/+1
As reported here: https://github.com/llvm/llvm-project/issues/44178 Concepts are not supposed to be instantiated until they are checked, so this patch implements that and goes through significant amounts of work to make sure we properly re-instantiate the concepts correctly. Differential Revision: https://reviews.llvm.org/D119544
2022-04-28Frontend: Delete output streams before closing CompilerInstance outputsDuncan P. N. Exon Smith1-1/+1
Delete the output streams coming from CompilerInstance::createOutputFile() and friends once writes are finished. Concretely, replacing `OS->flush()` with `OS.reset()` in: - `ExtractAPIAction::EndSourceFileAction()` - `PrecompiledPreambleAction::setEmittedPreamblePCH()` - `cc1_main()'s support for `-ftime-trace` This fixes theoretical bugs related to proxy streams, which may have cleanups to run in their destructor. For example, a proxy that CompilerInstance sometimes uses is `buffer_ostream`, which wraps a `raw_ostream` lacking pwrite support and adds it. `flush()` does not promise that output is complete; `buffer_ostream` needs to wait until the destructor to forward anything so that it can service later calls to `pwrite()`. If the destructor isn't called then the proxied stream hasn't received any content. This also protects against some logic bugs, triggering a null dereference on a later attempt to write to the stream. No tests, since in practice these particular code paths never use use `buffer_ostream`; you need to be writing a binary file to a pipe (such as stdout) to hit it, but `-extract-api` writes a text file and the other two use computed filenames that will never (in practice) be a pipe. This is effectively NFC, for now. But I have some other patches in the works that add guard rails, crashing if the stream hasn't been destructed by the time the CompilerInstance is told to keep the output file, since in most cases this is a problem. Differential Revision: https://reviews.llvm.org/D124635
2022-04-12[clang][extract-api] Add support for true anonymous enumsDaniel Grumberg1-3/+6
Anonymous enums without a typedef should have a "(anonymous)" identifier. Differential Revision: https://reviews.llvm.org/D123533
2022-04-11[clang][extract-api] Emit "functionSignature" in SGF for ObjC methods.Daniel Grumberg1-2/+2
- Split GlobalRecord into two distinct types to be able to introduce has_function_signature type trait. - Add has_function_signature type trait. - Serialize function signatures as part of serializeAPIRecord for records that are known to have a function signature. Differential Revision: https://reviews.llvm.org/D123304
2022-04-07[clang][extract-api][NFC] Use dedicated API to check for macro equalityDaniel Grumberg1-8/+9
Differential Revision: https://reviews.llvm.org/D123295
2022-04-07[clang][extract-api] Process only APIs declared in inputsDaniel Grumberg1-7/+80
We should only process APIs declared in the command line inputs to avoid drowning the ExtractAPI output with symbols the user doesn't care about. This is achieved by keeping track of the provided input files and checking that the associated Decl or Macro is declared in one of those files. Differential Revision: https://reviews.llvm.org/D123148