diff --git a/llvm/test/tools/llvm-cov/path_equivalence.c b/llvm/test/tools/llvm-cov/path_equivalence.c --- 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 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -784,10 +784,18 @@ // 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()) {