From: Chuanqi Xu Date: Mon, 17 Oct 2022 07:48:13 +0000 (+0800) Subject: [NFC] Judge if we have std c++ modules in RenderModulesOptions X-Git-Tag: upstream/17.0.6~30390 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f461e8045e220c3848b572cb5afd0e9db8d41681;p=platform%2Fupstream%2Fllvm.git [NFC] Judge if we have std c++ modules in RenderModulesOptions This patch moves the judgement if the std c++ modules feature is enabled into the RenderModulesOptions function. It simplify the code a little bit further more. It also helps further patches. --- diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 2dfd815..da8b715 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3660,10 +3660,19 @@ bool Driver::getDefaultModuleCachePath(SmallVectorImpl &Result) { return false; } -static void RenderModulesOptions(Compilation &C, const Driver &D, +static bool RenderModulesOptions(Compilation &C, const Driver &D, const ArgList &Args, const InputInfo &Input, - const InputInfo &Output, - ArgStringList &CmdArgs, bool &HaveModules) { + const InputInfo &Output, const Arg *Std, + ArgStringList &CmdArgs) { + bool IsCXX = types::isCXX(Input.getType()); + // FIXME: Find a better way to determine whether the input has standard c++ + // modules support by default. + bool HaveStdCXXModules = + IsCXX && Std && + (Std->containsValue("c++2a") || Std->containsValue("c++20") || + Std->containsValue("c++2b") || Std->containsValue("c++latest")); + bool HaveModules = HaveStdCXXModules; + // -fmodules enables the use of precompiled modules (off by default). // Users can pass -fno-cxx-modules to turn off modules support for // C++/Objective-C++ programs. @@ -3671,7 +3680,7 @@ static void RenderModulesOptions(Compilation &C, const Driver &D, if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules, false)) { bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules, true); - if (AllowedInCXX || !types::isCXX(Input.getType())) { + if (AllowedInCXX || !IsCXX) { CmdArgs.push_back("-fmodules"); HaveClangModules = true; } @@ -3842,6 +3851,8 @@ static void RenderModulesOptions(Compilation &C, const Driver &D, Args.ClaimAllArgs(options::OPT_fno_modules_validate_system_headers); Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation); } + + return HaveModules; } static void RenderCharacterOptions(const ArgList &Args, const llvm::Triple &T, @@ -6688,12 +6699,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ); - // FIXME: Find a better way to determine whether the language has modules - // support by default, or just assume that all languages do. bool HaveModules = - Std && (Std->containsValue("c++2a") || Std->containsValue("c++20") || - Std->containsValue("c++2b") || Std->containsValue("c++latest")); - RenderModulesOptions(C, D, Args, Input, Output, CmdArgs, HaveModules); + RenderModulesOptions(C, D, Args, Input, Output, Std, CmdArgs); if (Args.hasFlag(options::OPT_fpch_validate_input_files_content, options::OPT_fno_pch_validate_input_files_content, false))