From: Reid Kleckner Date: Thu, 26 Sep 2019 17:19:22 +0000 (+0000) Subject: Move normalization of `\` in #includes from -fms-compatibility to -fms-extensions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c6e4e7210cd1f80a0492f6bf1dc1f717a1cf0351;p=clang Move normalization of `\` in #includes from -fms-compatibility to -fms-extensions Handling backslashes in include paths in the implementation isn't non-conforming. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372999 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 660aba1db7..3b7eaee3c9 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/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(); + 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.MSVCCompat) { + if (LangOpts.MicrosoftExt) { NormalizedPath = Filename.str(); -#ifndef _WIN32 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/test/Lexer/cross-windows-on-linux-default.cpp b/test/Lexer/cross-windows-on-linux-default.cpp index 520b419a71..bcd4999a66 100644 --- a/test/Lexer/cross-windows-on-linux-default.cpp +++ b/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/test/Lexer/cross-windows-on-linux.cpp b/test/Lexer/cross-windows-on-linux.cpp index c6dcbca540..3932ffcb33 100644 --- a/test/Lexer/cross-windows-on-linux.cpp +++ b/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