diff --git a/llvm/include/llvm/ProfileData/GCOV.h b/llvm/include/llvm/ProfileData/GCOV.h --- a/llvm/include/llvm/ProfileData/GCOV.h +++ b/llvm/include/llvm/ProfileData/GCOV.h @@ -214,6 +214,9 @@ SmallVectorImpl>::const_iterator>; iterator begin() const { return iterator(functions.begin()); } iterator end() const { return iterator(functions.end()); } + +private: + unsigned addNormalizedPathToMap(StringRef filename); }; struct GCOVArc { diff --git a/llvm/lib/ProfileData/GCOV.cpp b/llvm/lib/ProfileData/GCOV.cpp --- a/llvm/lib/ProfileData/GCOV.cpp +++ b/llvm/lib/ProfileData/GCOV.cpp @@ -140,10 +140,7 @@ if (version >= GCOV::V900) fn->endColumn = buf.getWord(); } - auto r = filenameToIdx.try_emplace(filename, filenameToIdx.size()); - if (r.second) - filenames.emplace_back(filename); - fn->srcIdx = r.first->second; + fn->srcIdx = addNormalizedPathToMap(filename); identToFunction[fn->ident] = fn; } else if (tag == GCOV_TAG_BLOCKS && fn) { if (version < GCOV::V800) { @@ -326,6 +323,19 @@ LLVM_DUMP_METHOD void GCOVFile::dump() const { print(dbgs()); } #endif +unsigned GCOVFile::addNormalizedPathToMap(StringRef filename) { + // unify filename, as the same path can have different form + SmallString<256> P(filename); + sys::path::remove_dots(P, true); + filename = P.str(); + + auto r = filenameToIdx.try_emplace(filename, filenameToIdx.size()); + if (r.second) + filenames.emplace_back(filename); + + return r.first->second; +} + bool GCOVArc::onTree() const { return flags & GCOV_ARC_ON_TREE; } //===----------------------------------------------------------------------===// diff --git a/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_gcda.h.gcov b/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_gcda.h.gcov --- a/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_gcda.h.gcov +++ b/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_gcda.h.gcov @@ -1,4 +1,4 @@ - -: 0:Source:./test.h + -: 0:Source:test.h -: 0:Graph:test.gcno -: 0:Data:- -: 0:Runs:0 diff --git a/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_options.h.gcov b/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_options.h.gcov --- a/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_options.h.gcov +++ b/llvm/test/tools/llvm-cov/gcov/Inputs/test_no_options.h.gcov @@ -1,4 +1,4 @@ - -: 0:Source:./test.h + -: 0:Source:test.h -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 diff --git a/llvm/test/tools/llvm-cov/gcov/basic.test b/llvm/test/tools/llvm-cov/gcov/basic.test --- a/llvm/test/tools/llvm-cov/gcov/basic.test +++ b/llvm/test/tools/llvm-cov/gcov/basic.test @@ -43,14 +43,14 @@ RUN: llvm-cov gcov test_paths.cpp 2>/dev/null | FileCheck %s --check-prefix=MISSING RUN: ls a.c.gcov -MISSING: File 'src/./n/../a.c' +MISSING: File 'src/a.c' MISSING: Creating 'a.c.gcov' # Preserve paths. This mangles the output filenames. RUN: llvm-cov gcov -p test_paths.cpp 2>/dev/null | FileCheck %s --check-prefix=PRESERVE -RUN: ls src#n#^#a.c.gcov -PRESERVE: File 'src/./n/../a.c' -PRESERVE: Creating 'src#n#^#a.c.gcov' +RUN: ls src#a.c.gcov +PRESERVE: File 'src/a.c' +PRESERVE: Creating 'src#a.c.gcov' # Long file names. RUN: llvm-cov gcov -l test_paths.cpp @@ -58,11 +58,11 @@ # Long file names and preserve paths. RUN: mkdir -p src && llvm-cov gcov -lp -gcno test_paths.gcno -gcda test_paths.gcda src/../test_paths.cpp -RUN: ls src#^#test_paths.cpp##src#n#^#a.c.gcov +RUN: ls src#^#test_paths.cpp##src#a.c.gcov # Hash pathnames. RUN: llvm-cov gcov -x -gcno test_paths.gcno -gcda test_paths.gcda src/../test_paths.cpp -RUN: ls a.c##4784150e272908907eaa7380ca3eced8.gcov +RUN: ls a.c##0c546a4dd99c1774b7b06e4fad16158c.gcov # Function summaries. This changes stdout, but not the gcov files. RUN: llvm-cov gcov test.c -f | FileCheck %s --check-prefixes=OUT,OUTFILE,OUT-F @@ -136,7 +136,7 @@ OUT-B-NEXT:No calls OUTFILE-NEXT:Creating 'test.cpp.gcov' OUT-EMPTY: - OUT-NEXT:File './test.h' + OUT-NEXT:File 'test.h' OUT-NEXT:Lines executed:100.00% of 1 OUT-B-NEXT:No branches OUT-B-NEXT:No calls @@ -160,7 +160,7 @@ NO-GCDA-NEXT: Lines executed:0.00% of 43 NO-GCDA-NEXT: Creating 'test.cpp.gcov' NO-GCDA-EMPTY: -NO-GCDA-NEXT: File './test.h' +NO-GCDA-NEXT: File 'test.h' NO-GCDA-NEXT: Lines executed:0.00% of 1 NO-GCDA-NEXT: Creating 'test.h.gcov' @@ -361,7 +361,7 @@ C-NEXT: -: 73: return more_useless(); C-NEXT: -: 74:} - H: -: 0:Source:./test.h + H: -: 0:Source:test.h H-NEXT: -: 0:Graph:test.gcno H-NEXT: -: 0:Data:test.gcda H-NEXT: -: 0:Runs:1 diff --git a/llvm/test/tools/llvm-cov/gcov/gcov-fake-4.2.c b/llvm/test/tools/llvm-cov/gcov/gcov-fake-4.2.c --- a/llvm/test/tools/llvm-cov/gcov/gcov-fake-4.2.c +++ b/llvm/test/tools/llvm-cov/gcov/gcov-fake-4.2.c @@ -10,7 +10,7 @@ // CHECK-NEXT: Lines executed:84.21% of 38 // CHECK-NEXT: Creating 'test.cpp.gcov' // CHECK-EMPTY: -// CHECK-NEXT: File './test.h' +// CHECK-NEXT: File 'test.h' // CHECK-NEXT: Lines executed:100.00% of 1 // CHECK-NEXT: Creating 'test.h.gcov' // CHECK-EMPTY: @@ -32,7 +32,7 @@ // C-NEXT: -: 9: // C-NEXT:8589934592: 10: -// H: -: 0:Source:./test.h +// H: -: 0:Source:test.h // H-NEXT: -: 0:Graph:{{.*}}gcov-fake-4.2.gcno // H-NEXT: -: 0:Data:{{.*}}gcov-fake-4.2.gcda // H-NEXT: -: 0:Runs:2 diff --git a/llvm/test/tools/llvm-cov/gcov/intermediate-format.test b/llvm/test/tools/llvm-cov/gcov/intermediate-format.test --- a/llvm/test/tools/llvm-cov/gcov/intermediate-format.test +++ b/llvm/test/tools/llvm-cov/gcov/intermediate-format.test @@ -31,7 +31,7 @@ OUT-B-NEXT:Taken at least once:86.67% of 15 OUT-B-NEXT:No calls OUT-EMPTY: - OUT-NEXT:File './test.h' + OUT-NEXT:File 'test.h' OUT-NEXT:Lines executed:100.00% of 1 OUT-B-NEXT:No branches OUT-B-NEXT:No calls @@ -50,6 +50,6 @@ I:lcount:33,3 I-B-NEXT:branch:33,taken I-B-NEXT:branch:33,taken - I:file:./test.h + I:file:test.h I-NEXT:function:2,1,_ZN1AC2Ev I-NEXT:lcount:2,1