diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-15 14:47:55 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-15 15:38:43 +0100 |
commit | 791634b999e33e029aeeda91eeb5fae13757dcdc (patch) | |
tree | 5e869fd5b5d9fb8fd6c70046b88cfaafd882fa48 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | d1862a16310379179a40b309a9721318ae7e3254 (diff) | |
download | llvm-791634b999e33e029aeeda91eeb5fae13757dcdc.zip llvm-791634b999e33e029aeeda91eeb5fae13757dcdc.tar.gz llvm-791634b999e33e029aeeda91eeb5fae13757dcdc.tar.bz2 |
[clang][cli] Parse & generate options necessary for LangOptions defaults manually
It turns out we need to handle `LangOptions` separately from the rest of the options. `LangOptions` used to be conditionally parsed only when `!(DashX.getFormat() == InputKind::Precompiled || DashX.getLanguage() == Language::LLVM_IR)` and we need to restore this order (for more info, see D94682).
D94682 moves the parsing of marshalled `LangOpts` from `parseSimpleArgs` back to `ParseLangArgs`.
We need to parse marshalled `LangOpts` **after** `ParseLangArgs` calls `setLangDefaults`. This will enable future patches, where values of some `LangOpts` depend on the defaults.
However, two language options (`-finclude-default-header` and `-fdeclare-opencl-builtins`) need to be parsed **before** `ParseLangArgs` calls `setLangDefaults`, because they are necessary for setting up OpenCL defaults correctly.
This patch implements this by removing their marshalling info and manually parsing (and generating) them exactly where necessary.
Reviewed By: Bigcheese
Differential Revision: https://reviews.llvm.org/D94678
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 37d7f6f..c85b0f9 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -491,6 +491,11 @@ static unsigned getOptimizationLevelSize(ArgList &Args) { return 0; } +static std::string GetOptName(llvm::opt::OptSpecifier OptSpecifier) { + static const OptTable &OptTable = getDriverOptTable(); + return OptTable.getOption(OptSpecifier).getPrefixedName(); +} + static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector<std::string> &Diagnostics) { @@ -2137,6 +2142,15 @@ static const StringRef GetInputKindName(InputKind IK) { llvm_unreachable("unknown input language"); } +static void GenerateLangArgs(const LangOptions &Opts, + SmallVectorImpl<const char *> &Args, + CompilerInvocation::StringAllocator SA) { + if (Opts.IncludeDefaultHeader) + Args.push_back(SA(GetOptName(OPT_finclude_default_header))); + if (Opts.DeclareOpenCLBuiltins) + Args.push_back(SA(GetOptName(OPT_fdeclare_opencl_builtins))); +} + static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, const llvm::Triple &T, std::vector<std::string> &Includes, @@ -2212,6 +2226,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device); + // These need to be parsed now. They are used to set OpenCL defaults. + Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header); + Opts.DeclareOpenCLBuiltins = Args.hasArg(OPT_fdeclare_opencl_builtins); + CompilerInvocation::setLangDefaults(Opts, IK, T, Includes, LangStd); // -cl-strict-aliasing needs to emit diagnostic in the case where CL > 1.0. @@ -3163,6 +3181,8 @@ void CompilerInvocation::generateCC1CommandLine( #undef DIAG_OPTION_WITH_MARSHALLING #undef OPTION_WITH_MARSHALLING #undef GENERATE_OPTION_WITH_MARSHALLING + + GenerateLangArgs(*LangOpts, Args, SA); } IntrusiveRefCntPtr<llvm::vfs::FileSystem> |