[llvm-cov] Add error for invalid -path-equivalence format
authorKeith Smiley <keithbsmiley@gmail.com>
Wed, 1 Sep 2021 05:35:44 +0000 (22:35 -0700)
committerKeith Smiley <keithbsmiley@gmail.com>
Sat, 11 Sep 2021 01:34:37 +0000 (18:34 -0700)
Differential Revision: https://reviews.llvm.org/D109042

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

index c5e8f6c..26a35b7 100644 (file)
@@ -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'
index 02c0106..5c9ff41 100644 (file)
@@ -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()) {