From 07d799f08fec4cb9ceb14a43cc134dee7f1621fc Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Thu, 23 Nov 2023 19:52:27 +0100 Subject: [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 --- clang/lib/Frontend/CompilerInvocation.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 3f4ca02..3b92cc1 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -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()); -- cgit v1.1