[APINotes] Upstream Driver and Frontend options that enable API Notes

This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
This commit is contained in:
Egor Zhdan 2023-11-23 19:52:27 +01:00 committed by GitHub
parent 258631fc0c
commit 07d799f08f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 0 deletions

View File

@ -405,6 +405,7 @@ LANGOPT(XLPragmaPack, 1, 0, "IBM XL #pragma pack handling")
LANGOPT(RetainCommentsFromSystemHeaders, 1, 0, "retain documentation comments from system headers in the AST")
LANGOPT(APINotes, 1, 0, "use external API notes")
LANGOPT(APINotesModules, 1, 0, "use module-based external API notes")
LANGOPT(SanitizeAddressFieldPadding, 2, 0, "controls how aggressive is ASan "
"field padding (0: none, 1:least "

View File

@ -1754,6 +1754,18 @@ def fswift_async_fp_EQ : Joined<["-"], "fswift-async-fp=">,
NormalizedValuesScope<"CodeGenOptions::SwiftAsyncFramePointerKind">,
NormalizedValues<["Auto", "Always", "Never"]>,
MarshallingInfoEnum<CodeGenOpts<"SwiftAsyncFramePointer">, "Always">;
defm apinotes : BoolOption<"f", "apinotes",
LangOpts<"APINotes">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption], "Enable">,
NegFlag<SetFalse, [], [ClangOption], "Disable">,
BothFlags<[], [ClangOption, CC1Option], "external API notes support">>,
Group<f_clang_Group>;
defm apinotes_modules : BoolOption<"f", "apinotes-modules",
LangOpts<"APINotesModules">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption], "Enable">,
NegFlag<SetFalse, [], [ClangOption], "Disable">,
BothFlags<[], [ClangOption, CC1Option], "module-based external API notes support">>,
Group<f_clang_Group>;
def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
Group<f_clang_Group>, Visibility<[ClangOption, CC1Option]>,
MetaVarName<"<version>">,

View File

@ -6720,6 +6720,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
options::OPT_fno_assume_sane_operator_new);
if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes, false))
CmdArgs.push_back("-fapinotes");
if (Args.hasFlag(options::OPT_fapinotes_modules,
options::OPT_fno_apinotes_modules, false))
CmdArgs.push_back("-fapinotes-modules");
Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
// -fblocks=0 is default.
if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
TC.IsBlocksDefault()) ||

View File

@ -756,6 +756,14 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind,
TheSema->addExternalSource(ExternalSemaSrc.get());
ExternalSemaSrc->InitializeSema(*TheSema);
}
// If we're building a module and are supposed to load API notes,
// notify the API notes manager.
if (auto *currentModule = getPreprocessor().getCurrentModule()) {
(void)TheSema->APINotes.loadCurrentModuleAPINotes(
currentModule, getLangOpts().APINotesModules,
getAPINotesOpts().ModuleSearchPaths);
}
}
// Output Files

View File

@ -3267,6 +3267,16 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
return Diags.getNumErrors() == NumErrorsBefore;
}
static void GenerateAPINotesArgs(const APINotesOptions &Opts,
ArgumentConsumer Consumer) {
if (!Opts.SwiftVersion.empty())
GenerateArg(Consumer, OPT_fapinotes_swift_version,
Opts.SwiftVersion.getAsString());
for (const auto &Path : Opts.ModuleSearchPaths)
GenerateArg(Consumer, OPT_iapinotes_modules, Path);
}
static void ParseAPINotesArgs(APINotesOptions &Opts, ArgList &Args,
DiagnosticsEngine &diags) {
if (const Arg *A = Args.getLastArg(OPT_fapinotes_swift_version)) {
@ -4746,6 +4756,18 @@ std::string CompilerInvocation::getModuleHash() const {
for (const auto &ext : getFrontendOpts().ModuleFileExtensions)
ext->hashExtension(HBuilder);
// Extend the signature with the Swift version for API notes.
const APINotesOptions &APINotesOpts = getAPINotesOpts();
if (!APINotesOpts.SwiftVersion.empty()) {
HBuilder.add(APINotesOpts.SwiftVersion.getMajor());
if (auto Minor = APINotesOpts.SwiftVersion.getMinor())
HBuilder.add(*Minor);
if (auto Subminor = APINotesOpts.SwiftVersion.getSubminor())
HBuilder.add(*Subminor);
if (auto Build = APINotesOpts.SwiftVersion.getBuild())
HBuilder.add(*Build);
}
// When compiling with -gmodules, also hash -fdebug-prefix-map as it
// affects the debug info in the PCM.
if (getCodeGenOpts().DebugTypeExtRefs)
@ -4776,6 +4798,7 @@ void CompilerInvocationBase::generateCC1CommandLine(
GenerateFrontendArgs(getFrontendOpts(), Consumer, getLangOpts().IsHeaderFile);
GenerateTargetArgs(getTargetOpts(), Consumer);
GenerateHeaderSearchArgs(getHeaderSearchOpts(), Consumer);
GenerateAPINotesArgs(getAPINotesOpts(), Consumer);
GenerateLangArgs(getLangOpts(), Consumer, T, getFrontendOpts().DashX);
GenerateCodeGenArgs(getCodeGenOpts(), Consumer, T,
getFrontendOpts().OutputFile, &getLangOpts());