[llvm] r301371 - [gcov] Sort file info before printing it
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 17:16:11 PDT 2017
Author: vedantk
Date: Tue Apr 25 19:16:10 2017
New Revision: 301371
URL: http://llvm.org/viewvc/llvm-project?rev=301371&view=rev
Log:
[gcov] Sort file info before printing it
The order in which GCOV file info is printed depends on the string hash
function. This makes some GCOV tests brittle, because the tests must be
updated whenever the hash function changes.
Sort the filenames before printing out the file info to solve the
problem. This should be relatively cheap.
Differential Revision: https://reviews.llvm.org/D32512
Modified:
llvm/trunk/lib/IR/GCOV.cpp
llvm/trunk/test/tools/llvm-cov/Inputs/test_-b.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_-f.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_long_file_names.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_long_paths.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_missing.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_no_output.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_no_preserve_paths.output
llvm/trunk/test/tools/llvm-cov/Inputs/test_preserve_paths.output
Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Tue Apr 25 19:16:10 2017
@@ -589,8 +589,12 @@ FileInfo::openCoveragePath(StringRef Cov
/// print - Print source files with collected line count information.
void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
StringRef GCNOFile, StringRef GCDAFile) {
- for (const auto &LI : LineInfo) {
- StringRef Filename = LI.first();
+ SmallVector<StringRef, 4> Filenames;
+ for (const auto &LI : LineInfo)
+ Filenames.push_back(LI.first());
+ std::sort(Filenames.begin(), Filenames.end());
+
+ for (StringRef Filename : Filenames) {
auto AllLines = LineConsumer(Filename);
std::string CoveragePath = getCoveragePath(Filename, MainFilename);
@@ -603,7 +607,7 @@ void FileInfo::print(raw_ostream &InfoOS
CovOS << " -: 0:Runs:" << RunCount << "\n";
CovOS << " -: 0:Programs:" << ProgramCount << "\n";
- const LineData &Line = LI.second;
+ const LineData &Line = LineInfo[Filename];
GCOVCoverage FileCoverage(Filename);
for (uint32_t LineIndex = 0; LineIndex < Line.LastLine || !AllLines.empty();
++LineIndex) {
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_-b.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_-b.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_-b.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_-b.output Tue Apr 25 19:16:10 2017
@@ -1,3 +1,9 @@
+File './test.h'
+Lines executed:100.00% of 1
+No branches
+No calls
+./test.h:creating 'test.h.gcov'
+
File 'test.cpp'
Lines executed:84.21% of 38
Branches executed:100.00% of 15
@@ -5,9 +11,3 @@ Taken at least once:86.67% of 15
No calls
test.cpp:creating 'test.cpp.gcov'
-File './test.h'
-Lines executed:100.00% of 1
-No branches
-No calls
-./test.h:creating 'test.h.gcov'
-
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_-f.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_-f.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_-f.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_-f.output Tue Apr 25 19:16:10 2017
@@ -1,3 +1,9 @@
+Function '_ZN1AC1Ev'
+Lines executed:100.00% of 1
+
+Function '_ZN1AC2Ev'
+Lines executed:100.00% of 1
+
Function '_ZN1A1BEv'
Lines executed:100.00% of 1
@@ -22,17 +28,11 @@ Lines executed:100.00% of 4
Function 'main'
Lines executed:91.67% of 24
-Function '_ZN1AC1Ev'
-Lines executed:100.00% of 1
-
-Function '_ZN1AC2Ev'
+File './test.h'
Lines executed:100.00% of 1
+./test.h:creating 'test.h.gcov'
File 'test.cpp'
Lines executed:84.21% of 38
test.cpp:creating 'test.cpp.gcov'
-File './test.h'
-Lines executed:100.00% of 1
-./test.h:creating 'test.h.gcov'
-
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_long_file_names.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_long_file_names.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_long_file_names.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_long_file_names.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'test_paths.cpp##test.h.gcov'
-
File 'srcdir/./nested_dir/../test.cpp'
Lines executed:84.21% of 38
srcdir/./nested_dir/../test.cpp:creating 'test_paths.cpp##test.cpp.gcov'
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'test_paths.cpp##test.h.gcov'
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_long_paths.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_long_paths.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_long_paths.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_long_paths.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.h.gcov'
-
File 'srcdir/./nested_dir/../test.cpp'
Lines executed:84.21% of 38
srcdir/./nested_dir/../test.cpp:creating 'srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.cpp.gcov'
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.h.gcov'
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_missing.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_missing.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_missing.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_missing.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
-
File 'srcdir/./nested_dir/../test.cpp'
Lines executed:84.21% of 38
srcdir/./nested_dir/../test.cpp:creating 'test.cpp.gcov'
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_no_gcda.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'test.cpp'
-Lines executed:0.00% of 38
-test.cpp:creating 'test.cpp.gcov'
-
File './test.h'
Lines executed:0.00% of 1
./test.h:creating 'test.h.gcov'
+File 'test.cpp'
+Lines executed:0.00% of 38
+test.cpp:creating 'test.cpp.gcov'
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_no_options.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'test.cpp'
-Lines executed:84.21% of 38
-test.cpp:creating 'test.cpp.gcov'
-
File './test.h'
Lines executed:100.00% of 1
./test.h:creating 'test.h.gcov'
+File 'test.cpp'
+Lines executed:84.21% of 38
+test.cpp:creating 'test.cpp.gcov'
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_no_output.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_no_output.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_no_output.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_no_output.output Tue Apr 25 19:16:10 2017
@@ -1,6 +1,6 @@
-File 'test.cpp'
-Lines executed:84.21% of 38
-
File './test.h'
Lines executed:100.00% of 1
+File 'test.cpp'
+Lines executed:84.21% of 38
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_no_preserve_paths.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_no_preserve_paths.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_no_preserve_paths.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_no_preserve_paths.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
-
File 'srcdir/./nested_dir/../test.cpp'
Lines executed:84.21% of 38
srcdir/./nested_dir/../test.cpp:creating 'test.cpp.gcov'
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
+
Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_preserve_paths.output
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_preserve_paths.output?rev=301371&r1=301370&r2=301371&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/Inputs/test_preserve_paths.output (original)
+++ llvm/trunk/test/tools/llvm-cov/Inputs/test_preserve_paths.output Tue Apr 25 19:16:10 2017
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'srcdir#nested_dir#^#test.h.gcov'
-
File 'srcdir/./nested_dir/../test.cpp'
Lines executed:84.21% of 38
srcdir/./nested_dir/../test.cpp:creating 'srcdir#nested_dir#^#test.cpp.gcov'
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'srcdir#nested_dir#^#test.h.gcov'
+
More information about the llvm-commits
mailing list