52 Commits

Author SHA1 Message Date
James Y Knight
4205da0f13
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151782)
This commit handles the following types:
- clang::ExternalASTSource
- clang::TargetInfo
- clang::ASTContext
- clang::SourceManager
- clang::FileManager

Part of cleanup #151026
2025-08-01 22:23:30 -04:00
James Y Knight
c7f3437507
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs.

For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to
convenience method `DiagnosticIDs::create()`.

Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-07-31 15:07:35 -04:00
James Y Knight
9ddbb478ce
NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407)
This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new
object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>`
instead of `FileSystem*` or `FileSystem&`, when dealing with existing
objects.

Part of cleanup #151026.
2025-07-31 09:57:13 -04:00
Kazu Hirata
a244907922
[clang] Use range-based for loops (NFC) (#146811)
Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.
2025-07-03 08:36:03 -07:00
Kazu Hirata
6ab6321d03
[clang] Use range-based for loops (NFC) (#143153)
Note that use of llvm::for_each is discouraged unless we have functors
readily available.
2025-06-06 09:16:41 -07:00
Kazu Hirata
ddc8b5419a
[tools] Remove unused local variables (NFC) (#142880) 2025-06-04 22:42:59 -07:00
Jan Svoboda
13e1a2cb22 Reapply "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22 12:52:03 -07:00
Kazu Hirata
e2a885537f Revert "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c.

Multiple builtbot failures have been reported:
https://github.com/llvm/llvm-project/pull/139584
2025-05-22 12:44:20 -07:00
Jan Svoboda
9e306ad460
[clang] Remove intrusive reference count from DiagnosticOptions (#139584)
The `DiagnosticOptions` class is currently intrusively
reference-counted, which makes reasoning about its lifetime very
difficult in some cases. For example, `CompilerInvocation` owns the
`DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and
only exposes an accessor returning `DiagnosticOptions &`. One would
think this gives `CompilerInvocation` exclusive ownership of the object,
but that's not the case:

```c++
void shareOwnership(CompilerInvocation &CI) {
  llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions();
  // ...
}
```

This is a perfectly valid pattern that is being actually used in the
codebase.

