aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-04-02 09:52:52 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-04-02 09:58:59 +0800
commit21f85e230056172cffcaec76352e5a2019b54b86 (patch)
treee3b3bbf1935b9ca35666f0c87b8935e96f4496d7 /clang/lib
parent38113a083283d2f30a677befaa5fb86dce731c8b (diff)
downloadllvm-21f85e230056172cffcaec76352e5a2019b54b86.zip
llvm-21f85e230056172cffcaec76352e5a2019b54b86.tar.gz
llvm-21f85e230056172cffcaec76352e5a2019b54b86.tar.bz2
[NFC] [C++20] [Modules] Pulling out getCXX20NamedModuleOutputPath into a seperate function
Required in the review process of https://github.com/llvm/llvm-project/pull/85050.
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/Driver.cpp14
-rw-r--r--clang/lib/Driver/ToolChains/Clang.cpp18
-rw-r--r--clang/lib/Driver/ToolChains/Clang.h15
3 files changed, 35 insertions, 12 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7a53764..1a0f5f2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5814,19 +5814,9 @@ static const char *GetModuleOutputPath(Compilation &C, const JobAction &JA,
(C.getArgs().hasArg(options::OPT_fmodule_output) ||
C.getArgs().hasArg(options::OPT_fmodule_output_EQ)));
- if (Arg *ModuleOutputEQ =
- C.getArgs().getLastArg(options::OPT_fmodule_output_EQ))
- return C.addResultFile(ModuleOutputEQ->getValue(), &JA);
+ SmallString<256> OutputPath =
+ tools::getCXX20NamedModuleOutputPath(C.getArgs(), BaseInput);
- SmallString<64> OutputPath;
- Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
- if (FinalOutput && C.getArgs().hasArg(options::OPT_c))
- OutputPath = FinalOutput->getValue();
- else
- OutputPath = BaseInput;
-
- const char *Extension = types::getTypeTempSuffix(JA.getType());
- llvm::sys::path::replace_extension(OutputPath, Extension);
return C.addResultFile(C.getArgs().MakeArgString(OutputPath.c_str()), &JA);
}
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 3bcacff..b03ac60 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3839,6 +3839,24 @@ bool Driver::getDefaultModuleCachePath(SmallVectorImpl<char> &Result) {
return false;
}
+llvm::SmallString<256>
+clang::driver::tools::getCXX20NamedModuleOutputPath(const ArgList &Args,
+ const char *BaseInput) {
+ if (Arg *ModuleOutputEQ = Args.getLastArg(options::OPT_fmodule_output_EQ))
+ return StringRef(ModuleOutputEQ->getValue());
+
+ SmallString<256> OutputPath;
+ if (Arg *FinalOutput = Args.getLastArg(options::OPT_o);
+ FinalOutput && Args.hasArg(options::OPT_c))
+ OutputPath = FinalOutput->getValue();
+ else
+ OutputPath = BaseInput;
+
+ const char *Extension = types::getTypeTempSuffix(types::TY_ModuleFile);
+ llvm::sys::path::replace_extension(OutputPath, Extension);
+ return OutputPath;
+}
+
static bool RenderModulesOptions(Compilation &C, const Driver &D,
const ArgList &Args, const InputInfo &Input,
const InputInfo &Output, bool HaveStd20,
diff --git a/clang/lib/Driver/ToolChains/Clang.h b/clang/lib/Driver/ToolChains/Clang.h
index 0f503c4..18f6c5e 100644
--- a/clang/lib/Driver/ToolChains/Clang.h
+++ b/clang/lib/Driver/ToolChains/Clang.h
@@ -193,6 +193,21 @@ DwarfFissionKind getDebugFissionKind(const Driver &D,
const llvm::opt::ArgList &Args,
llvm::opt::Arg *&Arg);
+// Calculate the output path of the module file when compiling a module unit
+// with the `-fmodule-output` option or `-fmodule-output=` option specified.
+// The behavior is:
+// - If `-fmodule-output=` is specfied, then the module file is
+// writing to the value.
+// - Otherwise if the output object file of the module unit is specified, the
+// output path
+// of the module file should be the same with the output object file except
+// the corresponding suffix. This requires both `-o` and `-c` are specified.
+// - Otherwise, the output path of the module file will be the same with the
+// input with the corresponding suffix.
+llvm::SmallString<256>
+getCXX20NamedModuleOutputPath(const llvm::opt::ArgList &Args,
+ const char *BaseInput);
+
} // end namespace tools
} // end namespace driver