diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -427,16 +427,16 @@ SmallString<128> DirBuf; SmallString<128> FileBuf; if (llvm::sys::path::is_absolute(RemappedFile)) { - // Strip the common prefix (if it is more than just "/") from current - // directory and FileName for a more space-efficient encoding. + // Strip the common prefix (if it is more than just "/" or "C:\") from + // current directory and FileName for a more space-efficient encoding. auto FileIt = llvm::sys::path::begin(RemappedFile); auto FileE = llvm::sys::path::end(RemappedFile); auto CurDirIt = llvm::sys::path::begin(CurDir); auto CurDirE = llvm::sys::path::end(CurDir); for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt) llvm::sys::path::append(DirBuf, *CurDirIt); - if (std::distance(llvm::sys::path::begin(CurDir), CurDirIt) == 1) { - // Don't strip the common prefix if it is only the root "/" + if (llvm::sys::path::root_path(DirBuf) == DirBuf) { + // Don't strip the common prefix if it is only the root ("/" or "C:\") // since that would make LLVM diagnostic locations confusing. Dir = {}; File = RemappedFile; diff --git a/clang/test/CodeGen/debug-prefix-map.c b/clang/test/CodeGen/debug-prefix-map.c --- a/clang/test/CodeGen/debug-prefix-map.c +++ b/clang/test/CodeGen/debug-prefix-map.c @@ -19,23 +19,21 @@ vprintf("string", argp); } -// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}" -// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}", -// On POSIX systems "Dir" should actually be empty, but on Windows we -// can't recognize "/UNLIKELY_PATH" as being an absolute path. -// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "{{()|(.*:.*)}}") -// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}Inputs{{/|\\\\}}stdio.h", -// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "{{()|(.*:.*)}}") +// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}" +// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}", +// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "") +// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}Inputs{{/|\\\\}}stdio.h", +// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "") // CHECK-NO-MAIN-FILE-NAME-NOT: !DIFile(filename: -// CHECK-EVIL: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH=empty{{/|\\\\}}{{.*}}" -// CHECK-EVIL: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH=empty{{/|\\\\}}{{.*}}Inputs{{/|\\\\}}stdio.h", -// CHECK-EVIL-SAME: directory: "{{()|(.*:.*)}}") +// CHECK-EVIL: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH=empty{{/|\\\\}}{{.*}}" +// CHECK-EVIL: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH=empty{{/|\\\\}}{{.*}}Inputs{{/|\\\\}}stdio.h", +// CHECK-EVIL-SAME: directory: "") // CHECK-EVIL-NOT: !DIFile(filename: -// CHECK: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}" -// CHECK: !DIFile(filename: "{{/|C:\\\\|()}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}Inputs{{/|\\\\}}stdio.h", -// CHECK-SAME: directory: "{{()|(.*:.*)}}") +// CHECK: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}" +// CHECK: !DIFile(filename: "{{/|C:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty{{/|\\\\}}{{.*}}Inputs{{/|\\\\}}stdio.h", +// CHECK-SAME: directory: "" // CHECK-NOT: !DIFile(filename: // CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}", directory: "{{/|C:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty")