summaryrefslogtreecommitdiff
path: root/lib/Driver/ToolChains
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2019-09-26 18:13:19 +0000
committerReid Kleckner <rnk@google.com>2019-09-26 18:13:19 +0000
commitd09bf7265cb62f0d01eb4b685ac0b326ff189632 (patch)
treec618137cd25394cc6f3c6263518986e225eac25b /lib/Driver/ToolChains
parentc6e4e7210cd1f80a0492f6bf1dc1f717a1cf0351 (diff)
downloadclang-d09bf7265cb62f0d01eb4b685ac0b326ff189632.tar.gz
Only pass -coverage-notes-file when emitting coverage
The only functional change here is that -coverage-notes-file is not passed to -cc1 in some situations. This code appears to be trying to put the gcno and gcda output next to the final object file, but it's doing that in a really convoluted way that needs to be re-examined. It looks for -c or -S in the original command, and then looks at the -o argument if present in order to handle the -fno-integrated-as case. However, this doesn't work if this is a link command with multiple inputs. I looked into fixing this, but the check-profile test suite has a lot of dependencies on this behavior, so I left it all alone. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/ToolChains')
-rw-r--r--lib/Driver/ToolChains/Clang.cpp82
1 files changed, 46 insertions, 36 deletions
diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp
index 16c208b982..5484a9289c 100644
--- a/lib/Driver/ToolChains/Clang.cpp
+++ b/lib/Driver/ToolChains/Clang.cpp
@@ -832,12 +832,14 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
}
}
- if (Args.hasArg(options::OPT_ftest_coverage) ||
- Args.hasArg(options::OPT_coverage))
+ bool EmitCovNotes = Args.hasArg(options::OPT_ftest_coverage) ||
+ Args.hasArg(options::OPT_coverage);
+ bool EmitCovData = Args.hasFlag(options::OPT_fprofile_arcs,
+ options::OPT_fno_profile_arcs, false) ||
+ Args.hasArg(options::OPT_coverage);
+ if (EmitCovNotes)
CmdArgs.push_back("-femit-coverage-notes");
- if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
- false) ||
- Args.hasArg(options::OPT_coverage))
+ if (EmitCovData)
CmdArgs.push_back("-femit-coverage-data");
if (Args.hasFlag(options::OPT_fcoverage_mapping,
@@ -873,40 +875,48 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
CmdArgs.push_back(Args.MakeArgString(Twine("-fprofile-filter-files=" + v)));
}
- if (C.getArgs().hasArg(options::OPT_c) ||
- C.getArgs().hasArg(options::OPT_S)) {
- if (Output.isFilename()) {
- CmdArgs.push_back("-coverage-notes-file");
- SmallString<128> OutputFilename;
- if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
- OutputFilename = FinalOutput->getValue();
- else
- OutputFilename = llvm::sys::path::filename(Output.getBaseInput());
- SmallString<128> CoverageFilename = OutputFilename;
- if (llvm::sys::path::is_relative(CoverageFilename)) {
- SmallString<128> Pwd;
- if (!llvm::sys::fs::current_path(Pwd)) {
- llvm::sys::path::append(Pwd, CoverageFilename);
- CoverageFilename.swap(Pwd);
- }
+ // Leave -fprofile-dir= an unused argument unless .gcda emission is
+ // enabled. To be polite, with '-fprofile-arcs -fno-profile-arcs' consider
+ // the flag used. There is no -fno-profile-dir, so the user has no
+ // targeted way to suppress the warning.
+ Arg *FProfileDir = nullptr;
+ if (Args.hasArg(options::OPT_fprofile_arcs) ||
+ Args.hasArg(options::OPT_coverage))
+ FProfileDir = Args.getLastArg(options::OPT_fprofile_dir);
+
+ // Put the .gcno and .gcda files (if needed) next to the object file or
+ // bitcode file in the case of LTO.
+ // FIXME: There should be a simpler way to find the object file for this
+ // input, and this code probably does the wrong thing for commands that
+ // compile and link all at once.
+ if ((Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) &&
+ (EmitCovNotes || EmitCovData) && Output.isFilename()) {
+ SmallString<128> OutputFilename;
+ if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o))
+ OutputFilename = FinalOutput->getValue();
+ else
+ OutputFilename = llvm::sys::path::filename(Output.getBaseInput());
+ SmallString<128> CoverageFilename = OutputFilename;
+ if (llvm::sys::path::is_relative(CoverageFilename)) {
+ SmallString<128> Pwd;
+ if (!llvm::sys::fs::current_path(Pwd)) {
+ llvm::sys::path::append(Pwd, CoverageFilename);
+ CoverageFilename.swap(Pwd);
}
- llvm::sys::path::replace_extension(CoverageFilename, "gcno");
- CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
+ }
+ llvm::sys::path::replace_extension(CoverageFilename, "gcno");
- // Leave -fprofile-dir= an unused argument unless .gcda emission is
- // enabled. To be polite, with '-fprofile-arcs -fno-profile-arcs' consider
- // the flag used. There is no -fno-profile-dir, so the user has no
- // targeted way to suppress the warning.
- if (Args.hasArg(options::OPT_fprofile_arcs) ||
- Args.hasArg(options::OPT_coverage)) {
- CmdArgs.push_back("-coverage-data-file");
- if (Arg *FProfileDir = Args.getLastArg(options::OPT_fprofile_dir)) {
- CoverageFilename = FProfileDir->getValue();
- llvm::sys::path::append(CoverageFilename, OutputFilename);
- }
- llvm::sys::path::replace_extension(CoverageFilename, "gcda");
- CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
+ CmdArgs.push_back("-coverage-notes-file");
+ CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
+
+ if (EmitCovData) {
+ if (FProfileDir) {
+ CoverageFilename = FProfileDir->getValue();
+ llvm::sys::path::append(CoverageFilename, OutputFilename);
}
+ llvm::sys::path::replace_extension(CoverageFilename, "gcda");
+ CmdArgs.push_back("-coverage-data-file");
+ CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
}
}
}