Skip to content

Commit ab9acda

Browse files
author
Luke Cheeseman
committedSep 13, 2019
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 llvm-svn: 371853
1 parent d48ea5d commit ab9acda

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
 

Diff for: ‎clang/lib/Driver/ToolChains/Clang.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -6066,15 +6066,14 @@ const char *Clang::getBaseInputStem(const ArgList &Args,
60666066
const char *Clang::getDependencyFileName(const ArgList &Args,
60676067
const InputInfoList &Inputs) {
60686068
// FIXME: Think about this more.
6069-
std::string Res;
60706069

60716070
if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
6072-
std::string Str(OutputOpt->getValue());
6073-
Res = Str.substr(0, Str.rfind('.'));
6074-
} else {
6075-
Res = getBaseInputStem(Args, Inputs);
6071+
SmallString<128> OutputFilename(OutputOpt->getValue());
6072+
llvm::sys::path::replace_extension(OutputFilename, llvm::Twine('d'));
6073+
return Args.MakeArgString(OutputFilename);
60766074
}
6077-
return Args.MakeArgString(Res + ".d");
6075+
6076+
return Args.MakeArgString(std::string(getBaseInputStem(Args, Inputs)) + ".d");
60786077
}
60796078

60806079
// Begin ClangAs

Diff for: ‎clang/test/Driver/metadata-with-dots.c

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// REQUIRES: shell
2+
// RUN: mkdir -p out.dir
3+
// RUN: cat %s > out.dir/test.c
4+
// RUN: %clang -E -MMD %s -o out.dir/test
5+
// RUN: test ! -f %out.d
6+
// RUN: test -f out.dir/test.d
7+
// RUN: rm -rf out.dir/test.d out.dir/ out.d
8+
int main (void)
9+
{
10+
return 0;
11+
}

0 commit comments

Comments
 (0)
Please sign in to comment.