Skip to content

Commit 2499ff2

Browse files
committed
[Driver][Summary] implement emitting summary next to the object file
1 parent 49937a6 commit 2499ff2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5473,7 +5473,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54735473
if (Args.getLastArg(options::OPT_summaries_dir_EQ))
54745474
Args.AddLastArg(CmdArgs, options::OPT_summaries_dir_EQ);
54755475

5476-
// FIXME: This needs to be cleaned up and needs proper error handling as well.
54775476
if (const Arg *A = Args.getLastArg(options::OPT_emit_summaries_EQ)) {
54785477
llvm::SmallString<10> input;
54795478
for (const auto &II : Inputs) {
@@ -5485,14 +5484,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54855484
}
54865485

54875486
if (!input.empty()) {
5488-
if (A->containsValue("cwd")) {
5489-
llvm::SmallString<10> filename = llvm::sys::path::filename(input);
5490-
llvm::sys::path::replace_extension(filename, "json");
5487+
Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
5488+
StringRef filename = llvm::sys::path::filename(input);
5489+
llvm::SmallString<10> summaryFile;
5490+
5491+
if (A->containsValue("cwd") || !FinalOutput) {
5492+
summaryFile = filename;
5493+
} else if (A->containsValue("obj") && FinalOutput) {
5494+
summaryFile = llvm::sys::path::parent_path(FinalOutput->getValue());
5495+
llvm::sys::path::append(summaryFile, filename);
5496+
}
54915497

5498+
if (!summaryFile.empty()) {
5499+
llvm::sys::path::replace_extension(summaryFile, "json");
54925500
CmdArgs.push_back(
5493-
Args.MakeArgString(Twine("-summary-file=") + filename));
5494-
} else if (A->containsValue("obj")) {
5495-
// FIXME: implement
5501+
Args.MakeArgString(Twine("-summary-file=") + summaryFile));
54965502
}
54975503
}
54985504
}

0 commit comments

Comments
 (0)