118 Commits

Author SHA1 Message Date
QuietMisdreavus
63537872ae
ExtractAPI: use zero-based indices for line/column in symbol graph (#71753)
Other implementations of the symbol graph format use zero-based indices
for source locations, which causes problems when combined with clang's
current one-based indices. This commit sets ExtractAPI's symbol graph
output to use zero-based indices to align with other implementations.

rdar://107639783
2023-11-14 11:46:12 +00:00
Daniel Grumberg
6b43764a95
[clang][ExtractAPI] Update availability serialization in SGF (#71418)
The prevailiing symbol graph parsing library expects availability
attributes to just be "introduced" instead of "introducedVersion"

rdar://117823923
2023-11-07 10:44:45 +00:00
Vlad Serebrennikov
4ad2ada521 [clang][NFC] Refactor ElaboratedTypeKeyword
This patch moves ElaboratedTypeKeyword before `Type` definition so that the enum is complete where bit-field for it is declared. It also converts it to scoped enum and removes `ETK_` prefix.
2023-10-31 20:46:07 +03:00
Vlad Serebrennikov
49fd28d960 [clang][NFC] Refactor ArrayType::ArraySizeModifier
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-31 18:06:34 +03:00
Kazu Hirata
18d199116f Stop including llvm/ADT/STLFunctionalExtras.h (NFC)
These source files do not use function_ref.
2023-10-13 20:50:58 -07:00
Manna, Soumi
06c9cc7eaa [NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto
Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D159474
2023-09-28 09:00:55 -07:00
Jan Svoboda
5a3130e3b6 [clang] NFCI: Use FileEntryRef in FileManager::getCanonicalName() 2023-09-13 15:31:58 -07:00
Antonio Frighetto
ffb8434f6a [clang] Prevent unnecessary copies in SymbolGraphSerializer (NFC) 2023-09-08 17:19:06 +02:00
Elizabeth Andrews
847186eb94 [NFC][Clang] Fix static analyzer concern
Fix a few static analyzer concerns about dereferencing
null value.

Differential Revision: https://reviews.llvm.org/D158671
2023-08-25 13:03:06 -07:00
Erick Velez
e81744563a [clang][ExtractAPI] Fix bool spelling coming from the macro definition.
getFragmentsForType resulted in a bool typeIdentifier fragment to be spelled "_Bool".
This fixes the spelling to be "bool" and checks it in C and C++.

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D158474
2023-08-22 15:00:14 -07:00
Erick Velez
08f034f952 [clang][ExtractAPI] Add support for namespaces
Serialize namespaces, nested namespaces, and class relationships inside them.

Depends on D157076

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D158239
2023-08-22 09:56:34 -07:00
Erick Velez
3bb4855308 [clang][ExtractAPI] Refactor C++ method and field visitation
Refactor visitation for C++ record children by following the Visitor's CRTP.
Expand VisitCXXField, VisitCXXMethod for non-templates and introduce VisitCXXConstructor, VisitCXXDestructor.
Handle relationships by finding the parent's Record via USR from DeclContext.

Depends on D158029

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D158031
2023-08-21 10:38:01 -07:00
Erick Velez
634b2fd2ca [clang][ExtractAPI] Add support for C++ member templates
Visit and serialize C++ fields by checking if a var template's context is a CXXRecordDecl in VisitVarTemplateDecl.

Depends on D158027

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D158029
2023-08-21 10:17:58 -07:00
Erick Velez
d8e9c5d9ca [clang][ExtractAPI] Visit method templates with better scheme
Visit and serialize method templates and template specializations. Introduces a new scheme of visiting child Decls via VisitCXXMethodDecl which will be followed in future patches for Fields and non-template methods.

Depends on D157579

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D158027
2023-08-21 09:05:57 -07:00
Erick Velez
80b787e803 [clang][ExtractAPI] Add support for C++ global function templates
Add records, serialization for global function templates and their specializations

Depends on D157350

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D157579
2023-08-18 17:42:05 -07:00
Erick Velez
8d8c8981ca [clang][ExtractAPI] Add support for C++ variable templates
Serialize global C++ variable templates and specializations.

Depends on D157076

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D157350
2023-08-18 13:57:02 -07:00
Erick Velez
7ba37f4e46 [clang][ExtractAPI] Add support for C++ class templates and concepts
Add has_template template, DeclarationFragmentBuilder functions, and tests for class templates, specializations/partial specs, and concepts.

Depends on D157007

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D157076
2023-08-18 13:40:22 -07:00
Justin Bogner
314a5d707f Simplify a conditional in order to avoid a warning under MSVC
We were using some convoluted logic here to check if the result of a
`bool` returning function was false, causing MSVC to give a warning
about "'>': unsafe use of type 'bool' in operation". This just removes
the greater-than comparison of the bool against zero.
2023-08-16 16:19:57 -07:00
ruturaj4
1849318539 [clang][ExtractAPI] Add support for Objective-C categories
Differential Revision: https://reviews.llvm.org/D152770
2023-08-15 10:34:21 -05:00
Erick Velez
75f55eb331 [clang][ExtractAPI] Add support for C++ classes with fix
Reintroduce D153557 with fix for use-after-free from f4de606ef271 and minor changes.

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D157007
2023-08-04 07:19:24 -07:00
Erick Velez
20f7cc0df3 Revert "[clang][ExtractAPI] Add support for C++ classes"
This reverts commit 8b76b44e46ac5b4efbf8cb3702f09d353af2a112.
2023-08-02 13:23:45 -07:00
Augie Fackler
f4de606ef2 fix use-after-free introduced in 8b76b44e46ac
ASan catches this easily enough.
2023-08-02 14:38:08 -04:00
Erick Velez
8b76b44e46 [clang][ExtractAPI] Add support for C++ classes
Add ExtractAPI support C++ classes, fields,  methods, and various qualifiers and specifiers

Differential Revision: https://reviews.llvm.org/D153557
2023-08-02 10:19:05 -07:00
Saleem Abdulrasool
05d613ea93 [lit][clang] Avoid realpath on Windows due to MAX_PATH limitations
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-08-01 11:00:27 -07:00
Erick Velez
422bcd10c4 [clang][ExtractAPI] Add semicolons to vars and fields and to test reference JSON
Differential Revision: https://reviews.llvm.org/D154038
2023-07-31 23:29:04 -07:00
Ankur
8e9145e431 [clang][ExtractAPI] Add --emit-symbol-graph option
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-07-03 17:32:30 +05:30
Kazu Hirata
c4933940f7 [clang] Use DenseMapBase::lookup (NFC) 2023-06-13 00:24:43 -07:00
Erick Velez
06ff977047 [clang][ExtractAPI] Refactor serializer to the CRTP
Refactor SerializerBase and SymbolGraphSerializer to use a visitor pattern described by the CRTP.

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D151477
2023-05-30 19:00:35 +01:00
NagaChaitanya Vellanki
14805dcb0d [clang][ExtractAPI] Add semicolon to function declaration fragments
Add missing semicolon at the end of function declarations to fragments

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D149737
2023-05-04 11:46:43 -07:00
Usman Akinyemi
32b53cf9d0 [ExtractAPI] Remove extra attributes in property declaration fragments
Use `getPropertyAttributesAsWritten` instead of `getPropertyAttributes`
to get property attributes actually specified in the source code.
Resolves issue #61478.

https://reviews.llvm.org/D146759

Reviewed By: zixuw, dang

Differential Revision: https://reviews.llvm.org/D146759
2023-04-04 10:00:34 -07:00
NagaChaitanya Vellanki
a590d86343 [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id
Fixes https://github.com/llvm/llvm-project/issues/61479

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D146866
2023-03-30 11:36:16 -07:00
Daniel Grumberg
142c3d9d14 [clang][ExtractAPI] Reland ExtractAPI for libclang improvements
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-30 18:13:58 +01:00
Mitch Phillips
3be6c4d413 Revert "Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656""
This reverts commit 79116475124112051625b1a0665e35c861bb13fd.

Broke the ASan bots. See more information in
https://reviews.llvm.org/rG79116475124112051625b1a0665e35c861bb13fd
2023-03-29 11:39:44 -07:00
Mitch Phillips
96f028c0a2 Revert "[clang][ExtractAPI] Add queried symbol to parent contexts in libclang"
This reverts commit 1cfe1e732ad8e8148f6fa8fc0f0c86f4b965d567.

Depends on reverted commit 158a431227a876306fe5838936413dd51588d0c6. See
https://reviews.llvm.org/rG79116475124112051625b1a0665e35c861bb13fd for
more information, this broke the ASan bots.
2023-03-29 11:39:32 -07:00
Daniel Grumberg
1cfe1e732a [clang][ExtractAPI] Add queried symbol to parent contexts in libclang
Ensure that the current symbol is added to the parent contexts in the
output of libclang function for generating symbol graphs for single symbols.

Differential Revision: https://reviews.llvm.org/D147138
2023-03-29 16:32:26 +01:00
Daniel Grumberg
7911647512 Revert "Revert ExtractAPI from https://reviews.llvm.org/D146656"
This reverts commit 158a431227a876306fe5838936413dd51588d0c6.
2023-03-29 10:51:13 +01:00
Daniel Grumberg
158a431227 Revert ExtractAPI from https://reviews.llvm.org/D146656 2023-03-27 22:12:36 +01:00
Daniel Grumberg
d0dd151eed Address code review feedback 2023-03-27 17:24:10 +01:00
Daniel Grumberg
ea35740e7e [clang][ExtractAPI] Refactor ExtractAPIVisitor to make it more extensible
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-27 17:24:10 +01:00
NagaChaitanya Vellanki
c13ccf1fba [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id
Fixes https://github.com/llvm/llvm-project/issues/61481

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D146671
2023-03-23 15:10:27 -07:00
NagaChaitanya Vellanki
afce10c5b6 [clang][ExtractAPI] Add semicolons for enum, typedef, struct declaration fragments
Fixes https://github.com/llvm/llvm-project/issues/61480

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D146354
2023-03-20 15:43:00 +00:00
Ankur
58825d2cf9 [clang][ExtractAPI] Add multiple file support to --extract-api-ignores
- 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-03-13 18:05:16 +05:30
Ankur
65f7a84cf3 [clang][ExtractAPI] Handle platform specific unavailability correctly
This Patch gives ExtractAPI the ability to emit correct availability information for symbols marked as unavailable on a specific platform ( PR#60954 )

Reviewed By: dang

Differential Revision: https://reviews.llvm.org/D144940
2023-03-02 15:49:46 +00:00
Daniel Grumberg
7da2d644e0 [clang] [extract-api] Don't crash for category in libclang APIs
Remove failure conditions for categories in libclang and return empty
content instead.

Differential Revision: https://reviews.llvm.org/D142101
2023-02-10 16:30:19 +00: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
Archibald Elliott
f09cf34d00 [Support] Move TargetParsers to new component
This is a fairly large changeset, but it can be broken into a few
pieces:
- `llvm/Support/*TargetParser*` are all moved from the LLVM Support
  component into a new LLVM Component called "TargetParser". This
  potentially enables using tablegen to maintain this information, as
  is shown in https://reviews.llvm.org/D137517. This cannot currently
  be done, as llvm-tblgen relies on LLVM's Support component.
- This also moves two files from Support which use and depend on
  information in the TargetParser:
  - `llvm/Support/Host.{h,cpp}` which contains functions for inspecting
    the current Host machine for info about it, primarily to support
    getting the host triple, but also for `-mcpu=native` support in e.g.
    Clang. This is fairly tightly intertwined with the information in
    `X86TargetParser.h`, so keeping them in the same component makes
    sense.
  - `llvm/ADT/Triple.h` and `llvm/Support/Triple.cpp`, which contains
    the target triple parser and representation. This is very intertwined
    with the Arm target parser, because the arm architecture version
    appears in canonical triples on arm platforms.
- I moved the relevant unittests to their own directory.

And so, we end up with a single component that has all the information
about the following, which to me seems like a unified component:
- Triples that LLVM Knows about
- Architecture names and CPUs that LLVM knows about
- CPU detection logic for LLVM

Given this, I have also moved `RISCVISAInfo.h` into this component, as
it seems to me to be part of that same set of functionality.

If you get link errors in your components after this patch, you likely
need to add TargetParser into LLVM_LINK_COMPONENTS in CMake.

Differential Revision: https://reviews.llvm.org/D137838
2022-12-20 11:05:50 +00:00
Fangrui Song
53e5cd4d3e llvm::Optional::value => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.

This makes `ninja clang` work in the absence of llvm::Optional::value.
2022-12-17 06:37:59 +00:00
Daniel Grumberg
8dcb629aa4 [clang][ExtractAPI] Fix naming of typedef'd anonymous enums
Anonymous enums that are typedef'd should take on the name of the typedef.

Differential Revision: https://reviews.llvm.org/D140010
2022-12-16 11:01:03 +00:00
Daniel Grumberg
7a85192166 [clang][ExtractAPI] Add support for single symbol SGF and libclang support
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-13 11:18:11 +00:00