[clang] f461e80 - [NFC] Judge if we have std c++ modules in RenderModulesOptions
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 17 00:51:44 PDT 2022
Author: Chuanqi Xu
Date: 2022-10-17T15:51:02+08:00
New Revision: f461e8045e220c3848b572cb5afd0e9db8d41681
URL: https://github.com/llvm/llvm-project/commit/f461e8045e220c3848b572cb5afd0e9db8d41681
DIFF: https://github.com/llvm/llvm-project/commit/f461e8045e220c3848b572cb5afd0e9db8d41681.diff
LOG: [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.
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 2dfd815c5c93e..da8b715a76984 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3660,10 +3660,19 @@ bool Driver::getDefaultModuleCachePath(SmallVectorImpl<char> &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))
More information about the cfe-commits
mailing list