[PATCH] D67542: Fix depfile name construction

Luke Cheeseman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 03:25:20 PDT 2019


LukeCheeseman updated this revision to Diff 220067.
LukeCheeseman added a comment.

- Add a requires shell


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67542/new/

https://reviews.llvm.org/D67542

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/metadata-with-dots.c


Index: clang/test/Driver/metadata-with-dots.c
===================================================================
--- /dev/null
+++ clang/test/Driver/metadata-with-dots.c
@@ -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;
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6332,15 +6332,14 @@
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67542.220067.patch
Type: text/x-patch
Size: 1406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190913/1d7469ee/attachment.bin>


More information about the cfe-commits mailing list