diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -2191,6 +2191,10 @@ case SourceLocExpr::File: { SmallString<256> Path(PLoc.getFilename()); Ctx.getLangOpts().remapPathPrefix(Path); + if (Ctx.getTargetInfo().getTriple().isOSWindows()) { + llvm::sys::path::make_preferred(Path, + llvm::sys::path::Style::windows_slash); + } return MakeStringLiteral(Path); } case SourceLocExpr::Function: { @@ -2224,6 +2228,10 @@ if (Name == "_M_file_name") { SmallString<256> Path(PLoc.getFilename()); Ctx.getLangOpts().remapPathPrefix(Path); + if (Ctx.getTargetInfo().getTriple().isOSWindows()) { + llvm::sys::path::make_preferred( + Path, llvm::sys::path::Style::windows_slash); + } Value.getStructField(F->getFieldIndex()) = MakeStringLiteral(Path); } else if (Name == "_M_function_name") { // Note: this emits the PrettyFunction name -- different than what diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1512,6 +1512,10 @@ FN += PLoc.getFilename(); } getLangOpts().remapPathPrefix(FN); + if (getTargetInfo().getTriple().isOSWindows()) { + llvm::sys::path::make_preferred(FN, + llvm::sys::path::Style::windows_slash); + } Lexer::Stringify(FN); OS << '"' << FN << '"'; } diff --git a/clang/test/Preprocessor/file_test_windows.c b/clang/test/Preprocessor/file_test_windows.c --- a/clang/test/Preprocessor/file_test_windows.c +++ b/clang/test/Preprocessor/file_test_windows.c @@ -8,19 +8,19 @@ filename: __FILE__ #include "Inputs/include-file-test/file_test.h" -// CHECK: filename: "A:\\UNLIKELY_PATH\\empty\\file_test_windows.c" -// CHECK: filename: "A:\\UNLIKELY_PATH\\empty/Inputs/include-file-test/file_test.h" -// CHECK: basefile: "A:\\UNLIKELY_PATH\\empty\\file_test_windows.c" +// CHECK: filename: "A:/UNLIKELY_PATH/empty/file_test_windows.c" +// CHECK: filename: "A:/UNLIKELY_PATH/empty/Inputs/include-file-test/file_test.h" +// CHECK: basefile: "A:/UNLIKELY_PATH/empty/file_test_windows.c" // CHECK-NOT: filename: -// CHECK-EVIL: filename: "A:\\UNLIKELY_PATH=empty\\file_test_windows.c" -// CHECK-EVIL: filename: "A:\\UNLIKELY_PATH=empty/Inputs/include-file-test/file_test.h" -// CHECK-EVIL: basefile: "A:\\UNLIKELY_PATH=empty\\file_test_windows.c" +// CHECK-EVIL: filename: "A:/UNLIKELY_PATH=empty/file_test_windows.c" +// CHECK-EVIL: filename: "A:/UNLIKELY_PATH=empty/Inputs/include-file-test/file_test.h" +// CHECK-EVIL: basefile: "A:/UNLIKELY_PATH=empty/file_test_windows.c" // CHECK-EVIL-NOT: filename: -// CHECK-CASE: filename: "A:\\UNLIKELY_PATH_BASE\\file_test_windows.c" -// CHECK-CASE: filename: "A:\\UNLIKELY_PATH_INC\\include-file-test/file_test.h" -// CHECK-CASE: basefile: "A:\\UNLIKELY_PATH_BASE\\file_test_windows.c" +// CHECK-CASE: filename: "A:/UNLIKELY_PATH_BASE/file_test_windows.c" +// CHECK-CASE: filename: "A:/UNLIKELY_PATH_INC/include-file-test/file_test.h" +// CHECK-CASE: basefile: "A:/UNLIKELY_PATH_BASE/file_test_windows.c" // CHECK-CASE-NOT: filename: // CHECK-REMOVE: filename: "file_test_windows.c"