Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -434,37 +434,40 @@ CGDebugInfo::createFile(StringRef FileName, Optional> CSInfo, Optional Source) { - StringRef Dir; - StringRef File; - std::string RemappedFile = remapDIPath(FileName); - std::string CurDir = remapDIPath(getCurrentDirname()); + auto TargetStyle = CGM.getTarget().getTriple().isOSWindows() + ? llvm::sys::path::Style::windows + : llvm::sys::path::Style::posix; + + SmallString<128> RemappedFile; + SmallString<128> CurDir; + llvm::sys::path::native(remapDIPath(FileName), RemappedFile, TargetStyle); + llvm::sys::path::native(remapDIPath(getCurrentDirname()), CurDir, + TargetStyle); + SmallString<128> DirBuf; SmallString<128> FileBuf; - if (llvm::sys::path::is_absolute(RemappedFile)) { + if (llvm::sys::path::is_absolute(RemappedFile, TargetStyle)) { // Strip the common prefix (if it is more than just "/") from current // directory and FileName for a more space-efficient encoding. - auto FileIt = llvm::sys::path::begin(RemappedFile); + auto FileIt = llvm::sys::path::begin(RemappedFile, TargetStyle); auto FileE = llvm::sys::path::end(RemappedFile); - auto CurDirIt = llvm::sys::path::begin(CurDir); + auto CurDirIt = llvm::sys::path::begin(CurDir, TargetStyle); 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) { + llvm::sys::path::append(DirBuf, TargetStyle, *CurDirIt); + if (std::distance(llvm::sys::path::begin(CurDir, TargetStyle), CurDirIt) == 1) { // Don't strip the common prefix if it is only the root "/" // since that would make LLVM diagnostic locations confusing. - Dir = {}; - File = RemappedFile; + FileBuf = RemappedFile; } else { - for (; FileIt != FileE; ++FileIt) - llvm::sys::path::append(FileBuf, *FileIt); - Dir = DirBuf; - File = FileBuf; + llvm::sys::path::append(FileBuf, FileIt, FileE, TargetStyle); } } else { - Dir = CurDir; - File = RemappedFile; + DirBuf = CurDir; + FileBuf = RemappedFile; } - llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source); + + llvm::DIFile *F = DBuilder.createFile(FileBuf, DirBuf, CSInfo, Source); DIFileCache[FileName.data()].reset(F); return F; } @@ -611,9 +614,17 @@ // file was specified with an absolute path. if (CSKind) CSInfo.emplace(*CSKind, Checksum); - llvm::DIFile *CUFile = DBuilder.createFile( - remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo, - getSource(SM, SM.getMainFileID())); + + auto TargetStyle = CGM.getTarget().getTriple().isOSWindows() + ? llvm::sys::path::Style::windows + : llvm::sys::path::Style::posix; + SmallString<128> MainDIFile; + SmallString<128> MainDIDir; + llvm::sys::path::native(remapDIPath(MainFileName), MainDIFile, TargetStyle); + llvm::sys::path::native(remapDIPath(getCurrentDirname()), MainDIDir, + TargetStyle); + llvm::DIFile *CUFile = DBuilder.createFile(MainDIFile, MainDIDir, CSInfo, + getSource(SM, SM.getMainFileID())); StringRef Sysroot, SDK; if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) { Index: clang/test/CodeGen/debug-info-preprocessed-file-windows.i =================================================================== --- /dev/null +++ clang/test/CodeGen/debug-info-preprocessed-file-windows.i @@ -0,0 +1,11 @@ +# 1 "A:\\foo\\bar\\preprocessed-input.c" +# 1 "" 1 +# 1 "" 3 +# 318 "" 3 +# 1 "" 1 +# 1 "" 2 +# 1 "preprocessed-input.c" 2 + +// RUN: %clang -target i686-pc-windows -g -c -S -emit-llvm -o - %s | FileCheck %s +// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] +// CHECK: ![[FILE]] = !DIFile(filename: "A:\\foo\\bar\\preprocessed-input.c" Index: clang/test/CodeGen/debug-info-preprocessed-file.i =================================================================== --- clang/test/CodeGen/debug-info-preprocessed-file.i +++ clang/test/CodeGen/debug-info-preprocessed-file.i @@ -6,6 +6,6 @@ # 1 "" 2 # 1 "preprocessed-input.c" 2 -// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s +// RUN: %clang -target i686-pc-linux -g -c -S -emit-llvm -o - %s | FileCheck %s // CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] // CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c" Index: clang/test/CodeGen/debug-prefix-map.c =================================================================== --- clang/test/CodeGen/debug-prefix-map.c +++ clang/test/CodeGen/debug-prefix-map.c @@ -1,10 +1,23 @@ -// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - | FileCheck %s -check-prefix CHECK-NO-MAIN-FILE-NAME -// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefix CHECK-EVIL -// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name debug-prefix-map.c | FileCheck %s -// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR -// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix CHECK-SYSROOT -// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s -// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple i686-pc-linux -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK-NO-MAIN-FILE-NAME,CHECK-NO-MAIN-FILE-NAME-POSIX +// RUN: %clang_cc1 -triple i686-pc-windows -debug-info-kind=standalone -fdebug-prefix-map=%p=A:\UNLIKELY_PATH\empty %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK-NO-MAIN-FILE-NAME,CHECK-NO-MAIN-FILE-NAME-WIN + +// RUN: %clang_cc1 -triple i686-pc-linux -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK-EVIL,CHECK-EVIL-POSIX +// RUN: %clang_cc1 -triple i686-pc-windows -debug-info-kind=standalone -fdebug-prefix-map=%p=A:\UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK-EVIL,CHECK-EVIL-WIN + +// RUN: %clang_cc1 -triple i686-pc-linux -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name debug-prefix-map.c | FileCheck %s -check-prefixes=CHECK,CHECK-POSIX +// RUN: %clang_cc1 -triple i686-pc-windows -debug-info-kind=standalone -fdebug-prefix-map=%p=A:\UNLIKELY_PATH\empty %s -emit-llvm -o - -main-file-name debug-prefix-map.c | FileCheck %s -check-prefixes=CHECK,CHECK-WIN + +// RUN: %clang_cc1 -triple i686-pc-linux -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -fdebug-compilation-dir %p | FileCheck %s -check-prefixes=CHECK-COMPILATION-DIR,CHECK-COMPILATION-DIR-POSIX +// RUN: %clang_cc1 -triple i686-pc-windows -debug-info-kind=standalone -fdebug-prefix-map=%p=A:\UNLIKELY_PATH\empty %s -emit-llvm -o - -fdebug-compilation-dir %p | FileCheck %s -check-prefixes=CHECK-COMPILATION-DIR,CHECK-COMPILATION-DIR-WIN + +// RUN: %clang_cc1 -triple i686-pc-linux -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix=CHECK-SYSROOT-POSIX +// RUN: %clang_cc1 -triple i686-pc-windows -debug-info-kind=standalone -fdebug-prefix-map=%p=A:\UNLIKELY_PATH\empty %s -emit-llvm -o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix=CHECK-SYSROOT-WIN + +// RUN: %clang -g -target i686-pc-linux -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,CHECK-POSIX +// RUN: %clang -g -target i686-pc-windows -fdebug-prefix-map=%p=A:\UNLIKELY_PATH\empty -S -c %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,CHECK-WIN + +// RUN: %clang -g -target i686-pc-linux -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,CHECK-POSIX +// RUN: %clang -g -target i686-pc-windows -ffile-prefix-map=%p=A:\UNLIKELY_PATH\empty -S -c %s -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,CHECK-WIN #include "Inputs/stdio.h" @@ -19,26 +32,35 @@ vprintf("string", argp); } -// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "/UNLIKELY_PATH/empty{{/|\\\\}}" -// CHECK-NO-MAIN-FILE-NAME: !DIFile(filename: "/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: "/UNLIKELY_PATH/empty{{/|\\\\}}Inputs/stdio.h", -// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "{{()|(.*:.*)}}") +// CHECK-NO-MAIN-FILE-NAME-POSIX: !DIFile(filename: "/UNLIKELY_PATH/empty/" +// CHECK-NO-MAIN-FILE-NAME-WIN: !DIFile(filename: "A:\\UNLIKELY_PATH\\empty\\", +// CHECK-NO-MAIN-FILE-NAME-POSIX: !DIFile(filename: "/UNLIKELY_PATH/empty/{{.*}}", +// CHECK-NO-MAIN-FILE-NAME-WIN: !DIFile(filename: "A:\\UNLIKELY_PATH\\empty\\{{.*}}", +// CHECK-NO-MAIN-FILE-NAME-SAME: directory: "" +// CHECK-NO-MAIN-FILE-NAME-POSIX: !DIFile(filename: "/UNLIKELY_PATH/empty/Inputs/stdio.h", +// CHECK-NO-MAIN-FILE-NAME-WIN: !DIFile(filename: "A:\\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: "/UNLIKELY_PATH=empty{{/|\\\\}}{{.*}}" -// CHECK-EVIL: !DIFile(filename: "/UNLIKELY_PATH=empty{{/|\\\\}}{{.*}}Inputs/stdio.h", -// CHECK-EVIL-SAME: directory: "{{()|(.*:.*)}}") +// CHECK-EVIL-POSIX: !DIFile(filename: "/UNLIKELY_PATH=empty/{{.*}}" +// CHECK-EVIL-WIN: !DIFile(filename: "A:\\UNLIKELY_PATH=empty\\{{.*}}" +// CHECK-EVIL-POSIX: !DIFile(filename: "/UNLIKELY_PATH=empty/{{.*}}Inputs/stdio.h", +// CHECK-EVIL-WIN: !DIFile(filename: "A:\\UNLIKELY_PATH=empty\\{{.*}}Inputs\\stdio.h", +// CHECK-EVIL-SAME: directory: "" // CHECK-EVIL-NOT: !DIFile(filename: -// CHECK: !DIFile(filename: "/UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}" -// CHECK: !DIFile(filename: "/UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}Inputs/stdio.h", -// CHECK-SAME: directory: "{{()|(.*:.*)}}") +// CHECK-POSIX: !DIFile(filename: "/UNLIKELY_PATH/empty/{{.*}}" +// CHECK-WIN: !DIFile(filename: "A:\\UNLIKELY_PATH\\empty\\{{.*}}" +// CHECK-POSIX: !DIFile(filename: "/UNLIKELY_PATH/empty/{{.*}}Inputs/stdio.h", +// CHECK-WIN: !DIFile(filename: "A:\\UNLIKELY_PATH\\empty\\{{.*}}Inputs\\stdio.h", +// CHECK-SAME: directory: "" // CHECK-NOT: !DIFile(filename: -// CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}", directory: "/UNLIKELY_PATH/empty") -// CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs/stdio.h", directory: "/UNLIKELY_PATH/empty") +// CHECK-COMPILATION-DIR-POSIX: !DIFile(filename: "{{.*}}", directory: "/UNLIKELY_PATH/empty") +// CHECK-COMPILATION-DIR-WIN: !DIFile(filename: "{{.*}}", directory: "A:\\UNLIKELY_PATH\\empty") +// CHECK-COMPILATION-DIR-POSIX: !DIFile(filename: "{{.*}}Inputs/stdio.h", directory: "/UNLIKELY_PATH/empty") +// CHECK-COMPILATION-DIR-WIN: !DIFile(filename: "{{.*}}Inputs\\stdio.h", directory: "A:\\UNLIKELY_PATH\\empty") // CHECK-COMPILATION-DIR-NOT: !DIFile(filename: -// CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: "/UNLIKELY_PATH/empty" + +// CHECK-SYSROOT-POSIX: !DICompileUnit({{.*}}sysroot: "/UNLIKELY_PATH/empty" +// CHECK-SYSROOT-WIN: !DICompileUnit({{.*}}sysroot: "A:\\UNLIKELY_PATH\\empty" Index: clang/test/CodeGenCXX/linetable-fnbegin.cpp =================================================================== --- clang/test/CodeGenCXX/linetable-fnbegin.cpp +++ clang/test/CodeGenCXX/linetable-fnbegin.cpp @@ -4,7 +4,7 @@ // CHECK: define{{.*}}bar // CHECK-NOT: define // CHECK: ret {{.*}}, !dbg [[DBG:.*]] -// CHECK: [[HPP:.*]] = !DIFile(filename: "./template.hpp", +// CHECK: [[HPP:.*]] = !DIFile(filename: ".{{/|\\\\}}template.hpp", // CHECK: [[SP:.*]] = distinct !DISubprogram(name: "bar", // CHECK-SAME: file: [[HPP]], line: 22 // CHECK-SAME: DISPFlagDefinition Index: clang/test/Frontend/optimization-remark-line-directive.c =================================================================== --- clang/test/Frontend/optimization-remark-line-directive.c +++ clang/test/Frontend/optimization-remark-line-directive.c @@ -2,11 +2,11 @@ // directives. We cannot map #line directives back to // a SourceLocation. -// RUN: %clang_cc1 %s -Rpass=inline -debug-info-kind=line-tables-only -dwarf-column-info -emit-llvm-only -verify -fno-experimental-new-pass-manager +// RUN: %clang_cc1 %s -triple i686-pc-linux -Rpass=inline -debug-info-kind=line-tables-only -dwarf-column-info -emit-llvm-only -verify -fno-experimental-new-pass-manager // The new PM inliner is not added to the default pipeline at O0, so we add // some optimizations to trigger it. -// RUN: %clang_cc1 %s -Rpass=inline -fexperimental-new-pass-manager -O1 -debug-info-kind=line-tables-only -dwarf-column-info -emit-llvm-only -verify +// RUN: %clang_cc1 %s -triple i686-pc-linux -Rpass=inline -fexperimental-new-pass-manager -O1 -debug-info-kind=line-tables-only -dwarf-column-info -emit-llvm-only -verify int foo(int x, int y) __attribute__((always_inline)); int foo(int x, int y) { return x + y; } Index: clang/test/Frontend/stdin-input.c =================================================================== --- clang/test/Frontend/stdin-input.c +++ clang/test/Frontend/stdin-input.c @@ -2,6 +2,6 @@ // RUN: -Xclang -main-file-name -Xclang test/foo.c -x c - -o - | FileCheck %s // CHECK: ; ModuleID = 'test/foo.c' // CHECK: source_filename = "test/foo.c" -// CHECK: !DIFile(filename: "test/foo.c" +// CHECK: !DIFile(filename: "test{{/|\\\\}}foo.c" int main() {} Index: clang/test/Modules/module-debuginfo-prefix.m =================================================================== --- clang/test/Modules/module-debuginfo-prefix.m +++ clang/test/Modules/module-debuginfo-prefix.m @@ -22,4 +22,4 @@ // Dir should always be empty, but on Windows we can't recognize /var // as being an absolute path. -// CHECK: !DIFile(filename: "/OVERRIDE/DebugObjC.h", directory: "{{()|(.*:.*)}}") +// CHECK: !DIFile(filename: "{{/|\\\\}}OVERRIDE{{/|\\\\}}DebugObjC.h", directory: "{{()|(.:.*)}}") Index: clang/test/PCH/debug-info-pch-container-path.c =================================================================== --- clang/test/PCH/debug-info-pch-container-path.c +++ clang/test/PCH/debug-info-pch-container-path.c @@ -17,6 +17,6 @@ // CHECK-SAME: language: DW_LANG_C99, // CHECK-SAME: file: ![[FILE:[0-9]+]], // CHECK: ![[FILE]] = !DIFile( -// CHECK-SAME: filename: "SOURCE/debug-info-limited-struct.h", +// CHECK-SAME: filename: "SOURCE{{/|\\\\}}debug-info-limited-struct.h", // CHECK-SAME: directory: "BUILD"