[llvm] f081150 - [gcov] Implement --stdout -t
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun May 10 21:02:48 PDT 2020
Author: Fangrui Song
Date: 2020-05-10T21:02:38-07:00
New Revision: f081150c4dc0131c5c7db904ea5070be037ea6d1
URL: https://github.com/llvm/llvm-project/commit/f081150c4dc0131c5c7db904ea5070be037ea6d1
DIFF: https://github.com/llvm/llvm-project/commit/f081150c4dc0131c5c7db904ea5070be037ea6d1.diff
LOG: [gcov] Implement --stdout -t
gcov by default prints to a .gcov file. With --stdout, stdout is used.
Some summary information is omitted. There is no separator for multiple
source files.
Added:
Modified:
llvm/include/llvm/ProfileData/GCOV.h
llvm/lib/ProfileData/GCOV.cpp
llvm/test/tools/llvm-cov/llvm-cov.test
llvm/tools/llvm-cov/gcov.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ProfileData/GCOV.h b/llvm/include/llvm/ProfileData/GCOV.h
index 1aabf3b65b62..467772be5ed5 100644
--- a/llvm/include/llvm/ProfileData/GCOV.h
+++ b/llvm/include/llvm/ProfileData/GCOV.h
@@ -45,10 +45,11 @@ enum GCOVVersion { V402, V407, V800, V900 };
/// A struct for passing gcov options between functions.
struct Options {
- Options(bool A, bool B, bool C, bool F, bool P, bool U, bool L, bool N, bool X)
+ Options(bool A, bool B, bool C, bool F, bool P, bool U, bool L, bool N,
+ bool T, bool X)
: AllBlocks(A), BranchInfo(B), BranchCount(C), FuncCoverage(F),
PreservePaths(P), UncondBranch(U), LongFileNames(L), NoOutput(N),
- HashFilenames(X) {}
+ UseStdout(T), HashFilenames(X) {}
bool AllBlocks;
bool BranchInfo;
@@ -58,6 +59,7 @@ struct Options {
bool UncondBranch;
bool LongFileNames;
bool NoOutput;
+ bool UseStdout;
bool HashFilenames;
};
diff --git a/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp
index d96955292b6d..e8e0629f726f 100644
--- a/llvm/lib/ProfileData/GCOV.cpp
+++ b/llvm/lib/ProfileData/GCOV.cpp
@@ -650,9 +650,6 @@ std::string FileInfo::getCoveragePath(StringRef Filename,
std::unique_ptr<raw_ostream>
FileInfo::openCoveragePath(StringRef CoveragePath) {
- if (Options.NoOutput)
- return std::make_unique<raw_null_ostream>();
-
std::error_code EC;
auto OS =
std::make_unique<raw_fd_ostream>(CoveragePath, EC, sys::fs::OF_Text);
@@ -676,8 +673,13 @@ void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
auto AllLines = LineConsumer(Filename);
std::string CoveragePath = getCoveragePath(Filename, MainFilename);
- std::unique_ptr<raw_ostream> CovStream = openCoveragePath(CoveragePath);
- raw_ostream &CovOS = *CovStream;
+ std::unique_ptr<raw_ostream> CovStream;
+ if (Options.NoOutput)
+ CovStream = std::make_unique<raw_null_ostream>();
+ else if (!Options.UseStdout)
+ CovStream = openCoveragePath(CoveragePath);
+ raw_ostream &CovOS =
+ !Options.NoOutput && Options.UseStdout ? llvm::outs() : *CovStream;
CovOS << " -: 0:Source:" << Filename << "\n";
CovOS << " -: 0:Graph:" << GCNOFile << "\n";
@@ -774,10 +776,12 @@ void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
FileCoverages.push_back(std::make_pair(CoveragePath, FileCoverage));
}
- // FIXME: There is no way to detect calls given current instrumentation.
- if (Options.FuncCoverage)
- printFuncCoverage(InfoOS);
- printFileCoverage(InfoOS);
+ if (!Options.UseStdout) {
+ // FIXME: There is no way to detect calls given current instrumentation.
+ if (Options.FuncCoverage)
+ printFuncCoverage(InfoOS);
+ printFileCoverage(InfoOS);
+ }
}
/// printFunctionSummary - Print function and block summary.
diff --git a/llvm/test/tools/llvm-cov/llvm-cov.test b/llvm/test/tools/llvm-cov/llvm-cov.test
index 38fc065adc75..c1d904ed5083 100644
--- a/llvm/test/tools/llvm-cov/llvm-cov.test
+++ b/llvm/test/tools/llvm-cov/llvm-cov.test
@@ -35,6 +35,12 @@ RUN:
diff -aub test_objdir.h.gcov test.h.gcov
# With gcov output disabled
RUN: llvm-cov gcov -n test.c |
diff -u test_no_output.output -
+# Print to stdout.
+RUN: llvm-cov gcov -t test.c > stdout
+RUN: llvm-cov gcov --stdout test.c | cmp stdout -
+RUN: cat test_no_options.h.gcov test_no_options.cpp.gcov |
diff -u - stdout
+RUN: llvm-cov gcov -n -t test.c | count 0
+
# Missing source files. This test is fragile, as it depends on being
# run before we copy some sources into place in the next test.
RUN: llvm-cov gcov test_paths.cpp 2>/dev/null |
diff -u test_missing.output -
diff --git a/llvm/tools/llvm-cov/gcov.cpp b/llvm/tools/llvm-cov/gcov.cpp
index f1bca90e0b2a..bd3b6bef9e7c 100644
--- a/llvm/tools/llvm-cov/gcov.cpp
+++ b/llvm/tools/llvm-cov/gcov.cpp
@@ -119,6 +119,10 @@ int gcovMain(int argc, const char *argv[]) {
cl::desc("Preserve path components"));
cl::alias PreservePathsA("preserve-paths", cl::aliasopt(PreservePaths));
+ cl::opt<bool> UseStdout("t", cl::Grouping, cl::init(false),
+ cl::desc("Print to stdout"));
+ cl::alias UseStdoutA("stdout", cl::aliasopt(UseStdout));
+
cl::opt<bool> UncondBranch("u", cl::Grouping, cl::init(false),
cl::desc("Display unconditional branch info "
"(requires -b)"));
@@ -141,7 +145,7 @@ int gcovMain(int argc, const char *argv[]) {
GCOV::Options Options(AllBlocks, BranchProb, BranchCount, FuncSummary,
PreservePaths, UncondBranch, LongNames, NoOutput,
- HashFilenames);
+ UseStdout, HashFilenames);
for (const auto &SourceFile : SourceFiles)
reportCoverage(SourceFile, ObjectDir, InputGCNO, InputGCDA, DumpGCOV,
More information about the llvm-commits
mailing list