[llvm] e972e49 - [llvm-cov] Add error for invalid -path-equivalence format

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 10 18:35:24 PDT 2021


Author: Keith Smiley
Date: 2021-09-10T18:34:37-07:00
New Revision: e972e49b110928c9a682538be9b99bbf6b1e6c04

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

LOG: [llvm-cov] Add error for invalid -path-equivalence format

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

Added: 
    

Modified: 
    llvm/test/tools/llvm-cov/path_equivalence.c
    llvm/tools/llvm-cov/CodeCoverage.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-cov/path_equivalence.c b/llvm/test/tools/llvm-cov/path_equivalence.c
index c5e8f6cfa50df..26a35b78d2d74 100644
--- a/llvm/test/tools/llvm-cov/path_equivalence.c
+++ b/llvm/test/tools/llvm-cov/path_equivalence.c
@@ -2,3 +2,6 @@
 // RUN: llvm-cov show %S/Inputs/path_equivalence.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp,%S | FileCheck %s
 // RUN: llvm-cov show %S/Inputs/path_equivalence.covmapping -instr-profile=%t.profdata -path-equivalence=/tmp/,%S/ | FileCheck %s
 int main() {} // CHECK: [[@LINE]]|      1|int main() {}
+
+// RUN: not llvm-cov show --instr-profile=/dev/null -path-equivalence=foo /dev/null 2>&1 | FileCheck --check-prefix=INVALID %s
+// INVALID: error: -path-equivalence: invalid argument 'foo', must be in format 'from,to'

diff  --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp
index 02c0106cbc29e..5c9ff41a2d5d6 100644
--- a/llvm/tools/llvm-cov/CodeCoverage.cpp
+++ b/llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -784,10 +784,18 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
 
     // If path-equivalence was given and is a comma seperated pair then set
     // PathRemapping.
-    auto EquivPair = StringRef(PathRemap).split(',');
-    if (!(EquivPair.first.empty() && EquivPair.second.empty()))
+    if (!PathRemap.empty()) {
+      auto EquivPair = StringRef(PathRemap).split(',');
+      if (EquivPair.first.empty() || EquivPair.second.empty()) {
+        error("invalid argument '" + PathRemap +
+                  "', must be in format 'from,to'",
+              "-path-equivalence");
+        return 1;
+      }
+
       PathRemapping = {std::string(EquivPair.first),
                        std::string(EquivPair.second)};
+    }
 
     // If a demangler is supplied, check if it exists and register it.
     if (!DemanglerOpts.empty()) {


        


More information about the llvm-commits mailing list