Skip to content

Commit ced9816

Browse files
author
git apple-llvm automerger
committed
Merge commit '09e98950bfcf' from llvm.org/main into next
2 parents 7011bd4 + 7709739 commit ced9816

25 files changed

+357
-5
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,4 +815,7 @@ def warn_android_unversioned_fallback : Warning<
815815

816816
def err_drv_triple_version_invalid : Error<
817817
"version '%0' in target triple '%1' is invalid">;
818+
819+
def err_drv_installapi_unsupported : Error<
820+
"InstallAPI is not supported for '%0'">;
818821
}

clang/include/clang/Driver/Action.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class Action {
6060
PreprocessJobClass,
6161
PrecompileJobClass,
6262
ExtractAPIJobClass,
63+
InstallAPIJobClass,
6364
AnalyzeJobClass,
6465
MigrateJobClass,
6566
CompileJobClass,
@@ -465,6 +466,17 @@ class ExtractAPIJobAction : public JobAction {
465466
void addHeaderInput(Action *Input) { getInputs().push_back(Input); }
466467
};
467468

469+
class InstallAPIJobAction : public JobAction {
470+
void anchor() override;
471+
472+
public:
473+
InstallAPIJobAction(Action *Input, types::ID OutputType);
474+
475+
static bool classof(const Action *A) {
476+
return A->getKind() == InstallAPIJobClass;
477+
}
478+
};
479+
468480
class AnalyzeJobAction : public JobAction {
469481
void anchor() override;
470482

clang/include/clang/Driver/Options.td

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ class AnalyzerOpts<string base>
310310
: KeyPathAndMacro<"AnalyzerOpts->", base, "ANALYZER_"> {}
311311
class MigratorOpts<string base>
312312
: KeyPathAndMacro<"MigratorOpts.", base, "MIGRATOR_"> {}
313+
class InstallAPIOpts<string base>
314+
: KeyPathAndMacro<"InstallAPIOpts.", base, "INSTALLAPI_"> {}
313315

314316
// A boolean option which is opt-in in CC1. The positive option exists in CC1 and
315317
// Args.hasArg(OPT_ffoo) can be used to check that the flag is enabled.
@@ -1141,7 +1143,8 @@ def config_user_dir_EQ : Joined<["--"], "config-user-dir=">,
11411143
def coverage : Flag<["-", "--"], "coverage">, Group<Link_Group>,
11421144
Visibility<[ClangOption, CLOption]>;
11431145
def cpp_precomp : Flag<["-"], "cpp-precomp">, Group<clang_ignored_f_Group>;
1144-
def current__version : JoinedOrSeparate<["-"], "current_version">;
1146+
def current__version : JoinedOrSeparate<["-"], "current_version">,
1147+
Visibility<[ClangOption, CC1Option]>;
11451148
def cxx_isystem : JoinedOrSeparate<["-"], "cxx-isystem">, Group<clang_i_Group>,
11461149
HelpText<"Add directory to the C++ SYSTEM include search path">,
11471150
Visibility<[ClangOption, CC1Option]>,
@@ -1556,6 +1559,9 @@ def static_libsan : Flag<["-"], "static-libsan">,
15561559
HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
15571560
def : Flag<["-"], "shared-libasan">, Alias<shared_libsan>;
15581561
def fasm : Flag<["-"], "fasm">, Group<f_Group>;
1562+
def installapi : Flag<["-"], "installapi">,
1563+
Visibility<[ClangOption, CC1Option]>, Group<Action_Group>,
1564+
HelpText<"Create a text-based stub file by scanning header files">;
15591565

15601566
defm assume_unique_vtables : BoolFOption<"assume-unique-vtables",
15611567
CodeGenOpts<"AssumeUniqueVTables">, DefaultTrue,
@@ -4366,7 +4372,9 @@ def verify_pch : Flag<["-"], "verify-pch">, Group<Action_Group>,
43664372
Visibility<[ClangOption, CC1Option]>,
43674373
HelpText<"Load and verify that a pre-compiled header file is not stale">;
43684374
def init : Separate<["-"], "init">;
4369-
def install__name : Separate<["-"], "install_name">;
4375+
def install__name : Separate<["-"], "install_name">,
4376+
Visibility<[ClangOption, CC1Option]>,
4377+
MarshallingInfoString<InstallAPIOpts<"InstallName">>;
43704378
def iprefix : JoinedOrSeparate<["-"], "iprefix">, Group<clang_i_Group>,
43714379
Visibility<[ClangOption, CC1Option]>,
43724380
HelpText<"Set the -iwithprefix/-iwithprefixbefore prefix">, MetaVarName<"<dir>">;

clang/include/clang/Driver/Types.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ TYPE("lto-bc", LTO_BC, INVALID, "o", phases
9494
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
9595
TYPE("ifs", IFS, INVALID, "ifs", phases::IfsMerge)
9696
TYPE("ifs-cpp", IFS_CPP, INVALID, "ifs", phases::Compile, phases::IfsMerge)
97+
TYPE("tbd", TextAPI, INVALID, "tbd", phases::Precompile)
9798
TYPE("pcm", ModuleFile, INVALID, "pcm", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
9899
TYPE("header-unit", HeaderUnit, INVALID, "pcm", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
99100
TYPE("plist", Plist, INVALID, "plist", phases::Compile, phases::Backend, phases::Assemble, phases::Link)

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ class CompilerInstance : public ModuleLoader {
312312
return Invocation->getFrontendOpts();
313313
}
314314

315+
InstallAPIOptions &getInstallAPIOpts() {
316+
return Invocation->getInstallAPIOpts();
317+
}
318+
const InstallAPIOptions &getInstallAPIOpts() const {
319+
return Invocation->getInstallAPIOpts();
320+
}
321+
315322
HeaderSearchOptions &getHeaderSearchOpts() {
316323
return Invocation->getHeaderSearchOpts();
317324
}

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
#include "clang/CAS/CASOptions.h"
2020
#include "clang/Frontend/DependencyOutputOptions.h"
2121
#include "clang/Frontend/FrontendOptions.h"
22+
#include "clang/Frontend/InstallAPIOptions.h"
2223
#include "clang/Frontend/MigratorOptions.h"
2324
#include "clang/Frontend/PreprocessorOutputOptions.h"
2425
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
25-
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2626
#include "llvm/ADT/ArrayRef.h"
27+
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2728
#include <memory>
2829
#include <string>
2930

@@ -120,6 +121,9 @@ class CompilerInvocationBase {
120121
/// Options controlling preprocessed output.
121122
std::shared_ptr<PreprocessorOutputOptions> PreprocessorOutputOpts;
122123

124+
/// Options controlling InstallAPI operations and output.
125+
std::shared_ptr<InstallAPIOptions> InstallAPIOpts;
126+
123127
/// Dummy tag type whose instance can be passed into the constructor to
124128
/// prevent creation of the reference-counted option objects.
125129
struct EmptyConstructor {};
@@ -155,6 +159,7 @@ class CompilerInvocationBase {
155159
const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
156160
return *PreprocessorOutputOpts;
157161
}
162+
const InstallAPIOptions &getInstallAPIOpts() const { return *InstallAPIOpts; }
158163
/// @}
159164

160165
/// Command line generation.
@@ -268,6 +273,7 @@ class CompilerInvocation : public CompilerInvocationBase {
268273
using CompilerInvocationBase::getFrontendOpts;
269274
using CompilerInvocationBase::getDependencyOutputOpts;
270275
using CompilerInvocationBase::getPreprocessorOutputOpts;
276+
using CompilerInvocationBase::getInstallAPIOpts;
271277
/// @}
272278

273279
/// Mutable getters.
@@ -290,6 +296,7 @@ class CompilerInvocation : public CompilerInvocationBase {
290296
PreprocessorOutputOptions &getPreprocessorOutputOpts() {
291297
return *PreprocessorOutputOpts;
292298
}
299+
InstallAPIOptions &getInstallAPIOpts() { return *InstallAPIOpts; }
293300
/// @}
294301

295302
/// Base class internals.

clang/include/clang/Frontend/FrontendActions.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ class GenerateModuleAction : public ASTFrontendAction {
130130
bool shouldEraseOutputFiles() override;
131131
};
132132

133+
class InstallAPIAction : public ASTFrontendAction {
134+
protected:
135+
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
136+
StringRef InFile) override;
137+
138+
public:
139+
static std::unique_ptr<llvm::raw_pwrite_stream>
140+
CreateOutputFile(CompilerInstance &CI, StringRef InFile);
141+
};
142+
133143
class GenerateInterfaceStubsAction : public ASTFrontendAction {
134144
protected:
135145
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ enum ActionKind {
101101
/// Only execute frontend initialization.
102102
InitOnly,
103103

104+
// Create TextAPI stub.
105+
InstallAPI,
106+
104107
/// Dump information about a module file.
105108
ModuleFileInfo,
106109

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===--- InstallAPIOptions.h ------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_FRONTEND_INSTALLAPIOPTIONS_H
10+
#define LLVM_CLANG_FRONTEND_INSTALLAPIOPTIONS_H
11+
12+
#include "llvm/TextAPI/PackedVersion.h"
13+
14+
namespace clang {
15+
16+
/// InstallAPIOptions - Options for controlling InstallAPI verification and
17+
/// TextAPI output.
18+
class InstallAPIOptions {
19+
public:
20+
/// The install name which is apart of the library's ID.
21+
std::string InstallName;
22+
23+
/// The current version which is apart of the library's ID.
24+
llvm::MachO::PackedVersion CurrentVersion;
25+
};
26+
} // namespace clang
27+
28+
#endif
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===- InstallAPI/Context.h -------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Top level types for interacting with the generic clang driver and frontend
10+
// for InstallAPI operations.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
15+
#define LLVM_CLANG_INSTALLAPI_CONTEXT_H
16+
17+
#include "clang/AST/ASTConsumer.h"
18+
#include "clang/Basic/Diagnostic.h"
19+
#include "llvm/ADT/IntrusiveRefCntPtr.h"
20+
#include "llvm/TextAPI/InterfaceFile.h"
21+
#include "llvm/TextAPI/RecordVisitor.h"
22+
#include "llvm/TextAPI/RecordsSlice.h"
23+
24+
namespace clang {
25+
namespace installapi {
26+
27+
/// Struct used for generating validating InstallAPI.
28+
/// The attributes captured represent all necessary information
29+
/// to generate TextAPI output.
30+
struct InstallAPIContext {
31+
32+
/// Library attributes that are typically passed as linker inputs.
33+
llvm::MachO::RecordsSlice::BinaryAttrs BA;
34+
35+
/// Active target triple to parse.
36+
llvm::Triple TargetTriple{};
37+
38+
/// Output stream to write TextAPI file to.
39+
std::unique_ptr<llvm::raw_pwrite_stream> OS = nullptr;
40+
41+
/// DiagnosticsEngine to report errors.
42+
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags = nullptr;
43+
44+
/// File Path of output location.
45+
StringRef OutputLoc{};
46+
47+
/// What encoding to write output as.
48+
llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5;
49+
};
50+
51+
class InstallAPIConsumer : public ASTConsumer {
52+
public:
53+
InstallAPIConsumer(InstallAPIContext InstallAPICtx)
54+
: Ctx(std::move(InstallAPICtx)) {}
55+
56+
void HandleTranslationUnit(ASTContext &ASTContext) override;
57+
58+
private:
59+
InstallAPIContext Ctx;
60+
};
61+
62+
} // namespace installapi
63+
} // namespace clang
64+
65+
#endif // LLVM_CLANG_INSTALLAPI_CONTEXT_H

clang/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_subdirectory(DirectoryWatcher)
2525
add_subdirectory(Index)
2626
add_subdirectory(IndexDataStore)
2727
add_subdirectory(IndexSerialization)
28+
add_subdirectory(InstallAPI)
2829
add_subdirectory(StaticAnalyzer)
2930
add_subdirectory(Format)
3031
if(CLANG_INCLUDE_TESTS)

clang/lib/Driver/Action.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const char *Action::getClassName(ActionClass AC) {
3333
case CompileJobClass: return "compiler";
3434
case BackendJobClass: return "backend";
3535
case AssembleJobClass: return "assembler";
36+
case InstallAPIJobClass:
37+
return "installapi";
3638
case IfsMergeJobClass: return "interface-stub-merger";
3739
case LinkJobClass: return "linker";
3840
case LipoJobClass: return "lipo";
@@ -368,6 +370,11 @@ void ExtractAPIJobAction::anchor() {}
368370
ExtractAPIJobAction::ExtractAPIJobAction(Action *Inputs, types::ID OutputType)
369371
: JobAction(ExtractAPIJobClass, Inputs, OutputType) {}
370372

373+
void InstallAPIJobAction::anchor() {}
374+
375+
InstallAPIJobAction::InstallAPIJobAction(Action *Inputs, types::ID OutputType)
376+
: JobAction(InstallAPIJobClass, Inputs, OutputType) {}
377+
371378
void AnalyzeJobAction::anchor() {}
372379

373380
AnalyzeJobAction::AnalyzeJobAction(Action *Input, types::ID OutputType)

clang/lib/Driver/Driver.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4199,6 +4199,11 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
41994199
break;
42004200
}
42014201

4202+
if (auto *IAA = dyn_cast<InstallAPIJobAction>(Current)) {
4203+
Current = nullptr;
4204+
break;
4205+
}
4206+
42024207
// FIXME: Should we include any prior module file outputs as inputs of
42034208
// later actions in the same command line?
42044209

@@ -4329,6 +4334,13 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43294334
if (!MergerInputs.empty())
43304335
Actions.push_back(
43314336
C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image));
4337+
} else if (Args.hasArg(options::OPT_installapi)) {
4338+
// TODO: Lift restriction once operation can handle multiple inputs.
4339+
assert(Inputs.size() == 1 && "InstallAPI action can only handle 1 input");
4340+
const auto [InputType, InputArg] = Inputs.front();
4341+
Action *Current = C.MakeAction<InputAction>(*InputArg, InputType);
4342+
Actions.push_back(
4343+
C.MakeAction<InstallAPIJobAction>(Current, types::TY_TextAPI));
43324344
}
43334345

43344346
for (auto Opt : {options::OPT_print_supported_cpus,
@@ -4777,6 +4789,8 @@ Action *Driver::ConstructPhaseAction(
47774789
return C.MakeAction<VerifyPCHJobAction>(Input, types::TY_Nothing);
47784790
if (Args.hasArg(options::OPT_extract_api))
47794791
return C.MakeAction<ExtractAPIJobAction>(Input, types::TY_API_INFO);
4792+
if (Args.hasArg(options::OPT_installapi))
4793+
return C.MakeAction<InstallAPIJobAction>(Input, types::TY_TextAPI);
47804794
return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
47814795
}
47824796
case phases::Backend: {
@@ -6475,7 +6489,7 @@ bool Driver::ShouldUseClangCompiler(const JobAction &JA) const {
64756489
// And say "no" if this is not a kind of action clang understands.
64766490
if (!isa<PreprocessJobAction>(JA) && !isa<PrecompileJobAction>(JA) &&
64776491
!isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA) &&
6478-
!isa<ExtractAPIJobAction>(JA))
6492+
!isa<ExtractAPIJobAction>(JA) && !isa<InstallAPIJobAction>(JA))
64796493
return false;
64806494

64816495
return true;

clang/lib/Driver/ToolChain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
534534
case Action::DepscanJobClass:
535535
case Action::PreprocessJobClass:
536536
case Action::ExtractAPIJobClass:
537+
case Action::InstallAPIJobClass:
537538
case Action::AnalyzeJobClass:
538539
case Action::MigrateJobClass:
539540
case Action::VerifyPCHJobClass:

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5082,6 +5082,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job,
50825082
if (Arg *ExtractAPIIgnoresFileArg =
50835083
Args.getLastArg(options::OPT_extract_api_ignores_EQ))
50845084
ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
5085+
} else if (isa<InstallAPIJobAction>(JA)) {
5086+
if (!Triple.isOSDarwin())
5087+
D.Diag(diag::err_drv_installapi_unsupported) << Triple.str();
5088+
5089+
CmdArgs.push_back("-installapi");
5090+
// Add necessary library arguments for InstallAPI.
5091+
if (const Arg *A = Args.getLastArg(options::OPT_install__name))
5092+
A->render(Args, CmdArgs);
5093+
if (const Arg *A = Args.getLastArg(options::OPT_current__version))
5094+
A->render(Args, CmdArgs);
5095+
50855096
} else {
50865097
assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA) || isa<DepscanJobAction>(JA)) &&
50875098
"Invalid action for clang tool.");

clang/lib/Frontend/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS
1111
RemoteCachingService
1212
Support
1313
TargetParser
14+
TextAPI
1415
)
1516

1617
add_clang_library(clangFrontend
@@ -37,6 +38,7 @@ add_clang_library(clangFrontend
3738
IncludeTreePPActions.cpp
3839
InitPreprocessor.cpp
3940
LayoutOverrideSource.cpp
41+
InstallAPIConsumer.cpp
4042
LogDiagnosticPrinter.cpp
4143
ModuleDependencyCollector.cpp
4244
MultiplexConsumer.cpp
@@ -63,6 +65,7 @@ add_clang_library(clangFrontend
6365
clangBasic
6466
clangDriver
6567
clangEdit
68+
clangInstallAPI
6669
clangLex
6770
clangParse
6871
clangSema

0 commit comments

Comments
 (0)