From 05127fba4b66c91489e9f380f691a0bb42cd2782 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Wed, 27 Jan 2021 14:34:09 +0100 Subject: [PATCH] [clang][cli] Parse HeaderSearch options separately This patch moves parsing of header search options from `parseSimpleArgs` back to `ParseHeaderSearchArgs` where they originally were. The round-trip algorithm in D94472 requires this separation to be able to run parsing and generating **only** for the options that need to be tested via round-tripping. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D94802 --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Frontend/CompilerInvocation.cpp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2615ab4c..77f13e2 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -256,7 +256,7 @@ class DependencyOutputOpts class CodeGenOpts : KeyPathAndMacro<"CodeGenOpts.", base, "CODEGEN_"> {} class HeaderSearchOpts - : KeyPathAndMacro<"HeaderSearchOpts->", base> {} + : KeyPathAndMacro<"HeaderSearchOpts->", base, "HEADER_SEARCH_"> {} class PreprocessorOpts : KeyPathAndMacro<"PreprocessorOpts->", base> {} class FileSystemOpts diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index d61c3bd..f3e9f05 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1827,7 +1827,23 @@ std::string CompilerInvocation::GetResourcesPath(const char *Argv0, } static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args, + DiagnosticsEngine &Diags, const std::string &WorkingDir) { + HeaderSearchOptions *HeaderSearchOpts = &Opts; + bool Success = true; + +#define HEADER_SEARCH_OPTION_WITH_MARSHALLING( \ + PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, \ + DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \ + MERGER, EXTRACTOR, TABLE_INDEX) \ + PARSE_OPTION_WITH_MARSHALLING(Args, Diags, Success, ID, FLAGS, PARAM, \ + SHOULD_PARSE, KEYPATH, DEFAULT_VALUE, \ + IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, \ + MERGER, TABLE_INDEX) +#include "clang/Driver/Options.inc" +#undef HEADER_SEARCH_OPTION_WITH_MARSHALLING + if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ)) Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0); @@ -2774,7 +2790,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, LangOpts.IsHeaderFile); ParseTargetArgs(Res.getTargetOpts(), Args, Diags); llvm::Triple T(Res.getTargetOpts().Triple); - ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, + ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags, Res.getFileSystemOpts().WorkingDir); if (DashX.getFormat() == InputKind::Precompiled || DashX.getLanguage() == Language::LLVM_IR) { @@ -2995,6 +3011,7 @@ void CompilerInvocation::generateCC1CommandLine( EXTRACTOR, TABLE_INDEX) #define DIAG_OPTION_WITH_MARSHALLING OPTION_WITH_MARSHALLING +#define HEADER_SEARCH_OPTION_WITH_MARSHALLING OPTION_WITH_MARSHALLING #define LANG_OPTION_WITH_MARSHALLING OPTION_WITH_MARSHALLING #define CODEGEN_OPTION_WITH_MARSHALLING OPTION_WITH_MARSHALLING @@ -3002,6 +3019,7 @@ void CompilerInvocation::generateCC1CommandLine( #undef CODEGEN_OPTION_WITH_MARSHALLING #undef LANG_OPTION_WITH_MARSHALLING +#undef HEADER_SEARCH_OPTION_WITH_MARSHALLING #undef DIAG_OPTION_WITH_MARSHALLING #undef OPTION_WITH_MARSHALLING #undef GENERATE_OPTION_WITH_MARSHALLING -- 2.7.4