I would like to ensure the ownership of `DiagnosticOptions` by
`CompilerInvocation` is guaranteed to be exclusive. This can be
leveraged for a copy-on-write optimization later on. This PR changes
usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and
`lldb` to not be intrusively reference-counted.
2025-05-22 12:33:52 -07:00
Cyndy Ishida
823b1a5822
[clang-installapi] Store dylib attributes in the order they are passed on the command line. (#139087)
With the introduction of tbd-v5 holding rpaths, the order in which those
attributes are passed to `clang-installapi` must be represented in tbd
files. Previously, all dylib attributes were stored in a
non-deterministic `StringMap`. Instead, hold them in a custom collection
with an underlying vector to continue supporting searching by attribute.
This makes the order of all diagnostics related to load command
comparisons stable.

This approach resolves errors when building with reverse-iteration.
2025-05-08 21:15:10 -07:00
Kazu Hirata
c2d6c7cea7
[clang] Use llvm::append_range (NFC) (#136448) 2025-04-19 12:21:14 -07:00
Kazu Hirata
f4c76bba59
[clang] Use llvm::append_range (NFC) (#136256)
This patch replaces:

  llvm::copy(Src, std::back_inserter(Dst));

with:

  llvm::append_range(Dst, Src);

for breavity.

One side benefit is that llvm::append_range eventually calls
llvm::SmallVector::reserve if Dst is of llvm::SmallVector.
2025-04-18 00:15:13 -07:00
Kazu Hirata
43c82a8e07
[clang-installapi] Avoid repeated hash lookups (NFC) (#126677) 2025-02-11 09:07:46 -08:00
Chandler Carruth
dd647e3e60
Rework the Option library to reduce dynamic relocations (#119198)
Apologies for the large change, I looked for ways to break this up and
all of the ones I saw added real complexity. This change focuses on the
option's prefixed names and the array of prefixes. These are present in
every option and the dominant source of dynamic relocations for PIE or
PIC users of LLVM and Clang tooling. In some cases, 100s or 1000s of
them for the Clang driver which has a huge number of options.

This PR addresses this by building a string table and a prefixes table
that can be referenced with indices rather than pointers that require
dynamic relocations. This removes almost 7k dynmaic relocations from the
`clang` binary, roughly 8% of the remaining dynmaic relocations outside
of vtables. For busy-boxing use cases where many different option tables
are linked into the same binary, the savings add up a bit more.

The string table is a straightforward mechanism, but the prefixes
required some subtlety. They are encoded in a Pascal-string fashion with
a size followed by a sequence of offsets. This works relatively well for
the small realistic prefixes arrays in use.

Lots of code has to change in order to land this though: both all the
option library code has to be updated to use the string table and
prefixes table, and all the users of the options library have to be
updated to correctly instantiate the objects.

Some follow-up patches in the works to provide an abstraction for this
style of code, and to start using the same technique for some of the
other strings here now that the infrastructure is in place.
2024-12-11 15:44:44 -08:00
Kadir Cetinkaya
df9a14d7bb
Reapply "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"
This reverts commit a1153cd6fedd4c906a9840987934ca4712e34cb2 with fixes
to lldb breakages.

Fixes https://github.com/llvm/llvm-project/issues/117145.
2024-11-21 14:55:30 +01:00
Sylvestre Ledru
a1153cd6fe Revert "[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)"
Reverted for causing:
https://github.com/llvm/llvm-project/issues/117145

This reverts commit bdd10d9d249bd1c2a45e3de56a5accd97e953458.
2024-11-21 13:04:30 +01:00
kadir çetinkaya
bdd10d9d24
[NFC] Explicitly pass a VFS when creating DiagnosticsEngine (#115852)
Starting with 41e3919ded78d8870f7c95e9181c7f7e29aa3cc4 DiagnosticsEngine
creation might perform IO. It was implicitly defaulting to
getRealFileSystem. This patch makes it explicit by pushing the decision
making to callers.

It uses ambient VFS if one is available, and keeps using
`getRealFileSystem` if there aren't any VFS.
2024-11-21 12:11:41 +01:00
Jan Svoboda
b1aea98cfa
[clang] Make deprecations of some FileManager APIs formal (#110014)
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-25 10:36:44 -07:00
Cyndy Ishida
feed66f3ea
[InstallAPI] Pick up input headers by directory traversal (#94508)
Match TAPI behavior and allow input headers to be resolved via a passed
directory, which is expected to be a library sitting in a build
directory.
2024-06-14 13:08:27 -07:00
Cyndy Ishida
c9dc52d424
[InstallAPI] add JSON option to pass X<label> arguments (#91770) 2024-05-20 21:22:24 -07:00
Cyndy Ishida
504cf55463
[InstallAPI] Pass explicit module cache to avoid permissions issues.
Fixes: https://lab.llvm.org/buildbot/#/builders/192/builds/9313
2024-05-10 17:17:38 -07:00
Cyndy Ishida
062f6fe324
[InstallAPI] Support mutually exclusive parse options (#90686)
Projects like libc use mutually exclusive macros to compile files
multiple times and then merge the result into the final library. For
installapi to accept these, we'd need to parse the same declarations in
different ways. This patch adds the basic pipelining for installapi to
create the correct TBD file.

* -Xproject allows: -fmodules, -fobjc-arc, fvisibility=hidden, prefix
headers
* -Xlabel allows: -D and -U settings
* Error on 'private' and 'public' labels -X<label>
* Xplatform allows: -iframework <path> This is to support the case where
zippered frameworks want to pass in iOSSupport search path.
2024-05-10 09:35:41 -07:00
Cyndy Ishida
278774e428
[InstallAPI] Cleanup I/O error handling for input lists (#90664)
Add validation in the FileList reader to check that the headers exist and use similar diagnostics in Options.cpp
2024-04-30 16:10:20 -07:00
Fangrui Song
2c0a185e99 Remove unneeded LLVM_FALLTHROUGH. NFC 2024-04-25 13:21:46 -07:00
Cyndy Ishida
4c18681a2d
[InstallAPI] Add support for aliased exports (#88750)
Apple's ld supports alias_lists, described as
```
     -alias_list filename
             The specified filename contains a list of aliases. The symbol name and its alias are on one
             line, separated by whitespace.  Lines starting with # are ignored.
```
To handle this for installapi-produced TBD files, pass along the same
input and account for it in verification.
2024-04-18 07:39:21 -07:00
Cyndy Ishida
79dca25f4a [InstallAPI] Replace std::string -> StringRef 2024-04-12 22:05:12 -07:00
Cyndy Ishida
c24efffabb
[InstallAPI] Handle zippered frameworks (#88205)
A zippered framework is a single framework that can be loaded in both
macOS and macatalyst processes. Broadly to InstallAPI, it means the same
interface can represent two separate platforms.

A dylib's symbol table does not distinguish between macOS/macCatalyst.
  `InstallAPI` provides the ability for the tbd file to distinct
symbols between them.
The verifier handles this special logic by tracking all unavailable and
obsoleted APIs in this context and checking against those when
determining dylib symbols with no matching declaration.

* If there exists an available decl for either platform, do not warn.
* If there is no available decl, emit a diagnostic and print the source
location for both decls.
2024-04-11 20:01:55 -07:00
Cyndy Ishida
f04452de19
[InstallAPI] Tie lifetime of FE objects to DylibVerifier (#88189)
A few verification checks need to happen until all AST's have been
traversed, specifically for zippered framework checking. To keep source
location until that time valid, hold onto to references of
FrontendRecords + SourceManager.
2024-04-09 15:13:55 -07:00
Cyndy Ishida
27b2d7d4bb
[InstallAPI] Capture & compare load commands that may differ per arch slice (#87674)
* Capture reexported libraries, allowable clients, rpaths, shared cache
eligibility.
* Add support for select Xarch options.
* Add diagnostics related to capturing these options.
* Add support for verifying these attributes against what is encoded in
the dylib.
2024-04-05 13:58:24 -07:00
David Spickett
aff197ff21 Reland "[flang][clang] Add Visibility specific help text for options (#81869)"
This reverts commit 67d20412b448533c77f54ac7a1e5d0775d273729.

This includes fixes for clanginstallapi.
2024-04-05 08:27:59 +00:00
Cyndy Ishida
a4de589d11
[InstallAPI] Add support for parsing dSYMs (#86852)
InstallAPI does not directly look at object files in the dylib for
verification. To help diagnose violations where a declaration is
undiscovered in headers, parse the dSYM and look up the source location
for symbols. Emitting out the source location with a diagnostic is
enough for some IDE's (e.g. Xcode) to have them map back to editable
source files.
2024-03-29 08:29:22 -07:00
Cyndy Ishida
6ad1cf3b37
[InstallAPI] Add *umbrella-header options (#86587)
Umbrella headers are a concept for Darwin-based libraries. They allow
framework authors to control the order in which their headers should be
parsed and allow clients to access available headers by including a
single header.

InstallAPI will attempt to find the umbrella based on the name of the
framework. Users can also specify this explicitly by using command line
options specifying the umbrella header by file path. There can be an
umbrella header per access level.
2024-03-27 12:34:21 -04:00
Cyndy Ishida
487720fc13
Reapply "[InstallAPI] Add --extra* and --exclude* cli options for header input (#86522)" (#86574) 2024-03-25 17:32:21 -04:00
Cyndy Ishida
2d7df3167b Revert "[InstallAPI] Add --extra* and --exclude* cli options for header input (#86522)"
This reverts commit b7d8c6188986f62573b9516fe27fdd0c7df1aaf9. And
This reverts commit 2d40f179124f874aca4cf1145fdbc42fb8fb17f3.

It caused a build failure i'll need to reproduce.
` error: could not convert ‘Rule’ from ‘llvm::Regex’ to ‘llvm::Expected<llvm::Regex>’`
2024-03-25 15:50:46 -04:00
Cyndy Ishida
2d40f17912
[InstallAPI] Add --extra* and --exclude* cli options for header input (#86522)
InstallAPI takes a json list of headers that is typically generated from
a build system like Xcode based on a project's attributes. Sometimes,
maintainers may want to alter this for tapi input. Using e.g.
`--extra-public-headers`, users can manipulate what headers will be used
for TBD file generation.
2024-03-25 15:38:27 -04:00
Cyndy Ishida
e470ca89ba
[InstallAPI] Report exports discovered in binary but not in interface (#86025)
This patch completes the classes of errors installapi can detect.
2024-03-21 15:03:34 -07:00
Cyndy Ishida
936519f25c
[InstallAPI] Verify that declarations in headers map to exports found in dylib (#85348)
* This completes support for verifying every declaration found in a
header is discovered in the dylib. Diagnostics are reported for each
class for differences that are representable in TBD files.

* This patch also now captures unavailable attributes that depend on
target triples. This is needed for proper tbd file generation.
2024-03-19 18:36:46 -07:00
Cyndy Ishida
f2794ccede
[InstallAPI] Introduce Basic Verifier (#85106)
This adds basic support for calling the verifier on global declarations
that are expected to represent symbol exports. The driver now
exclusively uses this for knowing what symbols make up a TBD file.
Future patches will check against the dylib's symbol table.
2024-03-16 10:37:52 -07:00
Cyndy Ishida
c51095f51b
[InstallAPI] Add installapi specific options & diagnostics (#85100)
* A lot of `tapi installapi` options are already shared with clang, but
not all. This patch handles installapi-specific options by filtering for
them in the initial argv input, then passing the rest to the clang
driver.
* Installapi not only generates a text file but also reports to library
developers when there are inconsistencies between an interface and its
implementation. To allow this, add support for reporting installapi
diagnostics. This will be leveraged in the verifier service.
2024-03-16 09:08:17 -07:00
Cyndy Ishida
b058b7e628
[InstallAPI] capture compatibility versions (#85261) 2024-03-14 11:24:16 -07:00
Cyndy Ishida
a38b7a432d
[InstallAPI] Break up headers and add common header for TextAPI types (#84960)
Before it gets too unwieldy, add a common header for all MachO types
that are used across InstallAPI. Also, break up the types in
`InstallAPI/Frontend`. This both avoids circular dependencies and is
logically easier to maintain as more functionality gets added.
2024-03-12 12:37:17 -07:00
Cyndy Ishida
2c93beccdf
[InstallAPI] Collect C++ Decls (#84403)
This includes capturing symbols for global variables, functions,
classes, and templated defintions. As pre-determing what symbols are
generated from C++ declarations can be non-trivial, InstallAPI only
parses select declarations for symbol generation when parsing c++.

For example, installapi only looks at explicit template instantiations
or full template specializations, instead of general function or class
templates, for symbol emittion.
2024-03-11 09:02:43 -07:00
Cyndy Ishida
50ae8a2a38
[InstallAPI] Collect global functions (#83952)
* Include whether functions are inlinable as they impact whether to add
them into the tbd file and for future verification.
* Fix how clang arguments got passed along, previously spacing was
passed along to CC1 causing search path inputs to look non-existent.
2024-03-07 15:32:44 -08:00
Cyndy Ishida
17ede03a92
[InstallAPI] Collect frontend attributes & ObjCInterface decls (#83378)
* This patch introduces a container class, for holding records and
attributes only collectible from the clang frontend, which is a subclass
of `llvm::MachO::RecordsSlice`
* This also prunes out collecting declarations from headers that aren't
considered input to installapi.
* Uses these constructs for collecting global objective-c interfaces.
2024-03-01 14:56:20 -08:00
Fangrui Song
0f76d9fb5f clang-installapi: remove setInstalledDir 2024-02-28 15:17:31 -08:00
Cyndy Ishida
6101cf3164 [InstallAPI] add missing link to clangAST
Appeases bots.
2024-02-28 10:01:30 -08:00
Cyndy Ishida
c6cbf81c84
[InstallAPI] Hookup Input files & basic ASTVisitor (#82552)
This patch takes in json files as input to determine that header files
to process, and in which order, to pass along for CC1 invocations. This
patch also includes an ASTVisitor to collect simple global variables.
2024-02-28 09:47:45 -08:00
Cyndy Ishida
828bf134d7
[InstallAPI] Cleanup HeaderFile Interface & options handling, NFC (#82544) 2024-02-21 14:50:21 -08:00
Cyndy Ishida
5488e3ea48 [InstallAPI] add explicit dependency on llvmOption library 2024-02-21 10:21:17 -08:00
Cyndy Ishida
e7bfe414a6 [InstallAPI] Add additional missing library dependency
Fixes: https://lab.llvm.org/buildbot/#/builders/268/builds/8583
2024-02-21 10:09:55 -08:00