diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 660aba1db7af..3b7eaee3c914 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1785,20 +1785,23 @@ Optional Preprocessor::LookupHeaderIncludeOrImport( return Filename; }; StringRef TypoCorrectionName = CorrectTypoFilename(Filename); - SmallString<128> NormalizedTypoCorrectionPath; - if (LangOpts.MSVCCompat) { - NormalizedTypoCorrectionPath = TypoCorrectionName.str(); + #ifndef _WIN32 + // Normalize slashes when compiling with -fms-extensions on non-Windows. + // This is unnecessary on Windows since the filesystem there handles + // backslashes. + SmallString<128> NormalizedTypoCorrectionPath; + if (LangOpts.MicrosoftExt) { + NormalizedTypoCorrectionPath = TypoCorrectionName; llvm::sys::path::native(NormalizedTypoCorrectionPath); -#endif + TypoCorrectionName = NormalizedTypoCorrectionPath; } +#endif + Optional File = LookupFile( - FilenameLoc, - LangOpts.MSVCCompat ? NormalizedTypoCorrectionPath.c_str() - : TypoCorrectionName, - isAngled, LookupFrom, LookupFromFile, CurDir, - Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, - &SuggestedModule, &IsMapped, + FilenameLoc, TypoCorrectionName, isAngled, LookupFrom, LookupFromFile, + CurDir, Callbacks ? &SearchPath : nullptr, + Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); if (File) { auto Hint = @@ -1906,15 +1909,18 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( // the path. ModuleMap::KnownHeader SuggestedModule; SourceLocation FilenameLoc = FilenameTok.getLocation(); - SmallString<128> NormalizedPath; - if (LangOpts.MSVCCompat) { - NormalizedPath = Filename.str(); + StringRef LookupFilename = Filename; + #ifndef _WIN32 + // Normalize slashes when compiling with -fms-extensions on non-Windows. This + // is unnecessary on Windows since the filesystem there handles backslashes. + SmallString<128> NormalizedPath; + if (LangOpts.MicrosoftExt) { + NormalizedPath = Filename.str(); llvm::sys::path::native(NormalizedPath); -#endif + LookupFilename = NormalizedPath; } - StringRef LookupFilename = - LangOpts.MSVCCompat ? StringRef(NormalizedPath) : Filename; +#endif Optional File = LookupHeaderIncludeOrImport( CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok, diff --git a/clang/test/Lexer/cross-windows-on-linux-default.cpp b/clang/test/Lexer/cross-windows-on-linux-default.cpp index 520b419a7100..bcd4999a663a 100644 --- a/clang/test/Lexer/cross-windows-on-linux-default.cpp +++ b/clang/test/Lexer/cross-windows-on-linux-default.cpp @@ -1,4 +1,4 @@ -// RUN: not %clang_cc1 -fsyntax-only -fms-compatibility -triple i686-win32 %s 2>&1 \ +// RUN: not %clang_cc1 -fsyntax-only -fms-extensions -triple i686-win32 %s 2>&1 \ // RUN: | FileCheck %s #include "Inputs\success.h" diff --git a/clang/test/Lexer/cross-windows-on-linux.cpp b/clang/test/Lexer/cross-windows-on-linux.cpp index c6dcbca54056..3932ffcb33c8 100644 --- a/clang/test/Lexer/cross-windows-on-linux.cpp +++ b/clang/test/Lexer/cross-windows-on-linux.cpp @@ -6,10 +6,8 @@ // CHECK: #include "Inputs\success.h" // CHECK: ^ -// expected to fail on windows as the inclusion would succeed and the -// compilation will fail due to the '#error success'. -// XFAIL: windows-msvc - -// This test may or may not fail since 'Inputs\success.h' is passed -// to Win32 APIs on Windows. -// REQUIRES: disabled +// This test is really checking that we *don't* replace backslashes with slashes +// on non-Windows unless -fms-extensions is passed. It won't fail in this way on +// Windows because the filesystem will interpret the backslash as a directory +// separator. +// UNSUPPORTED: system-windows