[llvm] ff6dc05 - [Coverage][Unittest] Fix stringref issue

Jinsong Ji via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 06:59:51 PST 2021


Author: Jinsong Ji
Date: 2021-02-24T14:59:40Z
New Revision: ff6dc053b7ba8ffb7d02c9c4560fe80b66b117b8

URL: https://github.com/llvm/llvm-project/commit/ff6dc053b7ba8ffb7d02c9c4560fe80b66b117b8
DIFF: https://github.com/llvm/llvm-project/commit/ff6dc053b7ba8ffb7d02c9c4560fe80b66b117b8.diff

LOG: [Coverage][Unittest] Fix stringref issue

We will pass StringRef and change it in reader.
But we reuse the same Filename vector without clear it,
so in some systems, we may clobbeer previous results.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D97353

Added: 
    

Modified: 
    llvm/unittests/ProfileData/CoverageMappingTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index 44b7a13334d4..d1bb87ae966a 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -201,6 +201,9 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> {
 
   void readCoverageRegions(const std::string &Coverage,
                            OutputFunctionCoverageData &Data) {
+    // We will re-use the StringRef in duplicate tests, clear it to avoid
+    // clobber previous ones.
+    Filenames.clear();
     Filenames.resize(Files.size() + 1);
     for (const auto &E : Files)
       Filenames[E.getValue()] = E.getKey().str();


        


More information about the llvm-commits mailing list