[Coverage] Remove '..' from filenames *after* getting an absolute path

Failure to do this breaks relative paths which begin with '..'.

This issue was caught by the (still nascent) coverage bot.

llvm-svn: 275924
This commit is contained in:
Vedant Kumar 2016-07-18 22:32:02 +00:00
parent 4ced16dd2e
commit d04929d875
2 changed files with 16 additions and 5 deletions

View File

@ -932,8 +932,8 @@ StringRef getCoverageSection(const CodeGenModule &CGM) {
std::string normalizeFilename(StringRef Filename) {
llvm::SmallString<256> Path(Filename);
llvm::sys::path::remove_dots(Path, /*remove_dot_dots=*/true);
llvm::sys::fs::make_absolute(Path);
llvm::sys::path::remove_dots(Path, /*remove_dot_dots=*/true);
return Path.str().str();
}

View File

@ -1,7 +1,18 @@
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -main-file-name abspath.cpp %S/Inputs/../abspath.cpp -o - | FileCheck %s
// This test requires mkdir.
// REQUIRES: shell
//
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -main-file-name abspath.cpp %S/Inputs/../abspath.cpp -o - | FileCheck -check-prefix=RMDOTS %s
// CHECK: @__llvm_coverage_mapping = {{.*}}"\01
// CHECK-NOT: Inputs
// CHECK: "
// RMDOTS: @__llvm_coverage_mapping = {{.*}}"\01
// RMDOTS-NOT: Inputs
// RMDOTS: "
// RUN: cd %T && mkdir -p test && cd test
// RUN: echo "void f1() {}" > f1.c
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -main-file-name abspath.cpp ../test/f1.c -o - | FileCheck -check-prefix=RELPATH %s
// RELPATH: @__llvm_coverage_mapping = {{.*}}"\01
// RELPATH: test{{.*}}f1.c
// RELPATH: "
void f1() {}