r371853 - Fix depfile name construction
Luke Cheeseman via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 06:15:35 PDT 2019
Author: lukecheeseman
Date: Fri Sep 13 06:15:35 2019
New Revision: 371853
URL: http://llvm.org/viewvc/llvm-project?rev=371853&view=rev
Log:
Fix depfile name construction
- When using -o, the provided filename is using for constructing the depfile
name (when -MMD is passed).
- The logic looks for the rightmost '.' character and replaces what comes after
with 'd'.
- This works incorrectly when the filename has no extension and the directories
have '.' in them (e.g. out.dir/test)
- This replaces the funciton to just llvm::sys::path functionality
Differential Revision: https://reviews.llvm.org/D67542
Added:
cfe/trunk/test/Driver/metadata-with-dots.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=371853&r1=371852&r2=371853&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Sep 13 06:15:35 2019
@@ -6066,15 +6066,14 @@ const char *Clang::getBaseInputStem(cons
const char *Clang::getDependencyFileName(const ArgList &Args,
const InputInfoList &Inputs) {
// FIXME: Think about this more.
- std::string Res;
if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
- std::string Str(OutputOpt->getValue());
- Res = Str.substr(0, Str.rfind('.'));
- } else {
- Res = getBaseInputStem(Args, Inputs);
+ SmallString<128> OutputFilename(OutputOpt->getValue());
+ llvm::sys::path::replace_extension(OutputFilename, llvm::Twine('d'));
+ return Args.MakeArgString(OutputFilename);
}
- return Args.MakeArgString(Res + ".d");
+
+ return Args.MakeArgString(std::string(getBaseInputStem(Args, Inputs)) + ".d");
}
// Begin ClangAs
Added: cfe/trunk/test/Driver/metadata-with-dots.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/metadata-with-dots.c?rev=371853&view=auto
==============================================================================
--- cfe/trunk/test/Driver/metadata-with-dots.c (added)
+++ cfe/trunk/test/Driver/metadata-with-dots.c Fri Sep 13 06:15:35 2019
@@ -0,0 +1,11 @@
+// REQUIRES: shell
+// RUN: mkdir -p out.dir
+// RUN: cat %s > out.dir/test.c
+// RUN: %clang -E -MMD %s -o out.dir/test
+// RUN: test ! -f %out.d
+// RUN: test -f out.dir/test.d
+// RUN: rm -rf out.dir/test.d out.dir/ out.d
+int main (void)
+{
+ return 0;
+}
More information about the cfe-commits
mailing list