aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-04-03 16:15:30 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-04-03 16:28:05 +0800
commit72c29fa9e226a928b3d3a01d74f6b44a0b31b7d4 (patch)
treea229874b804955d3afc72bee2c72ee629989badf /clang/lib
parent4dd103e9c65de7d3dbf12e76fbb72724127ec325 (diff)
downloadllvm-72c29fa9e226a928b3d3a01d74f6b44a0b31b7d4.zip
llvm-72c29fa9e226a928b3d3a01d74f6b44a0b31b7d4.tar.gz
llvm-72c29fa9e226a928b3d3a01d74f6b44a0b31b7d4.tar.bz2
[C++20] [Modules] [Driver] Emit unused argument warning if we use '-fmodule-output' with non-module input
We required the file name of an 'importable module unit' should end with .cppm (or .ccm, .cxxm, .c++m). But the driver can accept '-fmodule-output' for files with normal suffixes (e.g., .cpp). This is somewhat inconsistency. In this patch, we only claim the option `-fmodule-output` is used if the type of the input file is modules related. Then now the compiler will emit 'unused argument' warnings if the input file is not modules related.
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/ToolChains/Clang.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index b03ac60..7fd6ad6 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4045,9 +4045,18 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
// module fragment.
CmdArgs.push_back("-fskip-odr-check-in-gmf");
- // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings.
- Args.ClaimAllArgs(options::OPT_fmodule_output);
- Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+ // We need to include the case the input file is a module file here.
+ // Since the default compilation model for C++ module interface unit will
+ // create temporary module file and compile the temporary module file
+ // to get the object file. Then the `-fmodule-output` flag will be
+ // brought to the second compilation process. So we have to claim it for
+ // the case too.
+ if (Input.getType() == driver::types::TY_CXXModule ||
+ Input.getType() == driver::types::TY_PP_CXXModule ||
+ Input.getType() == driver::types::TY_ModuleFile) {
+ Args.ClaimAllArgs(options::OPT_fmodule_output);
+ Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
+ }
return HaveModules;
}